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

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: rebase, remove dead code in app_list_menu_views, add ui assets Created 7 years, 3 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/chrome_notification_types.h" 11 #include "chrome/browser/chrome_notification_types.h"
11 #include "chrome/browser/extensions/extension_service.h" 12 #include "chrome/browser/extensions/extension_service.h"
12 #include "chrome/browser/feedback/feedback_util.h" 13 #include "chrome/browser/feedback/feedback_util.h"
14 #include "chrome/browser/profiles/profile_info_cache.h"
13 #include "chrome/browser/profiles/profile_manager.h" 15 #include "chrome/browser/profiles/profile_manager.h"
14 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h" 16 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h"
15 #include "chrome/browser/ui/app_list/apps_model_builder.h" 17 #include "chrome/browser/ui/app_list/apps_model_builder.h"
16 #include "chrome/browser/ui/app_list/chrome_app_list_item.h" 18 #include "chrome/browser/ui/app_list/chrome_app_list_item.h"
17 #include "chrome/browser/ui/app_list/chrome_signin_delegate.h" 19 #include "chrome/browser/ui/app_list/chrome_signin_delegate.h"
18 #include "chrome/browser/ui/app_list/search/search_controller.h" 20 #include "chrome/browser/ui/app_list/search/search_controller.h"
19 #include "chrome/browser/ui/browser_finder.h" 21 #include "chrome/browser/ui/browser_finder.h"
20 #include "chrome/browser/ui/chrome_pages.h" 22 #include "chrome/browser/ui/chrome_pages.h"
21 #include "chrome/browser/ui/host_desktop.h" 23 #include "chrome/browser/ui/host_desktop.h"
22 #include "chrome/browser/ui/web_applications/web_app_ui.h" 24 #include "chrome/browser/ui/web_applications/web_app_ui.h"
23 #include "chrome/browser/web_applications/web_app.h" 25 #include "chrome/browser/web_applications/web_app.h"
24 #include "chrome/common/extensions/extension_constants.h" 26 #include "chrome/common/extensions/extension_constants.h"
25 #include "chrome/common/url_constants.h" 27 #include "chrome/common/url_constants.h"
26 #include "content/public/browser/browser_thread.h" 28 #include "content/public/browser/browser_thread.h"
27 #include "content/public/browser/notification_source.h" 29 #include "content/public/browser/notification_source.h"
28 #include "content/public/browser/page_navigator.h" 30 #include "content/public/browser/page_navigator.h"
29 #include "content/public/browser/user_metrics.h" 31 #include "content/public/browser/user_metrics.h"
32 #include "ui/app_list/search_box_model.h"
30 33
31 #if defined(USE_ASH) 34 #if defined(USE_ASH)
32 #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"
33 #endif 36 #endif
34 37
35 #if defined(OS_WIN) 38 #if defined(OS_WIN)
36 #include "chrome/browser/web_applications/web_app_win.h" 39 #include "chrome/browser/web_applications/web_app_win.h"
37 #endif 40 #endif
38 41
39 namespace { 42 namespace {
40 43
41 #if defined(OS_WIN) 44 #if defined(OS_WIN)
42 void CreateShortcutInWebAppDir( 45 void CreateShortcutInWebAppDir(
43 const base::FilePath& app_data_dir, 46 const base::FilePath& app_data_dir,
44 base::Callback<void(const base::FilePath&)> callback, 47 base::Callback<void(const base::FilePath&)> callback,
45 const ShellIntegration::ShortcutInfo& info) { 48 const ShellIntegration::ShortcutInfo& info) {
46 content::BrowserThread::PostTaskAndReplyWithResult( 49 content::BrowserThread::PostTaskAndReplyWithResult(
47 content::BrowserThread::FILE, 50 content::BrowserThread::FILE,
48 FROM_HERE, 51 FROM_HERE,
49 base::Bind(web_app::CreateShortcutInWebAppDir, app_data_dir, info), 52 base::Bind(web_app::CreateShortcutInWebAppDir, app_data_dir, info),
50 callback); 53 callback);
51 } 54 }
52 #endif 55 #endif
53 56
57 void PopulateUsers(ProfileInfoCache& profile_info,
koz (OOO until 15th September) 2013/09/09 22:58:07 Use a const ref or a pointer, non-const refs are a
calamity 2013/09/10 22:50:46 Done.
58 base::FilePath active_profile_path,
tapted 2013/09/10 00:29:26 nit: const-ref for this guy too ;)
calamity 2013/09/10 22:50:46 Done.
59 app_list::AppListModel::Users* users) {
60 const size_t count = profile_info.GetNumberOfProfiles();
61 for (size_t i = 0; i < count; ++i) {
62 app_list::AppListModel::User* user = new app_list::AppListModel::User();
koz (OOO until 15th September) 2013/09/09 22:58:07 nit: Use a scoped_ptr<> and then .release() it int
calamity 2013/09/10 22:50:46 No longer using pointers.
63 user->name = profile_info.GetNameOfProfileAtIndex(i);
64 user->email = profile_info.GetUserNameOfProfileAtIndex(i);
65 user->profile_path = profile_info.GetPathOfProfileAtIndex(i);
66 user->active = active_profile_path == user->profile_path;
67 users->push_back(user);
68 }
69 }
70
54 } // namespace 71 } // namespace
55 72
56 AppListViewDelegate::AppListViewDelegate(AppListControllerDelegate* controller, 73 AppListViewDelegate::AppListViewDelegate(AppListControllerDelegate* controller,
57 Profile* profile) 74 Profile* profile)
58 : controller_(controller), 75 : controller_(controller),
59 profile_(profile), 76 profile_(profile),
60 model_(NULL) { 77 model_(NULL) {
61 DCHECK(profile_); 78 RegisterForNotifications();
62 registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL,
63 content::Source<Profile>(profile_));
64 registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_SIGNIN_FAILED,
65 content::Source<Profile>(profile_));
66 registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_SIGNED_OUT,
67 content::Source<Profile>(profile_));
68 g_browser_process->profile_manager()->GetProfileInfoCache().AddObserver(this); 79 g_browser_process->profile_manager()->GetProfileInfoCache().AddObserver(this);
69 } 80 }
70 81
71 AppListViewDelegate::~AppListViewDelegate() { 82 AppListViewDelegate::~AppListViewDelegate() {
72 g_browser_process-> 83 g_browser_process->
73 profile_manager()->GetProfileInfoCache().RemoveObserver(this); 84 profile_manager()->GetProfileInfoCache().RemoveObserver(this);
74 } 85 }
75 86
76 void AppListViewDelegate::OnProfileChanged() { 87 void AppListViewDelegate::RegisterForNotifications() {
77 model_->SetSignedIn(!signin_delegate_->NeedSignin()); 88 registrar_.RemoveAll();
78 ProfileInfoCache& cache = 89 DCHECK(profile_);
79 g_browser_process->profile_manager()->GetProfileInfoCache();
80 // Populate the current user details.
81 size_t profile_index = cache.GetIndexOfProfileWithPath(profile_->GetPath());
82 // The profile won't exist in the cache if the current app list profile is
83 // being deleted.
84 if (profile_index == std::string::npos)
85 return;
86 90
87 model_->SetCurrentUser(cache.GetNameOfProfileAtIndex(profile_index), 91 registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL,
88 cache.GetUserNameOfProfileAtIndex(profile_index)); 92 content::Source<Profile>(profile_));
93 registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_SIGNIN_FAILED,
94 content::Source<Profile>(profile_));
95 registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_SIGNED_OUT,
96 content::Source<Profile>(profile_));
89 } 97 }
90 98
91 void AppListViewDelegate::SetModel(app_list::AppListModel* model) { 99 void AppListViewDelegate::OnProfileChanged() {
92 if (model) { 100 model_->SetSignedIn(!GetSigninDelegate()->NeedSignin());
93 model_ = model;
94 apps_builder_.reset(new AppsModelBuilder(profile_,
95 model->apps(),
96 controller_.get()));
97 apps_builder_->Build();
98 101
99 search_controller_.reset(new app_list::SearchController( 102 // Populate the app list users.
100 profile_, model->search_box(), model->results(), controller_.get())); 103 app_list::AppListModel::Users users;
104 PopulateUsers(g_browser_process->profile_manager()->GetProfileInfoCache(),
105 profile_->GetPath(), &users);
106 model_->SetUsers(users);
107 }
101 108
102 signin_delegate_.reset(new ChromeSigninDelegate(profile_)); 109 void AppListViewDelegate::SetProfileByPath(const base::FilePath& profile_path) {
110 DCHECK(model_);
111
112 // The profile must be loaded before this is called.
113 profile_ =
114 g_browser_process->profile_manager()->GetProfileByPath(profile_path);
115 DCHECK(profile_);
116
117 RegisterForNotifications();
118
119 apps_builder_->SetProfile(profile_);
120
121 search_controller_.reset(new app_list::SearchController(
122 profile_, model_->search_box(), model_->results(), controller_.get()));
123
124 signin_delegate_->SetProfile(profile_);
tapted 2013/09/10 00:29:26 Why couldn't this just be signin_delegate_.reset(n
calamity 2013/09/10 22:50:46 SigninView holds onto this delegate when its const
tapted 2013/09/11 05:50:26 Hm - so it does. Mac will fetch a new delegate in
calamity 2013/09/13 18:02:35 Done.
103 125
104 #if defined(USE_ASH) 126 #if defined(USE_ASH)
105 app_sync_ui_state_watcher_.reset(new AppSyncUIStateWatcher(profile_, 127 app_sync_ui_state_watcher_.reset(new AppSyncUIStateWatcher(profile_,
106 model)); 128 model_));
107 #endif 129 #endif
108 OnProfileChanged(); 130 OnProfileChanged();
109 } else { 131 if (!model_->search_box()->text().empty())
110 model_ = NULL; 132 StartSearch();
tapted 2013/09/10 00:29:26 This feels funny here.. it feels like something th
xiyuan 2013/09/10 01:54:33 It does look strange. I would prefer to clear quer
calamity 2013/09/10 22:50:46 Clearing the search box means that if a user start
xiyuan 2013/09/11 05:01:49 Sounds reasonable.
tapted 2013/09/11 05:50:26 I'm leaning slightly towards clearing results and
calamity 2013/09/13 18:02:35 Changed to clear search text on profile change for
111 apps_builder_.reset(); 133 }
112 search_controller_.reset(); 134
113 signin_delegate_.reset(); 135 void AppListViewDelegate::InitModel(app_list::AppListModel* model) {
136 DCHECK(!model_);
137 DCHECK(model);
138 model_ = model;
139
140 // Initialize apps model.
141 apps_builder_.reset(new AppsModelBuilder(profile_,
142 model->apps(),
143 controller_.get()));
144 apps_builder_->Build();
145
146 search_controller_.reset(new app_list::SearchController(
147 profile_, model->search_box(), model->results(), controller_.get()));
148
149 signin_delegate_.reset(new ChromeSigninDelegate(profile_));
150
114 #if defined(USE_ASH) 151 #if defined(USE_ASH)
115 app_sync_ui_state_watcher_.reset(); 152 app_sync_ui_state_watcher_.reset(new AppSyncUIStateWatcher(profile_,
koz (OOO until 15th September) 2013/09/09 22:58:07 What does this do?
xiyuan 2013/09/10 01:54:33 This is for ChromeOS to show pulsing animation whe
koz (OOO until 15th September) 2013/09/10 15:21:36 Cool, thanks for the explanation. Sounds like some
153 model));
116 #endif 154 #endif
117 } 155 // Initialize the profile information in the app list menu.
156 OnProfileChanged();
118 } 157 }
119 158
120 app_list::SigninDelegate* AppListViewDelegate::GetSigninDelegate() { 159 app_list::SigninDelegate* AppListViewDelegate::GetSigninDelegate() {
121 return signin_delegate_.get(); 160 return signin_delegate_.get();
122 } 161 }
123 162
124 void AppListViewDelegate::ActivateAppListItem( 163 void AppListViewDelegate::ActivateAppListItem(
125 app_list::AppListItemModel* item, 164 app_list::AppListItemModel* item,
126 int event_flags) { 165 int event_flags) {
127 content::RecordAction(content::UserMetricsAction("AppList_ClickOnApp")); 166 content::RecordAction(content::UserMetricsAction("AppList_ClickOnApp"));
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 252
214 void AppListViewDelegate::OpenFeedback() { 253 void AppListViewDelegate::OpenFeedback() {
215 chrome::HostDesktopType desktop = chrome::GetHostDesktopTypeForNativeWindow( 254 chrome::HostDesktopType desktop = chrome::GetHostDesktopTypeForNativeWindow(
216 controller_->GetAppListWindow()); 255 controller_->GetAppListWindow());
217 Browser* browser = chrome::FindOrCreateTabbedBrowser( 256 Browser* browser = chrome::FindOrCreateTabbedBrowser(
218 profile_, desktop); 257 profile_, desktop);
219 chrome::ShowFeedbackPage(browser, std::string(), 258 chrome::ShowFeedbackPage(browser, std::string(),
220 chrome::kAppLauncherCategoryTag); 259 chrome::kAppLauncherCategoryTag);
221 } 260 }
222 261
262 void AppListViewDelegate::ShowForProfileByPath(
263 const base::FilePath& profile_path) {
264 controller_->ShowForProfileByPath(profile_path);
265 }
266
223 void AppListViewDelegate::Observe( 267 void AppListViewDelegate::Observe(
224 int type, 268 int type,
225 const content::NotificationSource& source, 269 const content::NotificationSource& source,
226 const content::NotificationDetails& details) { 270 const content::NotificationDetails& details) {
227 OnProfileChanged(); 271 OnProfileChanged();
228 } 272 }
229 273
274 void AppListViewDelegate::OnProfileAdded(const base::FilePath& profile_path) {
275 OnProfileChanged();
276 }
277
230 void AppListViewDelegate::OnProfileNameChanged( 278 void AppListViewDelegate::OnProfileNameChanged(
231 const base::FilePath& profile_path, 279 const base::FilePath& profile_path,
232 const base::string16& old_profile_name) { 280 const base::string16& old_profile_name) {
233 if (profile_->GetPath() != profile_path)
234 return;
235
236 OnProfileChanged(); 281 OnProfileChanged();
237 } 282 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698