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.
5 #include "chrome/browser/ui/views/app_list/linux/app_list_service_linux.h"
7 #include "base/memory/singleton.h"
8 #include "base/thread_task_runner_handle.h"
9 #include "chrome/browser/apps/scoped_keep_alive.h"
10 #include "chrome/browser/shell_integration.h"
11 #include "chrome/browser/shell_integration_linux.h"
12 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h"
13 #include "chrome/browser/ui/app_list/app_list_controller_delegate_views.h"
14 #include "chrome/browser/ui/app_list/app_list_shower_views.h"
15 #include "chrome/browser/ui/app_list/app_list_view_delegate.h"
16 #include "chrome/browser/ui/ash/app_list/app_list_service_ash.h"
17 #include "chrome/browser/ui/views/app_list/linux/app_list_linux.h"
18 #include "chrome/grit/chromium_strings.h"
19 #include "chrome/grit/google_chrome_strings.h"
20 #include "content/public/browser/browser_thread.h"
21 #include "ui/app_list/app_list_constants.h"
22 #include "ui/app_list/app_list_switches.h"
23 #include "ui/app_list/views/app_list_view.h"
24 #include "ui/base/l10n/l10n_util.h"
28 void CreateShortcuts() {
29 std::string app_list_title =
30 l10n_util::GetStringUTF8(IDS_APP_LIST_SHORTCUT_NAME);
32 if (!shell_integration_linux::CreateAppListDesktopShortcut(
33 app_list::kAppListWMClass,
35 LOG(WARNING) << "Unable to create App Launcher shortcut.";
41 AppListServiceLinux::~AppListServiceLinux() {}
44 AppListServiceLinux* AppListServiceLinux::GetInstance() {
45 return Singleton<AppListServiceLinux,
46 LeakySingletonTraits<AppListServiceLinux> >::get();
49 void AppListServiceLinux::CreateShortcut() {
50 content::BrowserThread::PostTask(
51 content::BrowserThread::FILE, FROM_HERE, base::Bind(&CreateShortcuts));
54 void AppListServiceLinux::OnActivationChanged(views::Widget* /*widget*/,
59 if (app_list::switches::ShouldNotDismissOnBlur())
62 // Dismiss the app list asynchronously. This must be done asynchronously
63 // or our caller will crash, as it expects the app list to remain alive.
64 base::ThreadTaskRunnerHandle::Get()->PostTask(
66 base::Bind(&AppListServiceLinux::DismissAppList, base::Unretained(this)));
69 AppListServiceLinux::AppListServiceLinux()
70 : AppListServiceViews(scoped_ptr<AppListControllerDelegate>(
71 new AppListControllerDelegateViews(this))) {}
73 void AppListServiceLinux::OnViewCreated() {
74 shower().app_list()->AddObserver(this);
77 void AppListServiceLinux::OnViewBeingDestroyed() {
78 shower().app_list()->RemoveObserver(this);
79 AppListServiceViews::OnViewBeingDestroyed();
82 void AppListServiceLinux::OnViewDismissed() {
85 void AppListServiceLinux::MoveNearCursor(app_list::AppListView* view) {
86 AppListLinux::MoveNearCursor(view);
90 AppListService* AppListService::Get(chrome::HostDesktopType desktop_type) {
91 if (desktop_type == chrome::HOST_DESKTOP_TYPE_ASH)
92 return AppListServiceAsh::GetInstance();
94 return AppListServiceLinux::GetInstance();
98 void AppListService::InitAll(Profile* initial_profile) {
99 AppListServiceAsh::GetInstance()->Init(initial_profile);
100 AppListServiceLinux::GetInstance()->Init(initial_profile);