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

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: small fixups 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"
10 #include "chrome/browser/extensions/extension_service.h" 11 #include "chrome/browser/extensions/extension_service.h"
11 #include "chrome/browser/feedback/feedback_util.h" 12 #include "chrome/browser/feedback/feedback_util.h"
13 #include "chrome/browser/profiles/profile_info_cache.h"
14 #include "chrome/browser/profiles/profile_info_util.h"
12 #include "chrome/browser/profiles/profile_manager.h" 15 #include "chrome/browser/profiles/profile_manager.h"
13 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h" 16 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h"
14 #include "chrome/browser/ui/app_list/apps_model_builder.h" 17 #include "chrome/browser/ui/app_list/apps_model_builder.h"
15 #include "chrome/browser/ui/app_list/chrome_app_list_item.h" 18 #include "chrome/browser/ui/app_list/chrome_app_list_item.h"
16 #include "chrome/browser/ui/app_list/chrome_signin_delegate.h" 19 #include "chrome/browser/ui/app_list/chrome_signin_delegate.h"
17 #include "chrome/browser/ui/app_list/search/search_controller.h" 20 #include "chrome/browser/ui/app_list/search/search_controller.h"
18 #include "chrome/browser/ui/browser_finder.h" 21 #include "chrome/browser/ui/browser_finder.h"
19 #include "chrome/browser/ui/chrome_pages.h" 22 #include "chrome/browser/ui/chrome_pages.h"
20 #include "chrome/browser/ui/host_desktop.h" 23 #include "chrome/browser/ui/host_desktop.h"
21 #include "chrome/browser/ui/web_applications/web_app_ui.h" 24 #include "chrome/browser/ui/web_applications/web_app_ui.h"
22 #include "chrome/browser/web_applications/web_app.h" 25 #include "chrome/browser/web_applications/web_app.h"
23 #include "chrome/common/extensions/extension_constants.h" 26 #include "chrome/common/extensions/extension_constants.h"
24 #include "chrome/common/url_constants.h" 27 #include "chrome/common/url_constants.h"
25 #include "content/public/browser/browser_thread.h" 28 #include "content/public/browser/browser_thread.h"
26 #include "content/public/browser/page_navigator.h" 29 #include "content/public/browser/page_navigator.h"
27 #include "content/public/browser/user_metrics.h" 30 #include "content/public/browser/user_metrics.h"
31 #include "ui/app_list/search_box_model.h"
32 #include "ui/base/profile_selector/avatar_menu_item_model.h"
28 33
29 #if defined(USE_ASH) 34 #if defined(USE_ASH)
30 #include "chrome/browser/ui/ash/app_list/app_sync_ui_state_watcher.h" 35 #include "chrome/browser/ui/ash/app_list/app_sync_ui_state_watcher.h"
31 #endif 36 #endif
32 37
33 #if defined(OS_WIN) 38 #if defined(OS_WIN)
34 #include "chrome/browser/web_applications/web_app_win.h" 39 #include "chrome/browser/web_applications/web_app_win.h"
35 #endif 40 #endif
36 41
37 namespace { 42 namespace {
38 43
39 #if defined(OS_WIN) 44 #if defined(OS_WIN)
40 void CreateShortcutInWebAppDir( 45 void CreateShortcutInWebAppDir(
41 const base::FilePath& app_data_dir, 46 const base::FilePath& app_data_dir,
42 base::Callback<void(const base::FilePath&)> callback, 47 base::Callback<void(const base::FilePath&)> callback,
43 const ShellIntegration::ShortcutInfo& info) { 48 const ShellIntegration::ShortcutInfo& info) {
44 content::BrowserThread::PostTaskAndReplyWithResult( 49 content::BrowserThread::PostTaskAndReplyWithResult(
45 content::BrowserThread::FILE, 50 content::BrowserThread::FILE,
46 FROM_HERE, 51 FROM_HERE,
47 base::Bind(web_app::CreateShortcutInWebAppDir, app_data_dir, info), 52 base::Bind(web_app::CreateShortcutInWebAppDir, app_data_dir, info),
48 callback); 53 callback);
49 } 54 }
50 #endif 55 #endif
51 56
52 } // namespace 57 } // namespace
53 58
54 AppListViewDelegate::AppListViewDelegate(AppListControllerDelegate* controller, 59 AppListViewDelegate::AppListViewDelegate(AppListControllerDelegate* controller,
55 Profile* profile) 60 Profile* profile)
56 : controller_(controller), 61 : controller_(controller),
57 profile_(profile) {} 62 profile_(profile),
63 model_(NULL) {}
58 64
59 AppListViewDelegate::~AppListViewDelegate() {} 65 AppListViewDelegate::~AppListViewDelegate() {}
60 66
61 void AppListViewDelegate::SetModel(app_list::AppListModel* model) { 67 void AppListViewDelegate::SetProfileByPath(base::FilePath profile_path) {
62 if (model) { 68 DCHECK(model_);
63 apps_builder_.reset(new AppsModelBuilder(profile_,
64 model->apps(),
65 controller_.get()));
66 apps_builder_->Build();
67 69
68 search_controller_.reset(new app_list::SearchController( 70 // The profile must be loaded before this is called.
69 profile_, model->search_box(), model->results(), controller_.get())); 71 profile_ =
72 g_browser_process->profile_manager()->GetProfileByPath(profile_path);
73 DCHECK(profile_);
70 74
71 signin_delegate_.reset(new ChromeSigninDelegate(profile_)); 75 apps_builder_->SetProfile(profile_);
76
77 search_controller_.reset(new app_list::SearchController(
78 profile_, model_->search_box(), model_->results(), controller_.get()));
79
80 signin_delegate_->SetProfileByPath(profile_path);
72 81
73 #if defined(USE_ASH) 82 #if defined(USE_ASH)
74 app_sync_ui_state_watcher_.reset(new AppSyncUIStateWatcher(profile_, 83 app_sync_ui_state_watcher_.reset(new AppSyncUIStateWatcher(profile_,
75 model)); 84 model_));
76 #endif 85 #endif
77 } else { 86
78 apps_builder_.reset(); 87 UpdateModelWithCurrentProfiles();
79 search_controller_.reset(); 88
89 if (!model_->search_box()->text().empty())
90 StartSearch();
91 }
92
93 void AppListViewDelegate::InitModel(app_list::AppListModel* model) {
94 DCHECK(model);
koz (OOO until 15th September) 2013/08/02 01:51:16 DCHECK(!model_), too.
calamity 2013/08/02 09:59:54 Done.
95 model_ = model;
96
97 // Initialize the profile information in the app list menu.
98 UpdateModelWithCurrentProfiles();
99
100 // Initialize apps model.
101 apps_builder_.reset(new AppsModelBuilder(profile_,
102 model->apps(),
103 controller_.get()));
104 apps_builder_->Build();
105
106 search_controller_.reset(new app_list::SearchController(
107 profile_, model->search_box(), model->results(), controller_.get()));
108
109 signin_delegate_.reset(new ChromeSigninDelegate(profile_));
110
80 #if defined(USE_ASH) 111 #if defined(USE_ASH)
81 app_sync_ui_state_watcher_.reset(); 112 app_sync_ui_state_watcher_.reset(new AppSyncUIStateWatcher(profile_,
113 model));
82 #endif 114 #endif
83 }
84 } 115 }
85 116
86 app_list::SigninDelegate* AppListViewDelegate::GetSigninDelegate() { 117 app_list::SigninDelegate* AppListViewDelegate::GetSigninDelegate() {
87 return signin_delegate_.get(); 118 return signin_delegate_.get();
88 } 119 }
89 120
90 void AppListViewDelegate::ActivateAppListItem( 121 void AppListViewDelegate::ActivateAppListItem(
91 app_list::AppListItemModel* item, 122 app_list::AppListItemModel* item,
92 int event_flags) { 123 int event_flags) {
93 content::RecordAction(content::UserMetricsAction("AppList_ClickOnApp")); 124 content::RecordAction(content::UserMetricsAction("AppList_ClickOnApp"));
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 } 184 }
154 185
155 void AppListViewDelegate::ViewActivationChanged(bool active) { 186 void AppListViewDelegate::ViewActivationChanged(bool active) {
156 controller_->ViewActivationChanged(active); 187 controller_->ViewActivationChanged(active);
157 } 188 }
158 189
159 gfx::ImageSkia AppListViewDelegate::GetWindowIcon() { 190 gfx::ImageSkia AppListViewDelegate::GetWindowIcon() {
160 return controller_->GetWindowIcon(); 191 return controller_->GetWindowIcon();
161 } 192 }
162 193
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() { 194 void AppListViewDelegate::OpenSettings() {
184 ExtensionService* service = profile_->GetExtensionService(); 195 ExtensionService* service = profile_->GetExtensionService();
185 DCHECK(service); 196 DCHECK(service);
186 const extensions::Extension* extension = service->GetInstalledExtension( 197 const extensions::Extension* extension = service->GetInstalledExtension(
187 extension_misc::kSettingsAppId); 198 extension_misc::kSettingsAppId);
188 DCHECK(extension); 199 DCHECK(extension);
189 controller_->ActivateApp(profile_, extension, 0); 200 controller_->ActivateApp(profile_, extension, 0);
190 } 201 }
191 202
192 void AppListViewDelegate::OpenHelp() { 203 void AppListViewDelegate::OpenHelp() {
193 chrome::HostDesktopType desktop = chrome::GetHostDesktopTypeForNativeWindow( 204 chrome::HostDesktopType desktop = chrome::GetHostDesktopTypeForNativeWindow(
194 controller_->GetAppListWindow()); 205 controller_->GetAppListWindow());
195 Browser* browser = chrome::FindOrCreateTabbedBrowser( 206 Browser* browser = chrome::FindOrCreateTabbedBrowser(
196 profile_, desktop); 207 profile_, desktop);
197 browser->OpenURL(content::OpenURLParams(GURL(chrome::kAppLauncherHelpURL), 208 browser->OpenURL(content::OpenURLParams(GURL(chrome::kAppLauncherHelpURL),
198 content::Referrer(), 209 content::Referrer(),
199 NEW_FOREGROUND_TAB, 210 NEW_FOREGROUND_TAB,
200 content::PAGE_TRANSITION_LINK, 211 content::PAGE_TRANSITION_LINK,
201 false)); 212 false));
202 } 213 }
203 214
204 void AppListViewDelegate::OpenFeedback() { 215 void AppListViewDelegate::OpenFeedback() {
205 chrome::HostDesktopType desktop = chrome::GetHostDesktopTypeForNativeWindow( 216 chrome::HostDesktopType desktop = chrome::GetHostDesktopTypeForNativeWindow(
206 controller_->GetAppListWindow()); 217 controller_->GetAppListWindow());
207 Browser* browser = chrome::FindOrCreateTabbedBrowser( 218 Browser* browser = chrome::FindOrCreateTabbedBrowser(
208 profile_, desktop); 219 profile_, desktop);
209 chrome::ShowFeedbackPage(browser, std::string(), 220 chrome::ShowFeedbackPage(browser, std::string(),
210 chrome::kAppLauncherCategoryTag); 221 chrome::kAppLauncherCategoryTag);
211 } 222 }
223
224 void AppListViewDelegate::ShowForProfileByPath(base::FilePath profile_path) {
225 controller_->ShowForProfileByPath(profile_path);
226 }
227
228 void AppListViewDelegate::UpdateModelWithCurrentProfiles() {
229 ProfileInfoCache& cache =
230 g_browser_process->profile_manager()->GetProfileInfoCache();
231 // Populate the current user details.
232 size_t profile_index = cache.GetIndexOfProfileWithPath(profile_->GetPath());
233 DCHECK_NE(profile_index, std::string::npos);
234 model_->SetCurrentUser(cache.GetNameOfProfileAtIndex(profile_index),
235 cache.GetUserNameOfProfileAtIndex(profile_index));
236
237 // Populate the profile menu items;
238 app_list::AppListModel::ProfileMenuItems profile_menu_items;
239 profiles::PopulateAvatarMenuItemModels(profile_menu_items,
240 &cache,
241 base::FilePath());
242 model_->SetProfileMenuItems(profile_menu_items);
243 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698