app_list_service_linux.cc revision f2477e01787aa58f445919b809d89e252beef54f
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 "chrome/browser/ui/app_list/app_list_controller_delegate.h" 9#include "chrome/browser/ui/app_list/app_list_factory.h" 10#include "chrome/browser/ui/app_list/app_list_shower.h" 11#include "chrome/browser/ui/app_list/app_list_view_delegate.h" 12#include "chrome/browser/ui/app_list/keep_alive_service_impl.h" 13#include "chrome/browser/ui/views/app_list/linux/app_list_controller_delegate_linux.h" 14#include "chrome/browser/ui/views/app_list/linux/app_list_linux.h" 15#include "ui/app_list/views/app_list_view.h" 16#include "ui/gfx/screen.h" 17 18namespace { 19 20class AppListFactoryLinux : public AppListFactory { 21 public: 22 explicit AppListFactoryLinux(AppListServiceLinux* service) 23 : service_(service) {} 24 virtual ~AppListFactoryLinux() {} 25 26 virtual AppList* CreateAppList( 27 Profile* profile, 28 AppListService* service, 29 const base::Closure& on_should_dismiss) OVERRIDE { 30 // The view delegate will be owned by the app list view. The app list view 31 // manages it's own lifetime. 32 AppListViewDelegate* view_delegate = new AppListViewDelegate( 33 profile, service->GetControllerDelegate()); 34 app_list::AppListView* view = new app_list::AppListView(view_delegate); 35 gfx::Point cursor = gfx::Screen::GetNativeScreen()->GetCursorScreenPoint(); 36 view->InitAsBubbleAtFixedLocation(NULL, 37 &pagination_model_, 38 cursor, 39 views::BubbleBorder::FLOAT, 40 false /* border_accepts_events */); 41 // TODO(mgiuca): Set the app launcher window's WM_CLASS so that it can be 42 // associated with its own launch icon in the window manager. 43 return new AppListLinux(view, on_should_dismiss); 44 } 45 46 private: 47 // PaginationModel that is shared across all views. 48 app_list::PaginationModel pagination_model_; 49 AppListServiceLinux* service_; 50 51 DISALLOW_COPY_AND_ASSIGN(AppListFactoryLinux); 52}; 53 54} // namespace 55 56AppListServiceLinux::~AppListServiceLinux() {} 57 58// static 59AppListServiceLinux* AppListServiceLinux::GetInstance() { 60 return Singleton<AppListServiceLinux, 61 LeakySingletonTraits<AppListServiceLinux> >::get(); 62} 63 64void AppListServiceLinux::set_can_close(bool can_close) { 65 shower_->set_can_close(can_close); 66} 67 68void AppListServiceLinux::OnAppListClosing() { 69 shower_->CloseAppList(); 70} 71 72void AppListServiceLinux::Init(Profile* initial_profile) { 73 HandleCommandLineFlags(initial_profile); 74} 75 76void AppListServiceLinux::CreateForProfile(Profile* requested_profile) { 77 shower_->CreateViewForProfile(requested_profile); 78} 79 80void AppListServiceLinux::ShowForProfile(Profile* requested_profile) { 81 DCHECK(requested_profile); 82 if (requested_profile->IsManaged()) 83 return; 84 85 ScopedKeepAlive show_app_list_keepalive; 86 87 // TODO(mgiuca): Call SetDidRunForNDayActiveStats. 88 89 InvalidatePendingProfileLoads(); 90 SetProfilePath(requested_profile->GetPath()); 91 shower_->ShowForProfile(requested_profile); 92 RecordAppListLaunch(); 93} 94 95void AppListServiceLinux::DismissAppList() { 96 shower_->DismissAppList(); 97} 98 99bool AppListServiceLinux::IsAppListVisible() const { 100 return shower_->IsAppListVisible(); 101} 102 103gfx::NativeWindow AppListServiceLinux::GetAppListWindow() { 104 return shower_->GetWindow(); 105} 106 107Profile* AppListServiceLinux::GetCurrentAppListProfile() { 108 return shower_->profile(); 109} 110 111AppListControllerDelegate* AppListServiceLinux::GetControllerDelegate() { 112 return controller_delegate_.get(); 113} 114 115void AppListServiceLinux::CreateShortcut() { 116 NOTIMPLEMENTED(); 117} 118 119AppListServiceLinux::AppListServiceLinux() 120 : shower_(new AppListShower( 121 scoped_ptr<AppListFactory>(new AppListFactoryLinux(this)), 122 scoped_ptr<KeepAliveService>(new KeepAliveServiceImpl), 123 this)), 124 controller_delegate_(new AppListControllerDelegateLinux(this)) { 125} 126 127// static 128AppListService* AppListService::Get(chrome::HostDesktopType desktop_type) { 129 return AppListServiceLinux::GetInstance(); 130} 131 132// static 133void AppListService::InitAll(Profile* initial_profile) { 134 AppListServiceLinux::GetInstance()->Init(initial_profile); 135} 136