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

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

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

Powered by Google App Engine
This is Rietveld 408576698