| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/ash/app_list/app_list_service_ash.h" | 5 #include "chrome/browser/ui/ash/app_list/app_list_service_ash.h" |
| 6 | 6 |
| 7 #include "ash/app_list/app_list_shower_delegate.h" | |
| 8 #include "ash/app_list/app_list_shower_delegate_factory.h" | |
| 9 #include "ash/app_list/app_list_view_delegate_factory.h" | |
| 10 #include "ash/shell.h" | 7 #include "ash/shell.h" |
| 11 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 12 #include "base/memory/ptr_util.h" | |
| 13 #include "base/memory/singleton.h" | 9 #include "base/memory/singleton.h" |
| 14 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/ui/app_list/app_list_view_delegate.h" | |
| 17 #include "chrome/browser/ui/app_list/start_page_service.h" | 12 #include "chrome/browser/ui/app_list/start_page_service.h" |
| 18 #include "chrome/browser/ui/ash/app_list/app_list_controller_ash.h" | 13 #include "chrome/browser/ui/ash/app_list/app_list_controller_ash.h" |
| 19 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" | 14 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" |
| 20 #include "chrome/browser/ui/ash/session_util.h" | |
| 21 #include "ui/app_list/app_list_switches.h" | 15 #include "ui/app_list/app_list_switches.h" |
| 22 #include "ui/app_list/shower/app_list_shower_delegate_factory.h" | |
| 23 #include "ui/app_list/shower/app_list_shower_impl.h" | |
| 24 #include "ui/app_list/views/app_list_main_view.h" | 16 #include "ui/app_list/views/app_list_main_view.h" |
| 25 #include "ui/app_list/views/app_list_view.h" | 17 #include "ui/app_list/views/app_list_view.h" |
| 26 #include "ui/app_list/views/contents_view.h" | 18 #include "ui/app_list/views/contents_view.h" |
| 27 | 19 |
| 28 namespace { | |
| 29 | |
| 30 class ViewDelegateFactoryImpl : public ash::AppListViewDelegateFactory { | |
| 31 public: | |
| 32 explicit ViewDelegateFactoryImpl(AppListServiceImpl* factory) | |
| 33 : factory_(factory) {} | |
| 34 ~ViewDelegateFactoryImpl() override {} | |
| 35 | |
| 36 // app_list::AppListViewDelegateFactory: | |
| 37 app_list::AppListViewDelegate* GetDelegate() override { | |
| 38 return factory_->GetViewDelegate( | |
| 39 Profile::FromBrowserContext(GetActiveBrowserContext())); | |
| 40 } | |
| 41 | |
| 42 private: | |
| 43 AppListServiceImpl* factory_; | |
| 44 | |
| 45 DISALLOW_COPY_AND_ASSIGN(ViewDelegateFactoryImpl); | |
| 46 }; | |
| 47 | |
| 48 } // namespace | |
| 49 | |
| 50 // static | 20 // static |
| 51 AppListServiceAsh* AppListServiceAsh::GetInstance() { | 21 AppListServiceAsh* AppListServiceAsh::GetInstance() { |
| 52 return base::Singleton<AppListServiceAsh, | 22 return base::Singleton<AppListServiceAsh, |
| 53 base::LeakySingletonTraits<AppListServiceAsh>>::get(); | 23 base::LeakySingletonTraits<AppListServiceAsh>>::get(); |
| 54 } | 24 } |
| 55 | 25 |
| 56 AppListServiceAsh::AppListServiceAsh() | 26 AppListServiceAsh::AppListServiceAsh() |
| 57 : shower_delegate_factory_(new ash::AppListShowerDelegateFactory( | 27 : controller_delegate_(new AppListControllerDelegateAsh()) { |
| 58 base::WrapUnique(new ViewDelegateFactoryImpl(this)))) { | |
| 59 app_list_shower_.reset( | |
| 60 new app_list::AppListShowerImpl(shower_delegate_factory_.get())); | |
| 61 controller_delegate_.reset( | |
| 62 new AppListControllerDelegateAsh(app_list_shower_.get())); | |
| 63 } | 28 } |
| 64 | 29 |
| 65 AppListServiceAsh::~AppListServiceAsh() { | 30 AppListServiceAsh::~AppListServiceAsh() { |
| 66 } | 31 } |
| 67 | 32 |
| 68 app_list::AppListShower* AppListServiceAsh::GetAppListShower() { | 33 void AppListServiceAsh::ShowAndSwitchToState( |
| 69 return app_list_shower_.get(); | 34 app_list::AppListModel::State state) { |
| 35 bool app_list_was_open = true; |
| 36 app_list::AppListView* app_list_view = |
| 37 ash::Shell::GetInstance()->GetAppListView(); |
| 38 if (!app_list_view) { |
| 39 // TODO(calamity): This may cause the app list to show briefly before the |
| 40 // state change. If this becomes an issue, add the ability to ash::Shell to |
| 41 // load the app list without showing it. |
| 42 ash::Shell::GetInstance()->ShowAppList(NULL); |
| 43 app_list_was_open = false; |
| 44 app_list_view = ash::Shell::GetInstance()->GetAppListView(); |
| 45 DCHECK(app_list_view); |
| 46 } |
| 47 |
| 48 if (state == app_list::AppListModel::INVALID_STATE) |
| 49 return; |
| 50 |
| 51 app_list::ContentsView* contents_view = |
| 52 app_list_view->app_list_main_view()->contents_view(); |
| 53 contents_view->SetActiveState(state, app_list_was_open /* animate */); |
| 70 } | 54 } |
| 71 | 55 |
| 72 void AppListServiceAsh::Init(Profile* initial_profile) { | 56 void AppListServiceAsh::Init(Profile* initial_profile) { |
| 73 // Ensure the StartPageService is created here. This early initialization is | 57 // Ensure the StartPageService is created here. This early initialization is |
| 74 // necessary to allow the WebContents to load before the app list is shown. | 58 // necessary to allow the WebContents to load before the app list is shown. |
| 75 app_list::StartPageService* service = | 59 app_list::StartPageService* service = |
| 76 app_list::StartPageService::Get(initial_profile); | 60 app_list::StartPageService::Get(initial_profile); |
| 77 if (service) | 61 if (service) |
| 78 service->Init(); | 62 service->Init(); |
| 79 } | 63 } |
| 80 | 64 |
| 81 void AppListServiceAsh::OnProfileWillBeRemoved( | 65 void AppListServiceAsh::OnProfileWillBeRemoved( |
| 82 const base::FilePath& profile_path) {} | 66 const base::FilePath& profile_path) { |
| 83 | |
| 84 void AppListServiceAsh::ShowAndSwitchToState( | |
| 85 app_list::AppListModel::State state) { | |
| 86 bool app_list_was_open = true; | |
| 87 app_list::AppListView* app_list_view = app_list_shower_->GetView(); | |
| 88 if (!app_list_view) { | |
| 89 // TODO(calamity): This may cause the app list to show briefly before the | |
| 90 // state change. If this becomes an issue, add the ability to ash::Shell to | |
| 91 // load the app list without showing it. | |
| 92 app_list_shower_->Show(ash::Shell::GetTargetRootWindow()); | |
| 93 app_list_was_open = false; | |
| 94 app_list_view = app_list_shower_->GetView(); | |
| 95 DCHECK(app_list_view); | |
| 96 } | |
| 97 | |
| 98 if (state == app_list::AppListModel::INVALID_STATE) | |
| 99 return; | |
| 100 | |
| 101 app_list::ContentsView* contents_view = | |
| 102 app_list_view->app_list_main_view()->contents_view(); | |
| 103 contents_view->SetActiveState(state, app_list_was_open /* animate */); | |
| 104 } | 67 } |
| 105 | 68 |
| 106 base::FilePath AppListServiceAsh::GetProfilePath( | 69 base::FilePath AppListServiceAsh::GetProfilePath( |
| 107 const base::FilePath& user_data_dir) { | 70 const base::FilePath& user_data_dir) { |
| 108 return ChromeLauncherController::instance()->profile()->GetPath(); | 71 return ChromeLauncherController::instance()->profile()->GetPath(); |
| 109 } | 72 } |
| 110 | 73 |
| 111 void AppListServiceAsh::ShowForProfile(Profile* /*default_profile*/) { | 74 void AppListServiceAsh::ShowForProfile(Profile* /*default_profile*/) { |
| 112 // This may not work correctly if the profile passed in is different from the | 75 // This may not work correctly if the profile passed in is different from the |
| 113 // one the ash Shell is currently using. | 76 // one the ash Shell is currently using. |
| 114 // TODO(ananta): Handle profile changes correctly when !defined(OS_CHROMEOS). | 77 // TODO(ananta): Handle profile changes correctly when !defined(OS_CHROMEOS). |
| 115 app_list_shower_->Show(ash::Shell::GetTargetRootWindow()); | 78 ash::Shell::GetInstance()->ShowAppList(NULL); |
| 116 } | 79 } |
| 117 | 80 |
| 118 void AppListServiceAsh::ShowForAppInstall(Profile* profile, | 81 void AppListServiceAsh::ShowForAppInstall(Profile* profile, |
| 119 const std::string& extension_id, | 82 const std::string& extension_id, |
| 120 bool start_discovery_tracking) { | 83 bool start_discovery_tracking) { |
| 121 if (app_list::switches::IsExperimentalAppListEnabled()) | 84 if (app_list::switches::IsExperimentalAppListEnabled()) |
| 122 ShowAndSwitchToState(app_list::AppListModel::STATE_APPS); | 85 ShowAndSwitchToState(app_list::AppListModel::STATE_APPS); |
| 123 | 86 |
| 124 AppListServiceImpl::ShowForAppInstall(profile, extension_id, | 87 AppListServiceImpl::ShowForAppInstall(profile, extension_id, |
| 125 start_discovery_tracking); | 88 start_discovery_tracking); |
| 126 } | 89 } |
| 127 | 90 |
| 128 void AppListServiceAsh::ShowForCustomLauncherPage(Profile* /*profile*/) { | 91 void AppListServiceAsh::ShowForCustomLauncherPage(Profile* /*profile*/) { |
| 129 ShowAndSwitchToState(app_list::AppListModel::STATE_CUSTOM_LAUNCHER_PAGE); | 92 ShowAndSwitchToState(app_list::AppListModel::STATE_CUSTOM_LAUNCHER_PAGE); |
| 130 } | 93 } |
| 131 | 94 |
| 132 void AppListServiceAsh::HideCustomLauncherPage() { | 95 void AppListServiceAsh::HideCustomLauncherPage() { |
| 133 app_list::AppListView* app_list_view = app_list_shower_->GetView(); | 96 app_list::AppListView* app_list_view = |
| 97 ash::Shell::GetInstance()->GetAppListView(); |
| 134 if (!app_list_view) | 98 if (!app_list_view) |
| 135 return; | 99 return; |
| 136 | 100 |
| 137 app_list::ContentsView* contents_view = | 101 app_list::ContentsView* contents_view = |
| 138 app_list_view->app_list_main_view()->contents_view(); | 102 app_list_view->app_list_main_view()->contents_view(); |
| 139 if (contents_view->IsStateActive( | 103 if (contents_view->IsStateActive( |
| 140 app_list::AppListModel::STATE_CUSTOM_LAUNCHER_PAGE)) { | 104 app_list::AppListModel::STATE_CUSTOM_LAUNCHER_PAGE)) { |
| 141 contents_view->SetActiveState(app_list::AppListModel::STATE_START, true); | 105 contents_view->SetActiveState(app_list::AppListModel::STATE_START, true); |
| 142 } | 106 } |
| 143 } | 107 } |
| 144 | 108 |
| 145 bool AppListServiceAsh::IsAppListVisible() const { | 109 bool AppListServiceAsh::IsAppListVisible() const { |
| 146 return app_list_shower_->GetTargetVisibility(); | 110 return ash::Shell::GetInstance()->GetAppListTargetVisibility(); |
| 147 } | 111 } |
| 148 | 112 |
| 149 void AppListServiceAsh::DismissAppList() { | 113 void AppListServiceAsh::DismissAppList() { |
| 150 app_list_shower_->Dismiss(); | 114 ash::Shell::GetInstance()->DismissAppList(); |
| 151 } | 115 } |
| 152 | 116 |
| 153 void AppListServiceAsh::EnableAppList(Profile* initial_profile, | 117 void AppListServiceAsh::EnableAppList(Profile* initial_profile, |
| 154 AppListEnableSource enable_source) {} | 118 AppListEnableSource enable_source) {} |
| 155 | 119 |
| 156 gfx::NativeWindow AppListServiceAsh::GetAppListWindow() { | 120 gfx::NativeWindow AppListServiceAsh::GetAppListWindow() { |
| 157 return app_list_shower_->GetWindow(); | 121 if (ash::Shell::HasInstance()) |
| 122 return ash::Shell::GetInstance()->GetAppListWindow(); |
| 123 return NULL; |
| 158 } | 124 } |
| 159 | 125 |
| 160 Profile* AppListServiceAsh::GetCurrentAppListProfile() { | 126 Profile* AppListServiceAsh::GetCurrentAppListProfile() { |
| 161 return ChromeLauncherController::instance()->profile(); | 127 return ChromeLauncherController::instance()->profile(); |
| 162 } | 128 } |
| 163 | 129 |
| 164 AppListControllerDelegate* AppListServiceAsh::GetControllerDelegate() { | 130 AppListControllerDelegate* AppListServiceAsh::GetControllerDelegate() { |
| 165 return controller_delegate_.get(); | 131 return controller_delegate_.get(); |
| 166 } | 132 } |
| 167 | 133 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 183 return AppListServiceAsh::GetInstance(); | 149 return AppListServiceAsh::GetInstance(); |
| 184 } | 150 } |
| 185 | 151 |
| 186 // static | 152 // static |
| 187 void AppListService::InitAll(Profile* initial_profile, | 153 void AppListService::InitAll(Profile* initial_profile, |
| 188 const base::FilePath& profile_path) { | 154 const base::FilePath& profile_path) { |
| 189 AppListServiceAsh::GetInstance()->Init(initial_profile); | 155 AppListServiceAsh::GetInstance()->Init(initial_profile); |
| 190 } | 156 } |
| 191 | 157 |
| 192 #endif // !defined(OS_WIN) | 158 #endif // !defined(OS_WIN) |
| OLD | NEW |