Chromium Code Reviews| 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 57 observer_(observer), | 57 observer_(observer), |
| 58 browser_(browser) { | 58 browser_(browser) { |
| 59 DCHECK(profile_info_); | 59 DCHECK(profile_info_); |
| 60 // Don't DCHECK(browser_) so that unit tests can reuse this ctor. | 60 // Don't DCHECK(browser_) so that unit tests can reuse this ctor. |
| 61 | 61 |
| 62 ActiveBrowserChanged(browser_); | 62 ActiveBrowserChanged(browser_); |
| 63 | 63 |
| 64 // Register this as an observer of the info cache. | 64 // Register this as an observer of the info cache. |
| 65 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, | 65 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, |
| 66 content::NotificationService::AllSources()); | 66 content::NotificationService::AllSources()); |
| 67 | |
| 68 #if defined(ENABLE_MANAGED_USERS) | |
| 69 // Register this as an observer of the SupervisedUserService to be notified | |
| 70 // of changes to the custodian info. | |
| 71 if (browser_) { | |
| 72 SupervisedUserService* service = | |
| 73 SupervisedUserServiceFactory::GetForProfile(browser_->profile()); | |
|
noms (inactive)
2014/09/25 14:22:22
Is it possible to be in a state where browser_->pr
Marc Treib
2014/09/25 14:50:56
browser_->profile() can be the guest profile, but
Bernhard Bauer
2014/09/25 15:15:48
Yeah, I don't think we set it to NULL for testing
| |
| 74 service->AddObserver(this); | |
| 75 } | |
| 76 #endif | |
| 67 } | 77 } |
| 68 | 78 |
| 69 AvatarMenu::~AvatarMenu() { | 79 AvatarMenu::~AvatarMenu() { |
| 80 #if defined(ENABLE_MANAGED_USERS) | |
| 81 if (browser_) { | |
| 82 SupervisedUserService* service = | |
| 83 SupervisedUserServiceFactory::GetForProfile(browser_->profile()); | |
| 84 service->RemoveObserver(this); | |
|
Bernhard Bauer
2014/09/25 15:15:48
A ScopedObserver might be useful here, to do this
Marc Treib
2014/09/25 15:30:28
Done.
| |
| 85 } | |
| 86 #endif | |
| 70 } | 87 } |
| 71 | 88 |
| 72 AvatarMenu::Item::Item(size_t menu_index, | 89 AvatarMenu::Item::Item(size_t menu_index, |
| 73 size_t profile_index, | 90 size_t profile_index, |
| 74 const gfx::Image& icon) | 91 const gfx::Image& icon) |
| 75 : icon(icon), | 92 : icon(icon), |
| 76 active(false), | 93 active(false), |
| 77 signed_in(false), | 94 signed_in(false), |
| 78 signin_required(false), | 95 signin_required(false), |
| 79 menu_index(menu_index), | 96 menu_index(menu_index), |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 227 } | 244 } |
| 228 | 245 |
| 229 void AvatarMenu::Observe(int type, | 246 void AvatarMenu::Observe(int type, |
| 230 const content::NotificationSource& source, | 247 const content::NotificationSource& source, |
| 231 const content::NotificationDetails& details) { | 248 const content::NotificationDetails& details) { |
| 232 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, type); | 249 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, type); |
| 233 RebuildMenu(); | 250 RebuildMenu(); |
| 234 if (observer_) | 251 if (observer_) |
| 235 observer_->OnAvatarMenuChanged(this); | 252 observer_->OnAvatarMenuChanged(this); |
| 236 } | 253 } |
| 254 | |
| 255 #if defined(ENABLE_MANAGED_USERS) | |
| 256 void AvatarMenu::OnCustodianInfoChanged() { | |
| 257 RebuildMenu(); | |
| 258 if (observer_) | |
| 259 observer_->OnAvatarMenuChanged(this); | |
| 260 } | |
| 261 #endif | |
| OLD | NEW |