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/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/views/app_list_view.h" 23 #include "ui/base/l10n/l10n_util.h" 24 25 namespace { 26 27 void CreateShortcuts() { 28 std::string app_list_title = 29 l10n_util::GetStringUTF8(IDS_APP_LIST_SHORTCUT_NAME); 30 31 if (!shell_integration_linux::CreateAppListDesktopShortcut( 32 app_list::kAppListWMClass, 33 app_list_title)) { 34 LOG(WARNING) << "Unable to create App Launcher shortcut."; 35 } 36 } 37 38 } // namespace 39 40 AppListServiceLinux::~AppListServiceLinux() {} 41 42 // static 43 AppListServiceLinux* AppListServiceLinux::GetInstance() { 44 return Singleton<AppListServiceLinux, 45 LeakySingletonTraits<AppListServiceLinux> >::get(); 46 } 47 48 void AppListServiceLinux::CreateShortcut() { 49 content::BrowserThread::PostTask( 50 content::BrowserThread::FILE, FROM_HERE, base::Bind(&CreateShortcuts)); 51 } 52 53 void AppListServiceLinux::OnActivationChanged(views::Widget* /*widget*/, 54 bool active) { 55 if (active) 56 return; 57 58 // Dismiss the app list asynchronously. This must be done asynchronously 59 // or our caller will crash, as it expects the app list to remain alive. 60 base::ThreadTaskRunnerHandle::Get()->PostTask( 61 FROM_HERE, 62 base::Bind(&AppListServiceLinux::DismissAppList, base::Unretained(this))); 63 } 64 65 AppListServiceLinux::AppListServiceLinux() 66 : AppListServiceViews(scoped_ptr<AppListControllerDelegate>( 67 new AppListControllerDelegateViews(this))) {} 68 69 void AppListServiceLinux::OnViewCreated() { 70 shower().app_list()->AddObserver(this); 71 } 72 73 void AppListServiceLinux::OnViewBeingDestroyed() { 74 shower().app_list()->RemoveObserver(this); 75 AppListServiceViews::OnViewBeingDestroyed(); 76 } 77 78 void AppListServiceLinux::OnViewDismissed() { 79 } 80 81 void AppListServiceLinux::MoveNearCursor(app_list::AppListView* view) { 82 AppListLinux::MoveNearCursor(view); 83 } 84 85 // static 86 AppListService* AppListService::Get(chrome::HostDesktopType desktop_type) { 87 if (desktop_type == chrome::HOST_DESKTOP_TYPE_ASH) 88 return AppListServiceAsh::GetInstance(); 89 90 return AppListServiceLinux::GetInstance(); 91 } 92 93 // static 94 void AppListService::InitAll(Profile* initial_profile) { 95 AppListServiceAsh::GetInstance()->Init(initial_profile); 96 AppListServiceLinux::GetInstance()->Init(initial_profile); 97 } 98