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

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

Issue 22268009: Move signin status and current user information into AppListModel. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 "chrome/browser/browser_process.h" 9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/chrome_notification_types.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"
12 #include "chrome/browser/profiles/profile_manager.h" 13 #include "chrome/browser/profiles/profile_manager.h"
13 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h" 14 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h"
14 #include "chrome/browser/ui/app_list/apps_model_builder.h" 15 #include "chrome/browser/ui/app_list/apps_model_builder.h"
15 #include "chrome/browser/ui/app_list/chrome_app_list_item.h" 16 #include "chrome/browser/ui/app_list/chrome_app_list_item.h"
16 #include "chrome/browser/ui/app_list/chrome_signin_delegate.h" 17 #include "chrome/browser/ui/app_list/chrome_signin_delegate.h"
17 #include "chrome/browser/ui/app_list/search/search_controller.h" 18 #include "chrome/browser/ui/app_list/search/search_controller.h"
18 #include "chrome/browser/ui/browser_finder.h" 19 #include "chrome/browser/ui/browser_finder.h"
19 #include "chrome/browser/ui/chrome_pages.h" 20 #include "chrome/browser/ui/chrome_pages.h"
20 #include "chrome/browser/ui/host_desktop.h" 21 #include "chrome/browser/ui/host_desktop.h"
21 #include "chrome/browser/ui/web_applications/web_app_ui.h" 22 #include "chrome/browser/ui/web_applications/web_app_ui.h"
22 #include "chrome/browser/web_applications/web_app.h" 23 #include "chrome/browser/web_applications/web_app.h"
23 #include "chrome/common/extensions/extension_constants.h" 24 #include "chrome/common/extensions/extension_constants.h"
24 #include "chrome/common/url_constants.h" 25 #include "chrome/common/url_constants.h"
25 #include "content/public/browser/browser_thread.h" 26 #include "content/public/browser/browser_thread.h"
27 #include "content/public/browser/notification_details.h"
28 #include "content/public/browser/notification_service.h"
29 #include "content/public/browser/notification_source.h"
26 #include "content/public/browser/page_navigator.h" 30 #include "content/public/browser/page_navigator.h"
27 #include "content/public/browser/user_metrics.h" 31 #include "content/public/browser/user_metrics.h"
28 32
29 #if defined(USE_ASH) 33 #if defined(USE_ASH)
30 #include "chrome/browser/ui/ash/app_list/app_sync_ui_state_watcher.h" 34 #include "chrome/browser/ui/ash/app_list/app_sync_ui_state_watcher.h"
31 #endif 35 #endif
32 36
33 #if defined(OS_WIN) 37 #if defined(OS_WIN)
34 #include "chrome/browser/web_applications/web_app_win.h" 38 #include "chrome/browser/web_applications/web_app_win.h"
35 #endif 39 #endif
(...skipping 11 matching lines...) Expand all
47 base::Bind(web_app::CreateShortcutInWebAppDir, app_data_dir, info), 51 base::Bind(web_app::CreateShortcutInWebAppDir, app_data_dir, info),
48 callback); 52 callback);
49 } 53 }
50 #endif 54 #endif
51 55
52 } // namespace 56 } // namespace
53 57
54 AppListViewDelegate::AppListViewDelegate(AppListControllerDelegate* controller, 58 AppListViewDelegate::AppListViewDelegate(AppListControllerDelegate* controller,
55 Profile* profile) 59 Profile* profile)
56 : controller_(controller), 60 : controller_(controller),
57 profile_(profile) {} 61 profile_(profile),
62 model_(NULL) {
63 RegisterForNotifications();
64 }
58 65
59 AppListViewDelegate::~AppListViewDelegate() {} 66 AppListViewDelegate::~AppListViewDelegate() {
67 signin_delegate_->RemoveObserver(this);
tapted 2013/08/06 09:27:50 SetModel has a check: `if (signin_delegate_.get())
calamity 2013/08/08 01:34:58 Done.
68 }
69
70 void AppListViewDelegate::RegisterForNotifications() {
71 DCHECK(profile_);
72 registrar_.RemoveAll();
tapted 2013/08/06 09:27:50 It looks like this (private function) is only call
calamity 2013/08/08 01:34:58 Done.
73 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED,
74 content::NotificationService::AllSources());
75 registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL,
76 content::Source<Profile>(profile_));
77 registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_SIGNIN_FAILED,
78 content::Source<Profile>(profile_));
79 registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_SIGNED_OUT,
80 content::Source<Profile>(profile_));
81 }
60 82
61 void AppListViewDelegate::SetModel(app_list::AppListModel* model) { 83 void AppListViewDelegate::SetModel(app_list::AppListModel* model) {
84 if (signin_delegate_.get())
85 signin_delegate_->RemoveObserver(this);
62 if (model) { 86 if (model) {
87 model_ = model;
63 apps_builder_.reset(new AppsModelBuilder(profile_, 88 apps_builder_.reset(new AppsModelBuilder(profile_,
64 model->apps(), 89 model->apps(),
65 controller_.get())); 90 controller_.get()));
66 apps_builder_->Build(); 91 apps_builder_->Build();
67 92
68 search_controller_.reset(new app_list::SearchController( 93 search_controller_.reset(new app_list::SearchController(
69 profile_, model->search_box(), model->results(), controller_.get())); 94 profile_, model->search_box(), model->results(), controller_.get()));
70 95
71 signin_delegate_.reset(new ChromeSigninDelegate(profile_)); 96 signin_delegate_.reset(new ChromeSigninDelegate(profile_));
97 signin_delegate_->AddObserver(this);
72 98
73 #if defined(USE_ASH) 99 #if defined(USE_ASH)
74 app_sync_ui_state_watcher_.reset(new AppSyncUIStateWatcher(profile_, 100 app_sync_ui_state_watcher_.reset(new AppSyncUIStateWatcher(profile_,
75 model)); 101 model));
76 #endif 102 #endif
103 UpdateModelWithCurrentProfiles();
77 } else { 104 } else {
105 model_ = NULL;
78 apps_builder_.reset(); 106 apps_builder_.reset();
79 search_controller_.reset(); 107 search_controller_.reset();
80 #if defined(USE_ASH) 108 #if defined(USE_ASH)
81 app_sync_ui_state_watcher_.reset(); 109 app_sync_ui_state_watcher_.reset();
82 #endif 110 #endif
83 } 111 }
84 } 112 }
85 113
86 app_list::SigninDelegate* AppListViewDelegate::GetSigninDelegate() { 114 app_list::SigninDelegate* AppListViewDelegate::GetSigninDelegate() {
87 return signin_delegate_.get(); 115 return signin_delegate_.get();
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 } 181 }
154 182
155 void AppListViewDelegate::ViewActivationChanged(bool active) { 183 void AppListViewDelegate::ViewActivationChanged(bool active) {
156 controller_->ViewActivationChanged(active); 184 controller_->ViewActivationChanged(active);
157 } 185 }
158 186
159 gfx::ImageSkia AppListViewDelegate::GetWindowIcon() { 187 gfx::ImageSkia AppListViewDelegate::GetWindowIcon() {
160 return controller_->GetWindowIcon(); 188 return controller_->GetWindowIcon();
161 } 189 }
162 190
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() { 191 void AppListViewDelegate::OpenSettings() {
184 ExtensionService* service = profile_->GetExtensionService(); 192 ExtensionService* service = profile_->GetExtensionService();
185 DCHECK(service); 193 DCHECK(service);
186 const extensions::Extension* extension = service->GetInstalledExtension( 194 const extensions::Extension* extension = service->GetInstalledExtension(
187 extension_misc::kSettingsAppId); 195 extension_misc::kSettingsAppId);
188 DCHECK(extension); 196 DCHECK(extension);
189 controller_->ActivateApp(profile_, extension, 0); 197 controller_->ActivateApp(profile_, extension, 0);
190 } 198 }
191 199
192 void AppListViewDelegate::OpenHelp() { 200 void AppListViewDelegate::OpenHelp() {
193 chrome::HostDesktopType desktop = chrome::GetHostDesktopTypeForNativeWindow( 201 chrome::HostDesktopType desktop = chrome::GetHostDesktopTypeForNativeWindow(
194 controller_->GetAppListWindow()); 202 controller_->GetAppListWindow());
195 Browser* browser = chrome::FindOrCreateTabbedBrowser( 203 Browser* browser = chrome::FindOrCreateTabbedBrowser(
196 profile_, desktop); 204 profile_, desktop);
197 browser->OpenURL(content::OpenURLParams(GURL(chrome::kAppLauncherHelpURL), 205 browser->OpenURL(content::OpenURLParams(GURL(chrome::kAppLauncherHelpURL),
198 content::Referrer(), 206 content::Referrer(),
199 NEW_FOREGROUND_TAB, 207 NEW_FOREGROUND_TAB,
200 content::PAGE_TRANSITION_LINK, 208 content::PAGE_TRANSITION_LINK,
201 false)); 209 false));
202 } 210 }
203 211
204 void AppListViewDelegate::OpenFeedback() { 212 void AppListViewDelegate::OpenFeedback() {
205 chrome::HostDesktopType desktop = chrome::GetHostDesktopTypeForNativeWindow( 213 chrome::HostDesktopType desktop = chrome::GetHostDesktopTypeForNativeWindow(
206 controller_->GetAppListWindow()); 214 controller_->GetAppListWindow());
207 Browser* browser = chrome::FindOrCreateTabbedBrowser( 215 Browser* browser = chrome::FindOrCreateTabbedBrowser(
208 profile_, desktop); 216 profile_, desktop);
209 chrome::ShowFeedbackPage(browser, std::string(), 217 chrome::ShowFeedbackPage(browser, std::string(),
210 chrome::kAppLauncherCategoryTag); 218 chrome::kAppLauncherCategoryTag);
211 } 219 }
220
221 void AppListViewDelegate::UpdateModelWithCurrentProfiles() {
koz (OOO until 15th September) 2013/08/06 08:14:42 I think this would be better named OnProfileChange
tapted 2013/08/06 09:27:50 nit: it's usually best to follow declaration order
calamity 2013/08/08 01:34:58 Done.
calamity 2013/08/08 01:34:58 Done.
222 model_->SetSignedIn(!signin_delegate_->NeedSignin());
223 ProfileInfoCache& cache =
224 g_browser_process->profile_manager()->GetProfileInfoCache();
225 // Populate the current user details.
226 size_t profile_index = cache.GetIndexOfProfileWithPath(profile_->GetPath());
227 // The profile won't exist in the cache if the current app list profile is
228 // being deleted.
229 if (profile_index == std::string::npos)
230 return;
tapted 2013/08/06 09:27:50 nit: blank line after early return
calamity 2013/08/08 01:34:58 Done.
231 model_->SetCurrentUser(cache.GetNameOfProfileAtIndex(profile_index),
232 cache.GetUserNameOfProfileAtIndex(profile_index));
233 }
234
235 void AppListViewDelegate::OnSigninSuccess() {
236 UpdateModelWithCurrentProfiles();
237 }
238
239 void AppListViewDelegate::Observe(
240 int type,
241 const content::NotificationSource& source,
242 const content::NotificationDetails& details) {
243 UpdateModelWithCurrentProfiles();
244 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698