Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(909)

Side by Side Diff: chrome/browser/ui/ash/app_list/app_list_service_ash.cc

Issue 1861013004: AppListController refactoring part 3: Switching over to use AppListShower in Ash. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mus_chrome_delegates_ash_impl
Patch Set: Rebase. Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
7 #include "ash/shell.h" 10 #include "ash/shell.h"
8 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "base/memory/ptr_util.h"
9 #include "base/memory/singleton.h" 13 #include "base/memory/singleton.h"
10 #include "build/build_config.h" 14 #include "build/build_config.h"
11 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/ui/app_list/app_list_view_delegate.h"
12 #include "chrome/browser/ui/app_list/start_page_service.h" 17 #include "chrome/browser/ui/app_list/start_page_service.h"
13 #include "chrome/browser/ui/ash/app_list/app_list_controller_ash.h" 18 #include "chrome/browser/ui/ash/app_list/app_list_controller_ash.h"
14 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" 19 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
20 #include "chrome/browser/ui/ash/session_util.h"
15 #include "ui/app_list/app_list_switches.h" 21 #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"
16 #include "ui/app_list/views/app_list_main_view.h" 24 #include "ui/app_list/views/app_list_main_view.h"
17 #include "ui/app_list/views/app_list_view.h" 25 #include "ui/app_list/views/app_list_view.h"
18 #include "ui/app_list/views/contents_view.h" 26 #include "ui/app_list/views/contents_view.h"
19 27
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
20 // static 50 // static
21 AppListServiceAsh* AppListServiceAsh::GetInstance() { 51 AppListServiceAsh* AppListServiceAsh::GetInstance() {
22 return base::Singleton<AppListServiceAsh, 52 return base::Singleton<AppListServiceAsh,
23 base::LeakySingletonTraits<AppListServiceAsh>>::get(); 53 base::LeakySingletonTraits<AppListServiceAsh>>::get();
24 } 54 }
25 55
26 AppListServiceAsh::AppListServiceAsh() 56 AppListServiceAsh::AppListServiceAsh()
27 : controller_delegate_(new AppListControllerDelegateAsh()) { 57 : shower_delegate_factory_(new ash::AppListShowerDelegateFactory(
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()));
28 } 63 }
29 64
30 AppListServiceAsh::~AppListServiceAsh() { 65 AppListServiceAsh::~AppListServiceAsh() {
31 } 66 }
32 67
68 app_list::AppListShower* AppListServiceAsh::GetAppListShower() {
69 return app_list_shower_.get();
70 }
71
72 void AppListServiceAsh::Init(Profile* initial_profile) {
73 // Ensure the StartPageService is created here. This early initialization is
74 // necessary to allow the WebContents to load before the app list is shown.
75 app_list::StartPageService* service =
76 app_list::StartPageService::Get(initial_profile);
77 if (service)
78 service->Init();
79 }
80
81 void AppListServiceAsh::OnProfileWillBeRemoved(
82 const base::FilePath& profile_path) {}
83
33 void AppListServiceAsh::ShowAndSwitchToState( 84 void AppListServiceAsh::ShowAndSwitchToState(
34 app_list::AppListModel::State state) { 85 app_list::AppListModel::State state) {
35 bool app_list_was_open = true; 86 bool app_list_was_open = true;
36 app_list::AppListView* app_list_view = 87 app_list::AppListView* app_list_view = app_list_shower_->GetView();
37 ash::Shell::GetInstance()->GetAppListView();
38 if (!app_list_view) { 88 if (!app_list_view) {
39 // TODO(calamity): This may cause the app list to show briefly before the 89 // 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 90 // state change. If this becomes an issue, add the ability to ash::Shell to
41 // load the app list without showing it. 91 // load the app list without showing it.
42 ash::Shell::GetInstance()->ShowAppList(NULL); 92 app_list_shower_->Show(ash::Shell::GetTargetRootWindow());
43 app_list_was_open = false; 93 app_list_was_open = false;
44 app_list_view = ash::Shell::GetInstance()->GetAppListView(); 94 app_list_view = app_list_shower_->GetView();
45 DCHECK(app_list_view); 95 DCHECK(app_list_view);
46 } 96 }
47 97
48 if (state == app_list::AppListModel::INVALID_STATE) 98 if (state == app_list::AppListModel::INVALID_STATE)
49 return; 99 return;
50 100
51 app_list::ContentsView* contents_view = 101 app_list::ContentsView* contents_view =
52 app_list_view->app_list_main_view()->contents_view(); 102 app_list_view->app_list_main_view()->contents_view();
53 contents_view->SetActiveState(state, app_list_was_open /* animate */); 103 contents_view->SetActiveState(state, app_list_was_open /* animate */);
54 } 104 }
55 105
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( 106 base::FilePath AppListServiceAsh::GetProfilePath(
70 const base::FilePath& user_data_dir) { 107 const base::FilePath& user_data_dir) {
71 return ChromeLauncherController::instance()->profile()->GetPath(); 108 return ChromeLauncherController::instance()->profile()->GetPath();
72 } 109 }
73 110
74 void AppListServiceAsh::ShowForProfile(Profile* /*default_profile*/) { 111 void AppListServiceAsh::ShowForProfile(Profile* /*default_profile*/) {
75 // This may not work correctly if the profile passed in is different from the 112 // This may not work correctly if the profile passed in is different from the
76 // one the ash Shell is currently using. 113 // one the ash Shell is currently using.
77 // TODO(ananta): Handle profile changes correctly when !defined(OS_CHROMEOS). 114 // TODO(ananta): Handle profile changes correctly when !defined(OS_CHROMEOS).
78 ash::Shell::GetInstance()->ShowAppList(NULL); 115 app_list_shower_->Show(ash::Shell::GetTargetRootWindow());
79 } 116 }
80 117
81 void AppListServiceAsh::ShowForAppInstall(Profile* profile, 118 void AppListServiceAsh::ShowForAppInstall(Profile* profile,
82 const std::string& extension_id, 119 const std::string& extension_id,
83 bool start_discovery_tracking) { 120 bool start_discovery_tracking) {
84 if (app_list::switches::IsExperimentalAppListEnabled()) 121 if (app_list::switches::IsExperimentalAppListEnabled())
85 ShowAndSwitchToState(app_list::AppListModel::STATE_APPS); 122 ShowAndSwitchToState(app_list::AppListModel::STATE_APPS);
86 123
87 AppListServiceImpl::ShowForAppInstall(profile, extension_id, 124 AppListServiceImpl::ShowForAppInstall(profile, extension_id,
88 start_discovery_tracking); 125 start_discovery_tracking);
89 } 126 }
90 127
91 void AppListServiceAsh::ShowForCustomLauncherPage(Profile* /*profile*/) { 128 void AppListServiceAsh::ShowForCustomLauncherPage(Profile* /*profile*/) {
92 ShowAndSwitchToState(app_list::AppListModel::STATE_CUSTOM_LAUNCHER_PAGE); 129 ShowAndSwitchToState(app_list::AppListModel::STATE_CUSTOM_LAUNCHER_PAGE);
93 } 130 }
94 131
95 void AppListServiceAsh::HideCustomLauncherPage() { 132 void AppListServiceAsh::HideCustomLauncherPage() {
96 app_list::AppListView* app_list_view = 133 app_list::AppListView* app_list_view = app_list_shower_->GetView();
97 ash::Shell::GetInstance()->GetAppListView();
98 if (!app_list_view) 134 if (!app_list_view)
99 return; 135 return;
100 136
101 app_list::ContentsView* contents_view = 137 app_list::ContentsView* contents_view =
102 app_list_view->app_list_main_view()->contents_view(); 138 app_list_view->app_list_main_view()->contents_view();
103 if (contents_view->IsStateActive( 139 if (contents_view->IsStateActive(
104 app_list::AppListModel::STATE_CUSTOM_LAUNCHER_PAGE)) { 140 app_list::AppListModel::STATE_CUSTOM_LAUNCHER_PAGE)) {
105 contents_view->SetActiveState(app_list::AppListModel::STATE_START, true); 141 contents_view->SetActiveState(app_list::AppListModel::STATE_START, true);
106 } 142 }
107 } 143 }
108 144
109 bool AppListServiceAsh::IsAppListVisible() const { 145 bool AppListServiceAsh::IsAppListVisible() const {
110 return ash::Shell::GetInstance()->GetAppListTargetVisibility(); 146 return app_list_shower_->GetTargetVisibility();
111 } 147 }
112 148
113 void AppListServiceAsh::DismissAppList() { 149 void AppListServiceAsh::DismissAppList() {
114 ash::Shell::GetInstance()->DismissAppList(); 150 app_list_shower_->Dismiss();
115 } 151 }
116 152
117 void AppListServiceAsh::EnableAppList(Profile* initial_profile, 153 void AppListServiceAsh::EnableAppList(Profile* initial_profile,
118 AppListEnableSource enable_source) {} 154 AppListEnableSource enable_source) {}
119 155
120 gfx::NativeWindow AppListServiceAsh::GetAppListWindow() { 156 gfx::NativeWindow AppListServiceAsh::GetAppListWindow() {
121 if (ash::Shell::HasInstance()) 157 return app_list_shower_->GetWindow();
122 return ash::Shell::GetInstance()->GetAppListWindow();
123 return NULL;
124 } 158 }
125 159
126 Profile* AppListServiceAsh::GetCurrentAppListProfile() { 160 Profile* AppListServiceAsh::GetCurrentAppListProfile() {
127 return ChromeLauncherController::instance()->profile(); 161 return ChromeLauncherController::instance()->profile();
128 } 162 }
129 163
130 AppListControllerDelegate* AppListServiceAsh::GetControllerDelegate() { 164 AppListControllerDelegate* AppListServiceAsh::GetControllerDelegate() {
131 return controller_delegate_.get(); 165 return controller_delegate_.get();
132 } 166 }
133 167
(...skipping 15 matching lines...) Expand all
149 return AppListServiceAsh::GetInstance(); 183 return AppListServiceAsh::GetInstance();
150 } 184 }
151 185
152 // static 186 // static
153 void AppListService::InitAll(Profile* initial_profile, 187 void AppListService::InitAll(Profile* initial_profile,
154 const base::FilePath& profile_path) { 188 const base::FilePath& profile_path) {
155 AppListServiceAsh::GetInstance()->Init(initial_profile); 189 AppListServiceAsh::GetInstance()->Init(initial_profile);
156 } 190 }
157 191
158 #endif // !defined(OS_WIN) 192 #endif // !defined(OS_WIN)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698