Chromium Code Reviews| 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/shell.h" | |
| 8 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 9 #include "base/memory/singleton.h" | 8 #include "base/memory/singleton.h" |
| 9 #include "base/thread_task_runner_handle.h" | |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/ui/app_list/start_page_service.h" | 12 #include "chrome/browser/ui/app_list/start_page_service.h" |
| 13 #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" |
| 14 #include "chrome/browser/ui/ash/app_list/app_list_shower_ash.h" | |
| 14 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" | 15 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" |
| 16 #include "chrome/browser/ui/ash/session_util.h" | |
| 15 #include "ui/app_list/app_list_switches.h" | 17 #include "ui/app_list/app_list_switches.h" |
| 16 #include "ui/app_list/views/app_list_main_view.h" | 18 #include "ui/app_list/views/app_list_main_view.h" |
| 17 #include "ui/app_list/views/app_list_view.h" | 19 #include "ui/app_list/views/app_list_view.h" |
| 18 #include "ui/app_list/views/contents_view.h" | 20 #include "ui/app_list/views/contents_view.h" |
| 19 | 21 |
| 20 // static | 22 // static |
| 21 AppListServiceAsh* AppListServiceAsh::GetInstance() { | 23 AppListServiceAsh* AppListServiceAsh::GetInstance() { |
| 22 return base::Singleton<AppListServiceAsh, | 24 return base::Singleton<AppListServiceAsh, |
| 23 base::LeakySingletonTraits<AppListServiceAsh>>::get(); | 25 base::LeakySingletonTraits<AppListServiceAsh>>::get(); |
| 24 } | 26 } |
| 25 | 27 |
| 26 AppListServiceAsh::AppListServiceAsh() | 28 AppListServiceAsh::AppListServiceAsh() |
| 27 : controller_delegate_(new AppListControllerDelegateAsh()) { | 29 : app_list_shower_(new AppListShowerAsh()) { |
| 30 controller_delegate_.reset( | |
| 31 new AppListControllerDelegateAsh(app_list_shower_.get())); | |
| 32 // The PostTask is necessary because getting AppListViewDelegate requires a | |
| 33 // Profile to be set on AppListViewDelegate, which requires the | |
| 34 // AppListService to be already created. | |
| 35 base::ThreadTaskRunnerHandle::Get()->PostTask( | |
| 36 FROM_HERE, base::Bind(&AppListServiceAsh::SetViewDelegateForShower, | |
| 37 base::Unretained(this))); | |
|
xiyuan
2016/03/11 18:36:00
We should figure out a way to get rid of this Post
mfomitchev
2016/03/24 17:47:29
Done.
| |
| 28 } | 38 } |
| 29 | 39 |
| 30 AppListServiceAsh::~AppListServiceAsh() { | 40 AppListServiceAsh::~AppListServiceAsh() { |
| 31 } | 41 } |
| 32 | 42 |
| 43 app_list::AppListController* AppListServiceAsh::GetAppListController() { | |
| 44 return app_list_shower_.get(); | |
| 45 } | |
| 46 | |
| 47 void AppListServiceAsh::Init(Profile* initial_profile) { | |
| 48 // Ensure the StartPageService is created here. This early initialization is | |
| 49 // necessary to allow the WebContents to load before the app list is shown. | |
| 50 app_list::StartPageService* service = | |
| 51 app_list::StartPageService::Get(initial_profile); | |
| 52 if (service) | |
| 53 service->Init(); | |
| 54 } | |
| 55 | |
| 56 void AppListServiceAsh::OnProfileWillBeRemoved( | |
| 57 const base::FilePath& profile_path) {} | |
| 58 | |
| 59 void AppListServiceAsh::SetViewDelegateForShower() { | |
| 60 AppListViewDelegate* view_delegate = | |
| 61 GetViewDelegate(Profile::FromBrowserContext(GetActiveBrowserContext())); | |
| 62 app_list_shower_->set_view_delegate(view_delegate); | |
| 63 } | |
| 64 | |
| 33 void AppListServiceAsh::ShowAndSwitchToState( | 65 void AppListServiceAsh::ShowAndSwitchToState( |
| 34 app_list::AppListModel::State state) { | 66 app_list::AppListModel::State state) { |
| 35 bool app_list_was_open = true; | 67 bool app_list_was_open = true; |
| 36 app_list::AppListView* app_list_view = | 68 app_list::AppListView* app_list_view = app_list_shower_->GetView(); |
| 37 ash::Shell::GetInstance()->GetAppListView(); | |
| 38 if (!app_list_view) { | 69 if (!app_list_view) { |
| 39 // TODO(calamity): This may cause the app list to show briefly before the | 70 // 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 | 71 // state change. If this becomes an issue, add the ability to ash::Shell to |
| 41 // load the app list without showing it. | 72 // load the app list without showing it. |
| 42 ash::Shell::GetInstance()->ShowAppList(NULL); | 73 app_list_shower_->Show(NULL); |
| 43 app_list_was_open = false; | 74 app_list_was_open = false; |
| 44 app_list_view = ash::Shell::GetInstance()->GetAppListView(); | 75 app_list_view = app_list_shower_->GetView(); |
| 45 DCHECK(app_list_view); | 76 DCHECK(app_list_view); |
| 46 } | 77 } |
| 47 | 78 |
| 48 if (state == app_list::AppListModel::INVALID_STATE) | 79 if (state == app_list::AppListModel::INVALID_STATE) |
| 49 return; | 80 return; |
| 50 | 81 |
| 51 app_list::ContentsView* contents_view = | 82 app_list::ContentsView* contents_view = |
| 52 app_list_view->app_list_main_view()->contents_view(); | 83 app_list_view->app_list_main_view()->contents_view(); |
| 53 contents_view->SetActiveState(state, app_list_was_open /* animate */); | 84 contents_view->SetActiveState(state, app_list_was_open /* animate */); |
| 54 } | 85 } |
| 55 | 86 |
| 56 void AppListServiceAsh::Init(Profile* initial_profile) { | |
| 57 // Ensure the StartPageService is created here. This early initialization is | |
| 58 // necessary to allow the WebContents to load before the app list is shown. | |
| 59 app_list::StartPageService* service = | |
| 60 app_list::StartPageService::Get(initial_profile); | |
| 61 if (service) | |
| 62 service->Init(); | |
| 63 } | |
| 64 | |
| 65 void AppListServiceAsh::OnProfileWillBeRemoved( | |
| 66 const base::FilePath& profile_path) { | |
| 67 } | |
| 68 | |
| 69 base::FilePath AppListServiceAsh::GetProfilePath( | 87 base::FilePath AppListServiceAsh::GetProfilePath( |
| 70 const base::FilePath& user_data_dir) { | 88 const base::FilePath& user_data_dir) { |
| 71 return ChromeLauncherController::instance()->profile()->GetPath(); | 89 return ChromeLauncherController::instance()->profile()->GetPath(); |
| 72 } | 90 } |
| 73 | 91 |
| 74 void AppListServiceAsh::ShowForProfile(Profile* /*default_profile*/) { | 92 void AppListServiceAsh::ShowForProfile(Profile* /*default_profile*/) { |
| 75 // This may not work correctly if the profile passed in is different from the | 93 // This may not work correctly if the profile passed in is different from the |
| 76 // one the ash Shell is currently using. | 94 // one the ash Shell is currently using. |
| 77 // TODO(ananta): Handle profile changes correctly when !defined(OS_CHROMEOS). | 95 // TODO(ananta): Handle profile changes correctly when !defined(OS_CHROMEOS). |
| 78 ash::Shell::GetInstance()->ShowAppList(NULL); | 96 app_list_shower_->Show(NULL); |
| 79 } | 97 } |
| 80 | 98 |
| 81 void AppListServiceAsh::ShowForAppInstall(Profile* profile, | 99 void AppListServiceAsh::ShowForAppInstall(Profile* profile, |
| 82 const std::string& extension_id, | 100 const std::string& extension_id, |
| 83 bool start_discovery_tracking) { | 101 bool start_discovery_tracking) { |
| 84 if (app_list::switches::IsExperimentalAppListEnabled()) | 102 if (app_list::switches::IsExperimentalAppListEnabled()) |
| 85 ShowAndSwitchToState(app_list::AppListModel::STATE_APPS); | 103 ShowAndSwitchToState(app_list::AppListModel::STATE_APPS); |
| 86 | 104 |
| 87 AppListServiceImpl::ShowForAppInstall(profile, extension_id, | 105 AppListServiceImpl::ShowForAppInstall(profile, extension_id, |
| 88 start_discovery_tracking); | 106 start_discovery_tracking); |
| 89 } | 107 } |
| 90 | 108 |
| 91 void AppListServiceAsh::ShowForCustomLauncherPage(Profile* /*profile*/) { | 109 void AppListServiceAsh::ShowForCustomLauncherPage(Profile* /*profile*/) { |
| 92 ShowAndSwitchToState(app_list::AppListModel::STATE_CUSTOM_LAUNCHER_PAGE); | 110 ShowAndSwitchToState(app_list::AppListModel::STATE_CUSTOM_LAUNCHER_PAGE); |
| 93 } | 111 } |
| 94 | 112 |
| 95 void AppListServiceAsh::HideCustomLauncherPage() { | 113 void AppListServiceAsh::HideCustomLauncherPage() { |
| 96 app_list::AppListView* app_list_view = | 114 app_list::AppListView* app_list_view = app_list_shower_->GetView(); |
| 97 ash::Shell::GetInstance()->GetAppListView(); | |
| 98 if (!app_list_view) | 115 if (!app_list_view) |
| 99 return; | 116 return; |
| 100 | 117 |
| 101 app_list::ContentsView* contents_view = | 118 app_list::ContentsView* contents_view = |
| 102 app_list_view->app_list_main_view()->contents_view(); | 119 app_list_view->app_list_main_view()->contents_view(); |
| 103 if (contents_view->IsStateActive( | 120 if (contents_view->IsStateActive( |
| 104 app_list::AppListModel::STATE_CUSTOM_LAUNCHER_PAGE)) { | 121 app_list::AppListModel::STATE_CUSTOM_LAUNCHER_PAGE)) { |
| 105 contents_view->SetActiveState(app_list::AppListModel::STATE_START, true); | 122 contents_view->SetActiveState(app_list::AppListModel::STATE_START, true); |
| 106 } | 123 } |
| 107 } | 124 } |
| 108 | 125 |
| 109 bool AppListServiceAsh::IsAppListVisible() const { | 126 bool AppListServiceAsh::IsAppListVisible() const { |
| 110 return ash::Shell::GetInstance()->GetAppListTargetVisibility(); | 127 return app_list_shower_->GetTargetVisibility(); |
| 111 } | 128 } |
| 112 | 129 |
| 113 void AppListServiceAsh::DismissAppList() { | 130 void AppListServiceAsh::DismissAppList() { |
| 114 ash::Shell::GetInstance()->DismissAppList(); | 131 app_list_shower_->Dismiss(); |
| 115 } | 132 } |
| 116 | 133 |
| 117 void AppListServiceAsh::EnableAppList(Profile* initial_profile, | 134 void AppListServiceAsh::EnableAppList(Profile* initial_profile, |
| 118 AppListEnableSource enable_source) {} | 135 AppListEnableSource enable_source) {} |
| 119 | 136 |
| 120 gfx::NativeWindow AppListServiceAsh::GetAppListWindow() { | 137 gfx::NativeWindow AppListServiceAsh::GetAppListWindow() { |
| 121 if (ash::Shell::HasInstance()) | 138 return app_list_shower_->GetWindow(); |
| 122 return ash::Shell::GetInstance()->GetAppListWindow(); | |
| 123 return NULL; | |
| 124 } | 139 } |
| 125 | 140 |
| 126 Profile* AppListServiceAsh::GetCurrentAppListProfile() { | 141 Profile* AppListServiceAsh::GetCurrentAppListProfile() { |
| 127 return ChromeLauncherController::instance()->profile(); | 142 return ChromeLauncherController::instance()->profile(); |
| 128 } | 143 } |
| 129 | 144 |
| 130 AppListControllerDelegate* AppListServiceAsh::GetControllerDelegate() { | 145 AppListControllerDelegate* AppListServiceAsh::GetControllerDelegate() { |
| 131 return controller_delegate_.get(); | 146 return controller_delegate_.get(); |
| 132 } | 147 } |
| 133 | 148 |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 149 return AppListServiceAsh::GetInstance(); | 164 return AppListServiceAsh::GetInstance(); |
| 150 } | 165 } |
| 151 | 166 |
| 152 // static | 167 // static |
| 153 void AppListService::InitAll(Profile* initial_profile, | 168 void AppListService::InitAll(Profile* initial_profile, |
| 154 const base::FilePath& profile_path) { | 169 const base::FilePath& profile_path) { |
| 155 AppListServiceAsh::GetInstance()->Init(initial_profile); | 170 AppListServiceAsh::GetInstance()->Init(initial_profile); |
| 156 } | 171 } |
| 157 | 172 |
| 158 #endif // !defined(OS_WIN) | 173 #endif // !defined(OS_WIN) |
| OLD | NEW |