OLD | NEW |
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 Loading... |
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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 } | 242 } |
242 | 243 |
243 bool AvatarMenu::ShouldShowAddNewProfileLink() const { | 244 bool AvatarMenu::ShouldShowAddNewProfileLink() const { |
244 return menu_actions_->ShouldShowAddNewProfileLink(); | 245 return menu_actions_->ShouldShowAddNewProfileLink(); |
245 } | 246 } |
246 | 247 |
247 bool AvatarMenu::ShouldShowEditProfileLink() const { | 248 bool AvatarMenu::ShouldShowEditProfileLink() const { |
248 return menu_actions_->ShouldShowEditProfileLink(); | 249 return menu_actions_->ShouldShowEditProfileLink(); |
249 } | 250 } |
250 | 251 |
251 void AvatarMenu::Observe(int type, | 252 void AvatarMenu::OnProfileAdded(const base::FilePath& profile_path) { |
252 const content::NotificationSource& source, | 253 Update(); |
253 const content::NotificationDetails& details) { | 254 } |
254 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, type); | 255 |
255 RebuildMenu(); | 256 void AvatarMenu::OnProfileWasRemoved(const base::FilePath& profile_path, |
256 if (observer_) | 257 const base::string16& profile_name) { |
257 observer_->OnAvatarMenuChanged(this); | 258 Update(); |
| 259 } |
| 260 |
| 261 void AvatarMenu::OnProfileNameChanged(const base::FilePath& profile_path, |
| 262 const base::string16& old_profile_name) { |
| 263 Update(); |
| 264 } |
| 265 |
| 266 void AvatarMenu::OnProfileUserNameChanged(const base::FilePath& profile_path) { |
| 267 Update(); |
| 268 } |
| 269 |
| 270 void AvatarMenu::OnProfileAvatarChanged(const base::FilePath& profile_path) { |
| 271 Update(); |
| 272 } |
| 273 |
| 274 void AvatarMenu::OnProfileHighResAvatarLoaded( |
| 275 const base::FilePath& profile_path) { |
| 276 Update(); |
| 277 } |
| 278 |
| 279 void AvatarMenu::OnProfileSigninRequiredChanged( |
| 280 const base::FilePath& profile_path) { |
| 281 Update(); |
258 } | 282 } |
259 | 283 |
260 #if defined(ENABLE_SUPERVISED_USERS) | 284 #if defined(ENABLE_SUPERVISED_USERS) |
261 void AvatarMenu::OnCustodianInfoChanged() { | 285 void AvatarMenu::OnCustodianInfoChanged() { |
262 RebuildMenu(); | 286 RebuildMenu(); |
263 if (observer_) | 287 if (observer_) |
264 observer_->OnAvatarMenuChanged(this); | 288 observer_->OnAvatarMenuChanged(this); |
265 } | 289 } |
266 #endif | 290 #endif |
| 291 |
| 292 void AvatarMenu::Update() { |
| 293 RebuildMenu(); |
| 294 if (observer_) |
| 295 observer_->OnAvatarMenuChanged(this); |
| 296 } |
OLD | NEW |