app_list_service_linux.cc revision 010d83a9304c5a91596085d917d248abff47903a
1// Copyright 2013 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "chrome/browser/ui/views/app_list/linux/app_list_service_linux.h"
6
7#include "base/memory/singleton.h"
8#include "base/thread_task_runner_handle.h"
9#include "chrome/browser/shell_integration.h"
10#include "chrome/browser/shell_integration_linux.h"
11#include "chrome/browser/ui/app_list/app_list_controller_delegate_views.h"
12#include "chrome/browser/ui/app_list/app_list_shower_views.h"
13#include "chrome/browser/ui/views/app_list/linux/app_list_linux.h"
14#include "content/public/browser/browser_thread.h"
15#include "grit/chromium_strings.h"
16#include "grit/google_chrome_strings.h"
17#include "ui/app_list/app_list_constants.h"
18#include "ui/app_list/views/app_list_view.h"
19#include "ui/base/l10n/l10n_util.h"
20
21namespace {
22
23void CreateShortcuts() {
24  std::string app_list_title =
25      l10n_util::GetStringUTF8(IDS_APP_LIST_SHORTCUT_NAME);
26
27  if (!ShellIntegrationLinux::CreateAppListDesktopShortcut(
28           app_list::kAppListWMClass,
29           app_list_title)) {
30    LOG(WARNING) << "Unable to create App Launcher shortcut.";
31  }
32}
33
34}  // namespace
35
36AppListServiceLinux::~AppListServiceLinux() {}
37
38// static
39AppListServiceLinux* AppListServiceLinux::GetInstance() {
40  return Singleton<AppListServiceLinux,
41                   LeakySingletonTraits<AppListServiceLinux> >::get();
42}
43
44void AppListServiceLinux::CreateShortcut() {
45  content::BrowserThread::PostTask(
46      content::BrowserThread::FILE, FROM_HERE, base::Bind(&CreateShortcuts));
47}
48
49void AppListServiceLinux::OnActivationChanged(views::Widget* /*widget*/,
50                                              bool active) {
51  if (active)
52    return;
53
54  // Dismiss the app list asynchronously. This must be done asynchronously
55  // or our caller will crash, as it expects the app list to remain alive.
56  base::ThreadTaskRunnerHandle::Get()->PostTask(
57      FROM_HERE,
58      base::Bind(&AppListServiceLinux::DismissAppList, base::Unretained(this)));
59}
60
61AppListServiceLinux::AppListServiceLinux()
62    : AppListServiceViews(scoped_ptr<AppListControllerDelegate>(
63          new AppListControllerDelegateViews(this))) {}
64
65void AppListServiceLinux::OnViewCreated() {
66  shower().app_list()->AddObserver(this);
67}
68
69void AppListServiceLinux::OnViewBeingDestroyed() {
70  shower().app_list()->RemoveObserver(this);
71  AppListServiceViews::OnViewBeingDestroyed();
72}
73
74void AppListServiceLinux::OnViewDismissed() {
75}
76
77void AppListServiceLinux::MoveNearCursor(app_list::AppListView* view) {
78  AppListLinux::MoveNearCursor(view);
79}
80
81// static
82AppListService* AppListService::Get(chrome::HostDesktopType desktop_type) {
83  return AppListServiceLinux::GetInstance();
84}
85
86// static
87void AppListService::InitAll(Profile* initial_profile) {
88  AppListServiceLinux::GetInstance()->Init(initial_profile);
89}
90