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 "chrome/browser/shell_integration.h"
9 #include "chrome/browser/shell_integration_linux.h"
10 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h"
11 #include "chrome/browser/ui/app_list/app_list_factory.h"
12 #include "chrome/browser/ui/app_list/app_list_shower.h"
13 #include "chrome/browser/ui/app_list/app_list_view_delegate.h"
14 #include "chrome/browser/ui/app_list/keep_alive_service_impl.h"
15 #include "chrome/browser/ui/views/app_list/linux/app_list_controller_delegate_linux.h"
16 #include "chrome/browser/ui/views/app_list/linux/app_list_linux.h"
17 #include "content/public/browser/browser_thread.h"
18 #include "grit/chromium_strings.h"
19 #include "grit/google_chrome_strings.h"
20 #include "ui/app_list/app_list_constants.h"
21 #include "ui/app_list/views/app_list_view.h"
22 #include "ui/base/l10n/l10n_util.h"
23 #include "ui/gfx/screen.h"
27 class AppListFactoryLinux : public AppListFactory {
29 explicit AppListFactoryLinux(AppListServiceLinux* service)
30 : service_(service) {}
31 virtual ~AppListFactoryLinux() {}
33 virtual AppList* CreateAppList(
35 AppListService* service,
36 const base::Closure& on_should_dismiss) OVERRIDE {
37 // The view delegate will be owned by the app list view. The app list view
38 // manages it's own lifetime.
39 AppListViewDelegate* view_delegate = new AppListViewDelegate(
40 profile, service->GetControllerDelegate());
41 app_list::AppListView* view = new app_list::AppListView(view_delegate);
42 gfx::Point cursor = gfx::Screen::GetNativeScreen()->GetCursorScreenPoint();
43 view->InitAsBubbleAtFixedLocation(NULL,
46 views::BubbleBorder::FLOAT,
47 false /* border_accepts_events */);
48 return new AppListLinux(view, on_should_dismiss);
52 // PaginationModel that is shared across all views.
53 app_list::PaginationModel pagination_model_;
54 AppListServiceLinux* service_;
56 DISALLOW_COPY_AND_ASSIGN(AppListFactoryLinux);
59 void CreateShortcuts() {
60 std::string app_list_title =
61 l10n_util::GetStringUTF8(IDS_APP_LIST_SHORTCUT_NAME);
63 if (!ShellIntegrationLinux::CreateAppListDesktopShortcut(
64 app_list::kAppListWMClass,
66 LOG(WARNING) << "Unable to create App Launcher shortcut.";
72 AppListServiceLinux::~AppListServiceLinux() {}
75 AppListServiceLinux* AppListServiceLinux::GetInstance() {
76 return Singleton<AppListServiceLinux,
77 LeakySingletonTraits<AppListServiceLinux> >::get();
80 void AppListServiceLinux::set_can_close(bool can_close) {
81 shower_->set_can_close(can_close);
84 void AppListServiceLinux::OnAppListClosing() {
85 shower_->CloseAppList();
88 void AppListServiceLinux::Init(Profile* initial_profile) {
89 HandleCommandLineFlags(initial_profile);
92 void AppListServiceLinux::CreateForProfile(Profile* requested_profile) {
93 shower_->CreateViewForProfile(requested_profile);
96 void AppListServiceLinux::ShowForProfile(Profile* requested_profile) {
97 DCHECK(requested_profile);
98 if (requested_profile->IsManaged())
101 ScopedKeepAlive show_app_list_keepalive;
103 // TODO(mgiuca): Call SetDidRunForNDayActiveStats.
105 InvalidatePendingProfileLoads();
106 SetProfilePath(requested_profile->GetPath());
107 shower_->ShowForProfile(requested_profile);
108 RecordAppListLaunch();
111 void AppListServiceLinux::DismissAppList() {
112 shower_->DismissAppList();
115 bool AppListServiceLinux::IsAppListVisible() const {
116 return shower_->IsAppListVisible();
119 gfx::NativeWindow AppListServiceLinux::GetAppListWindow() {
120 return shower_->GetWindow();
123 Profile* AppListServiceLinux::GetCurrentAppListProfile() {
124 return shower_->profile();
127 AppListControllerDelegate* AppListServiceLinux::GetControllerDelegate() {
128 return controller_delegate_.get();
131 void AppListServiceLinux::CreateShortcut() {
132 content::BrowserThread::PostTask(
133 content::BrowserThread::FILE, FROM_HERE, base::Bind(&CreateShortcuts));
136 AppListServiceLinux::AppListServiceLinux()
137 : shower_(new AppListShower(
138 scoped_ptr<AppListFactory>(new AppListFactoryLinux(this)),
139 scoped_ptr<KeepAliveService>(new KeepAliveServiceImpl),
141 controller_delegate_(new AppListControllerDelegateLinux(this)) {
145 AppListService* AppListService::Get(chrome::HostDesktopType desktop_type) {
146 return AppListServiceLinux::GetInstance();
150 void AppListService::InitAll(Profile* initial_profile) {
151 AppListServiceLinux::GetInstance()->Init(initial_profile);