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

Side by Side Diff: chrome/browser/profiles/avatar_menu.cc

Issue 895803003: [Profiles] Remove the NotificationService from the ProfileInfoCache (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 10 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
« no previous file with comments | « chrome/browser/profiles/avatar_menu.h ('k') | chrome/browser/profiles/profile_info_cache.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/profiles/avatar_menu.h" 5 #include "chrome/browser/profiles/avatar_menu.h"
6 6
7 #include "ash/ash_switches.h" 7 #include "ash/ash_switches.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/i18n/case_conversion.h" 9 #include "base/i18n/case_conversion.h"
10 #include "base/metrics/field_trial.h" 10 #include "base/metrics/field_trial.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 #endif 58 #endif
59 profile_info_(profile_cache), 59 profile_info_(profile_cache),
60 observer_(observer), 60 observer_(observer),
61 browser_(browser) { 61 browser_(browser) {
62 DCHECK(profile_info_); 62 DCHECK(profile_info_);
63 // Don't DCHECK(browser_) so that unit tests can reuse this ctor. 63 // Don't DCHECK(browser_) so that unit tests can reuse this ctor.
64 64
65 ActiveBrowserChanged(browser_); 65 ActiveBrowserChanged(browser_);
66 66
67 // Register this as an observer of the info cache. 67 // Register this as an observer of the info cache.
68 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, 68 g_browser_process->profile_manager()->GetProfileInfoCache().AddObserver(this);
69 content::NotificationService::AllSources());
70 69
71 #if defined(ENABLE_SUPERVISED_USERS) 70 #if defined(ENABLE_SUPERVISED_USERS)
72 // Register this as an observer of the SupervisedUserService to be notified 71 // Register this as an observer of the SupervisedUserService to be notified
73 // of changes to the custodian info. 72 // of changes to the custodian info.
74 if (browser_) { 73 if (browser_) {
75 supervised_user_observer_.Add( 74 supervised_user_observer_.Add(
76 SupervisedUserServiceFactory::GetForProfile(browser_->profile())); 75 SupervisedUserServiceFactory::GetForProfile(browser_->profile()));
77 } 76 }
78 #endif 77 #endif
79 } 78 }
80 79
81 AvatarMenu::~AvatarMenu() { 80 AvatarMenu::~AvatarMenu() {
81 g_browser_process->profile_manager()->
82 GetProfileInfoCache().RemoveObserver(this);
82 } 83 }
83 84
84 AvatarMenu::Item::Item(size_t menu_index, 85 AvatarMenu::Item::Item(size_t menu_index,
85 size_t profile_index, 86 size_t profile_index,
86 const gfx::Image& icon) 87 const gfx::Image& icon)
87 : icon(icon), 88 : icon(icon),
88 active(false), 89 active(false),
89 signed_in(false), 90 signed_in(false),
90 signin_required(false), 91 signin_required(false),
91 menu_index(menu_index), 92 menu_index(menu_index),
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 } 246 }
246 247
247 bool AvatarMenu::ShouldShowAddNewProfileLink() const { 248 bool AvatarMenu::ShouldShowAddNewProfileLink() const {
248 return menu_actions_->ShouldShowAddNewProfileLink(); 249 return menu_actions_->ShouldShowAddNewProfileLink();
249 } 250 }
250 251
251 bool AvatarMenu::ShouldShowEditProfileLink() const { 252 bool AvatarMenu::ShouldShowEditProfileLink() const {
252 return menu_actions_->ShouldShowEditProfileLink(); 253 return menu_actions_->ShouldShowEditProfileLink();
253 } 254 }
254 255
255 void AvatarMenu::Observe(int type, 256 void AvatarMenu::OnProfileAdded(const base::FilePath& profile_path) {
256 const content::NotificationSource& source, 257 Update();
257 const content::NotificationDetails& details) { 258 }
258 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, type); 259
259 RebuildMenu(); 260 void AvatarMenu::OnProfileWasRemoved(const base::FilePath& profile_path,
260 if (observer_) 261 const base::string16& profile_name) {
261 observer_->OnAvatarMenuChanged(this); 262 Update();
263 }
264
265 void AvatarMenu::OnProfileNameChanged(const base::FilePath& profile_path,
266 const base::string16& old_profile_name) {
267 Update();
268 }
269
270 void AvatarMenu::OnProfileUserNameChanged(const base::FilePath& profile_path) {
271 Update();
272 }
273
274 void AvatarMenu::OnProfileAvatarChanged(const base::FilePath& profile_path) {
275 Update();
276 }
277
278 void AvatarMenu::OnProfileHighResAvatarLoaded(
279 const base::FilePath& profile_path) {
280 Update();
281 }
282
283 void AvatarMenu::OnProfileSigninRequiredChanged(
284 const base::FilePath& profile_path) {
285 Update();
262 } 286 }
263 287
264 #if defined(ENABLE_SUPERVISED_USERS) 288 #if defined(ENABLE_SUPERVISED_USERS)
265 void AvatarMenu::OnCustodianInfoChanged() { 289 void AvatarMenu::OnCustodianInfoChanged() {
266 RebuildMenu(); 290 RebuildMenu();
267 if (observer_) 291 if (observer_)
268 observer_->OnAvatarMenuChanged(this); 292 observer_->OnAvatarMenuChanged(this);
269 } 293 }
270 #endif 294 #endif
295
296 void AvatarMenu::Update() {
297 RebuildMenu();
298 if (observer_)
299 observer_->OnAvatarMenuChanged(this);
300 }
OLDNEW
« no previous file with comments | « chrome/browser/profiles/avatar_menu.h ('k') | chrome/browser/profiles/profile_info_cache.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698