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

Side by Side Diff: chrome/browser/ui/app_list/app_list_view_delegate.cc

Issue 20656002: Add profile selector menu to app list. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove junk from list_model.h Created 7 years, 4 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/app_list/app_list_view_delegate.h" 5 #include "chrome/browser/ui/app_list/app_list_view_delegate.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/stl_util.h"
9 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/chrome_notification_types.h"
10 #include "chrome/browser/extensions/extension_service.h" 12 #include "chrome/browser/extensions/extension_service.h"
11 #include "chrome/browser/feedback/feedback_util.h" 13 #include "chrome/browser/feedback/feedback_util.h"
14 #include "chrome/browser/profiles/profile_info_cache.h"
15 #include "chrome/browser/profiles/profile_info_util.h"
12 #include "chrome/browser/profiles/profile_manager.h" 16 #include "chrome/browser/profiles/profile_manager.h"
13 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h" 17 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h"
14 #include "chrome/browser/ui/app_list/apps_model_builder.h" 18 #include "chrome/browser/ui/app_list/apps_model_builder.h"
15 #include "chrome/browser/ui/app_list/chrome_app_list_item.h" 19 #include "chrome/browser/ui/app_list/chrome_app_list_item.h"
16 #include "chrome/browser/ui/app_list/chrome_signin_delegate.h" 20 #include "chrome/browser/ui/app_list/chrome_signin_delegate.h"
17 #include "chrome/browser/ui/app_list/search/search_controller.h" 21 #include "chrome/browser/ui/app_list/search/search_controller.h"
18 #include "chrome/browser/ui/browser_finder.h" 22 #include "chrome/browser/ui/browser_finder.h"
19 #include "chrome/browser/ui/chrome_pages.h" 23 #include "chrome/browser/ui/chrome_pages.h"
20 #include "chrome/browser/ui/host_desktop.h" 24 #include "chrome/browser/ui/host_desktop.h"
21 #include "chrome/browser/ui/web_applications/web_app_ui.h" 25 #include "chrome/browser/ui/web_applications/web_app_ui.h"
22 #include "chrome/browser/web_applications/web_app.h" 26 #include "chrome/browser/web_applications/web_app.h"
23 #include "chrome/common/extensions/extension_constants.h" 27 #include "chrome/common/extensions/extension_constants.h"
24 #include "chrome/common/url_constants.h" 28 #include "chrome/common/url_constants.h"
25 #include "content/public/browser/browser_thread.h" 29 #include "content/public/browser/browser_thread.h"
30 #include "content/public/browser/notification_details.h"
31 #include "content/public/browser/notification_service.h"
32 #include "content/public/browser/notification_source.h"
26 #include "content/public/browser/page_navigator.h" 33 #include "content/public/browser/page_navigator.h"
27 #include "content/public/browser/user_metrics.h" 34 #include "content/public/browser/user_metrics.h"
35 #include "ui/app_list/search_box_model.h"
36 #include "ui/base/profile_selector/avatar_menu_item_model.h"
28 37
29 #if defined(USE_ASH) 38 #if defined(USE_ASH)
30 #include "chrome/browser/ui/ash/app_list/app_sync_ui_state_watcher.h" 39 #include "chrome/browser/ui/ash/app_list/app_sync_ui_state_watcher.h"
31 #endif 40 #endif
32 41
33 #if defined(OS_WIN) 42 #if defined(OS_WIN)
34 #include "chrome/browser/web_applications/web_app_win.h" 43 #include "chrome/browser/web_applications/web_app_win.h"
35 #endif 44 #endif
36 45
37 namespace { 46 namespace {
38 47
39 #if defined(OS_WIN) 48 #if defined(OS_WIN)
40 void CreateShortcutInWebAppDir( 49 void CreateShortcutInWebAppDir(
41 const base::FilePath& app_data_dir, 50 const base::FilePath& app_data_dir,
42 base::Callback<void(const base::FilePath&)> callback, 51 base::Callback<void(const base::FilePath&)> callback,
43 const ShellIntegration::ShortcutInfo& info) { 52 const ShellIntegration::ShortcutInfo& info) {
44 content::BrowserThread::PostTaskAndReplyWithResult( 53 content::BrowserThread::PostTaskAndReplyWithResult(
45 content::BrowserThread::FILE, 54 content::BrowserThread::FILE,
46 FROM_HERE, 55 FROM_HERE,
47 base::Bind(web_app::CreateShortcutInWebAppDir, app_data_dir, info), 56 base::Bind(web_app::CreateShortcutInWebAppDir, app_data_dir, info),
48 callback); 57 callback);
49 } 58 }
50 #endif 59 #endif
51 60
52 } // namespace 61 } // namespace
53 62
54 AppListViewDelegate::AppListViewDelegate(AppListControllerDelegate* controller, 63 AppListViewDelegate::AppListViewDelegate(AppListControllerDelegate* controller,
55 Profile* profile) 64 Profile* profile)
56 : controller_(controller), 65 : controller_(controller),
57 profile_(profile) {} 66 profile_(profile),
67 model_(NULL) {
68 RegisterForNotifications();
69 }
58 70
59 AppListViewDelegate::~AppListViewDelegate() {} 71 AppListViewDelegate::~AppListViewDelegate() {
72 signin_delegate_->RemoveObserver(this);
73 }
60 74
61 void AppListViewDelegate::SetModel(app_list::AppListModel* model) { 75 void AppListViewDelegate::RegisterForNotifications() {
62 if (model) { 76 DCHECK(profile_);
63 apps_builder_.reset(new AppsModelBuilder(profile_, 77 registrar_.RemoveAll();
64 model->apps(), 78 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED,
65 controller_.get())); 79 content::NotificationService::AllSources());
66 apps_builder_->Build(); 80 registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL,
81 content::Source<Profile>(profile_));
82 registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_SIGNIN_FAILED,
83 content::Source<Profile>(profile_));
84 registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_SIGNED_OUT,
85 content::Source<Profile>(profile_));
86 }
67 87
68 search_controller_.reset(new app_list::SearchController( 88 void AppListViewDelegate::SetProfileByPath(const base::FilePath& profile_path) {
69 profile_, model->search_box(), model->results(), controller_.get())); 89 DCHECK(model_);
70 90
71 signin_delegate_.reset(new ChromeSigninDelegate(profile_)); 91 // The profile must be loaded before this is called.
92 profile_ =
93 g_browser_process->profile_manager()->GetProfileByPath(profile_path);
94 DCHECK(profile_);
95
96 RegisterForNotifications();
97
98 apps_builder_->SetProfile(profile_);
99
100 search_controller_.reset(new app_list::SearchController(
101 profile_, model_->search_box(), model_->results(), controller_.get()));
102
103 signin_delegate_->SetProfileByPath(profile_path);
72 104
73 #if defined(USE_ASH) 105 #if defined(USE_ASH)
74 app_sync_ui_state_watcher_.reset(new AppSyncUIStateWatcher(profile_, 106 app_sync_ui_state_watcher_.reset(new AppSyncUIStateWatcher(profile_,
75 model)); 107 model_));
76 #endif 108 #endif
77 } else { 109
78 apps_builder_.reset(); 110 UpdateModelWithCurrentProfiles();
79 search_controller_.reset(); 111
112 if (!model_->search_box()->text().empty())
113 StartSearch();
114 }
115
116 void AppListViewDelegate::InitModel(app_list::AppListModel* model) {
117 DCHECK(!model_);
118 DCHECK(model);
119 model_ = model;
120
121 // Initialize apps model.
122 apps_builder_.reset(new AppsModelBuilder(profile_,
123 model->apps(),
124 controller_.get()));
125 apps_builder_->Build();
126
127 search_controller_.reset(new app_list::SearchController(
128 profile_, model->search_box(), model->results(), controller_.get()));
129
130 signin_delegate_.reset(new ChromeSigninDelegate(profile_));
131 signin_delegate_->AddObserver(this);
132
80 #if defined(USE_ASH) 133 #if defined(USE_ASH)
81 app_sync_ui_state_watcher_.reset(); 134 app_sync_ui_state_watcher_.reset(new AppSyncUIStateWatcher(profile_,
135 model));
82 #endif 136 #endif
83 } 137 // Initialize the profile information in the app list menu.
138 UpdateModelWithCurrentProfiles();
84 } 139 }
85 140
86 app_list::SigninDelegate* AppListViewDelegate::GetSigninDelegate() { 141 app_list::SigninDelegate* AppListViewDelegate::GetSigninDelegate() {
87 return signin_delegate_.get(); 142 return signin_delegate_.get();
88 } 143 }
89 144
90 void AppListViewDelegate::ActivateAppListItem( 145 void AppListViewDelegate::ActivateAppListItem(
91 app_list::AppListItemModel* item, 146 app_list::AppListItemModel* item,
92 int event_flags) { 147 int event_flags) {
93 content::RecordAction(content::UserMetricsAction("AppList_ClickOnApp")); 148 content::RecordAction(content::UserMetricsAction("AppList_ClickOnApp"));
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 } 208 }
154 209
155 void AppListViewDelegate::ViewActivationChanged(bool active) { 210 void AppListViewDelegate::ViewActivationChanged(bool active) {
156 controller_->ViewActivationChanged(active); 211 controller_->ViewActivationChanged(active);
157 } 212 }
158 213
159 gfx::ImageSkia AppListViewDelegate::GetWindowIcon() { 214 gfx::ImageSkia AppListViewDelegate::GetWindowIcon() {
160 return controller_->GetWindowIcon(); 215 return controller_->GetWindowIcon();
161 } 216 }
162 217
163 string16 AppListViewDelegate::GetCurrentUserName() {
164 ProfileInfoCache& cache =
165 g_browser_process->profile_manager()->GetProfileInfoCache();
166 size_t profile_index = cache.GetIndexOfProfileWithPath(profile_->GetPath());
167 if (profile_index != std::string::npos)
168 return cache.GetNameOfProfileAtIndex(profile_index);
169
170 return string16();
171 }
172
173 string16 AppListViewDelegate::GetCurrentUserEmail() {
174 ProfileInfoCache& cache =
175 g_browser_process->profile_manager()->GetProfileInfoCache();
176 size_t profile_index = cache.GetIndexOfProfileWithPath(profile_->GetPath());
177 if (profile_index != std::string::npos)
178 return cache.GetUserNameOfProfileAtIndex(profile_index);
179
180 return string16();
181 }
182
183 void AppListViewDelegate::OpenSettings() { 218 void AppListViewDelegate::OpenSettings() {
184 ExtensionService* service = profile_->GetExtensionService(); 219 ExtensionService* service = profile_->GetExtensionService();
185 DCHECK(service); 220 DCHECK(service);
186 const extensions::Extension* extension = service->GetInstalledExtension( 221 const extensions::Extension* extension = service->GetInstalledExtension(
187 extension_misc::kSettingsAppId); 222 extension_misc::kSettingsAppId);
188 DCHECK(extension); 223 DCHECK(extension);
189 controller_->ActivateApp(profile_, extension, 0); 224 controller_->ActivateApp(profile_, extension, 0);
190 } 225 }
191 226
192 void AppListViewDelegate::OpenHelp() { 227 void AppListViewDelegate::OpenHelp() {
193 chrome::HostDesktopType desktop = chrome::GetHostDesktopTypeForNativeWindow( 228 chrome::HostDesktopType desktop = chrome::GetHostDesktopTypeForNativeWindow(
194 controller_->GetAppListWindow()); 229 controller_->GetAppListWindow());
195 Browser* browser = chrome::FindOrCreateTabbedBrowser( 230 Browser* browser = chrome::FindOrCreateTabbedBrowser(
196 profile_, desktop); 231 profile_, desktop);
197 browser->OpenURL(content::OpenURLParams(GURL(chrome::kAppLauncherHelpURL), 232 browser->OpenURL(content::OpenURLParams(GURL(chrome::kAppLauncherHelpURL),
198 content::Referrer(), 233 content::Referrer(),
199 NEW_FOREGROUND_TAB, 234 NEW_FOREGROUND_TAB,
200 content::PAGE_TRANSITION_LINK, 235 content::PAGE_TRANSITION_LINK,
201 false)); 236 false));
202 } 237 }
203 238
204 void AppListViewDelegate::OpenFeedback() { 239 void AppListViewDelegate::OpenFeedback() {
205 chrome::HostDesktopType desktop = chrome::GetHostDesktopTypeForNativeWindow( 240 chrome::HostDesktopType desktop = chrome::GetHostDesktopTypeForNativeWindow(
206 controller_->GetAppListWindow()); 241 controller_->GetAppListWindow());
207 Browser* browser = chrome::FindOrCreateTabbedBrowser( 242 Browser* browser = chrome::FindOrCreateTabbedBrowser(
208 profile_, desktop); 243 profile_, desktop);
209 chrome::ShowFeedbackPage(browser, std::string(), 244 chrome::ShowFeedbackPage(browser, std::string(),
210 chrome::kAppLauncherCategoryTag); 245 chrome::kAppLauncherCategoryTag);
211 } 246 }
247
248 void AppListViewDelegate::ShowForProfileByPath(
249 const base::FilePath& profile_path) {
250 controller_->ShowForProfileByPath(profile_path);
251 }
252
253 void AppListViewDelegate::UpdateModelWithCurrentProfiles() {
254 model_->SetSignedIn(!signin_delegate_->NeedSignin());
255 ProfileInfoCache& cache =
256 g_browser_process->profile_manager()->GetProfileInfoCache();
257 // Populate the current user details.
258 size_t profile_index = cache.GetIndexOfProfileWithPath(profile_->GetPath());
259 // The profile won't exist in the cache if the current app list profile is
260 // being deleted.
261 if (profile_index == std::string::npos)
262 return;
tapted 2013/08/05 03:01:39 nit: blank line after early return
calamity 2013/08/08 04:52:12 Done.
263 model_->SetCurrentUser(cache.GetNameOfProfileAtIndex(profile_index),
264 cache.GetUserNameOfProfileAtIndex(profile_index));
265
266 // Populate the profile menu items;
tapted 2013/08/05 03:01:39 semicolon should be a .
calamity 2013/08/08 04:52:12 Done.
267 app_list::AppListModel::ProfileMenuItems profile_menu_items;
268 profiles::PopulateAvatarMenuItemModels(&cache,
269 base::FilePath(),
270 &profile_menu_items);
271 model_->SetProfileMenuItems(profile_menu_items);
272 }
273
274 void AppListViewDelegate::OnSigninSuccess() {
275 UpdateModelWithCurrentProfiles();
276 }
277
278 void AppListViewDelegate::Observe(
279 int type,
280 const content::NotificationSource& source,
281 const content::NotificationDetails& details) {
282 UpdateModelWithCurrentProfiles();
283 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698