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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/i18n/case_conversion.h" | 8 #include "base/i18n/case_conversion.h" |
9 #include "base/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
10 #include "base/profiler/scoped_tracker.h" | 10 #include "base/profiler/scoped_tracker.h" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
14 #include "chrome/browser/chrome_notification_types.h" | 14 #include "chrome/browser/chrome_notification_types.h" |
15 #include "chrome/browser/profiles/avatar_menu_actions.h" | 15 #include "chrome/browser/profiles/avatar_menu_actions.h" |
16 #include "chrome/browser/profiles/avatar_menu_observer.h" | 16 #include "chrome/browser/profiles/avatar_menu_observer.h" |
17 #include "chrome/browser/profiles/profile_list.h" | 17 #include "chrome/browser/profiles/profile_list.h" |
18 #include "chrome/browser/profiles/profile_manager.h" | 18 #include "chrome/browser/profiles/profile_manager.h" |
19 #include "chrome/browser/profiles/profile_metrics.h" | 19 #include "chrome/browser/profiles/profile_metrics.h" |
20 #include "chrome/browser/profiles/profile_window.h" | 20 #include "chrome/browser/profiles/profile_window.h" |
21 #include "chrome/browser/profiles/profiles_state.h" | 21 #include "chrome/browser/profiles/profiles_state.h" |
22 #include "chrome/browser/ui/browser.h" | 22 #include "chrome/browser/ui/browser.h" |
23 #include "chrome/browser/ui/browser_dialogs.h" | 23 #include "chrome/browser/ui/browser_dialogs.h" |
24 #include "chrome/browser/ui/startup/startup_browser_creator.h" | 24 #include "chrome/browser/ui/startup/startup_browser_creator.h" |
25 #include "chrome/browser/ui/user_manager.h" | 25 #include "chrome/browser/ui/user_manager.h" |
26 #include "chrome/common/chrome_switches.h" | 26 #include "chrome/common/chrome_switches.h" |
| 27 #include "chrome/common/features.h" |
27 #include "chrome/grit/generated_resources.h" | 28 #include "chrome/grit/generated_resources.h" |
28 #include "chrome/grit/theme_resources.h" | 29 #include "chrome/grit/theme_resources.h" |
29 #include "components/signin/core/common/profile_management_switches.h" | 30 #include "components/signin/core/common/profile_management_switches.h" |
30 #include "content/public/browser/browser_thread.h" | 31 #include "content/public/browser/browser_thread.h" |
31 #include "content/public/browser/notification_service.h" | 32 #include "content/public/browser/notification_service.h" |
32 #include "ui/base/l10n/l10n_util.h" | 33 #include "ui/base/l10n/l10n_util.h" |
33 #include "ui/base/resource/resource_bundle.h" | 34 #include "ui/base/resource/resource_bundle.h" |
34 | 35 |
35 #if defined(ENABLE_SUPERVISED_USERS) | 36 #if BUILDFLAG(ENABLE_SUPERVISED_USERS) |
36 #include "chrome/browser/supervised_user/supervised_user_service.h" | 37 #include "chrome/browser/supervised_user/supervised_user_service.h" |
37 #include "chrome/browser/supervised_user/supervised_user_service_factory.h" | 38 #include "chrome/browser/supervised_user/supervised_user_service_factory.h" |
38 #endif | 39 #endif |
39 | 40 |
40 using content::BrowserThread; | 41 using content::BrowserThread; |
41 | 42 |
42 AvatarMenu::AvatarMenu(ProfileAttributesStorage* profile_storage, | 43 AvatarMenu::AvatarMenu(ProfileAttributesStorage* profile_storage, |
43 AvatarMenuObserver* observer, | 44 AvatarMenuObserver* observer, |
44 Browser* browser) | 45 Browser* browser) |
45 : profile_list_(ProfileList::Create(profile_storage)), | 46 : profile_list_(ProfileList::Create(profile_storage)), |
46 menu_actions_(AvatarMenuActions::Create()), | 47 menu_actions_(AvatarMenuActions::Create()), |
47 #if defined(ENABLE_SUPERVISED_USERS) | 48 #if BUILDFLAG(ENABLE_SUPERVISED_USERS) |
48 supervised_user_observer_(this), | 49 supervised_user_observer_(this), |
49 #endif | 50 #endif |
50 profile_storage_(profile_storage), | 51 profile_storage_(profile_storage), |
51 observer_(observer), | 52 observer_(observer), |
52 browser_(browser) { | 53 browser_(browser) { |
53 DCHECK(profile_storage_); | 54 DCHECK(profile_storage_); |
54 // Don't DCHECK(browser_) so that unit tests can reuse this ctor. | 55 // Don't DCHECK(browser_) so that unit tests can reuse this ctor. |
55 | 56 |
56 ActiveBrowserChanged(browser_); | 57 ActiveBrowserChanged(browser_); |
57 | 58 |
58 // Register this as an observer of the info cache. | 59 // Register this as an observer of the info cache. |
59 profile_storage_->AddObserver(this); | 60 profile_storage_->AddObserver(this); |
60 | 61 |
61 #if defined(ENABLE_SUPERVISED_USERS) | 62 #if BUILDFLAG(ENABLE_SUPERVISED_USERS) |
62 // Register this as an observer of the SupervisedUserService to be notified | 63 // Register this as an observer of the SupervisedUserService to be notified |
63 // of changes to the custodian info. | 64 // of changes to the custodian info. |
64 if (browser_) { | 65 if (browser_) { |
65 supervised_user_observer_.Add( | 66 supervised_user_observer_.Add( |
66 SupervisedUserServiceFactory::GetForProfile(browser_->profile())); | 67 SupervisedUserServiceFactory::GetForProfile(browser_->profile())); |
67 } | 68 } |
68 #endif | 69 #endif |
69 } | 70 } |
70 | 71 |
71 AvatarMenu::~AvatarMenu() { | 72 AvatarMenu::~AvatarMenu() { |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 | 161 |
161 size_t index = | 162 size_t index = |
162 profile_list_->MenuIndexFromProfilePath(active_profile->GetPath()); | 163 profile_list_->MenuIndexFromProfilePath(active_profile->GetPath()); |
163 DCHECK_LT(index, profile_list_->GetNumberOfItems()); | 164 DCHECK_LT(index, profile_list_->GetNumberOfItems()); |
164 return index; | 165 return index; |
165 } | 166 } |
166 | 167 |
167 base::string16 AvatarMenu::GetSupervisedUserInformation() const { | 168 base::string16 AvatarMenu::GetSupervisedUserInformation() const { |
168 // |browser_| can be NULL in unit_tests. | 169 // |browser_| can be NULL in unit_tests. |
169 if (browser_ && browser_->profile()->IsSupervised()) { | 170 if (browser_ && browser_->profile()->IsSupervised()) { |
170 #if defined(ENABLE_SUPERVISED_USERS) | 171 #if BUILDFLAG(ENABLE_SUPERVISED_USERS) |
171 SupervisedUserService* service = | 172 SupervisedUserService* service = |
172 SupervisedUserServiceFactory::GetForProfile(browser_->profile()); | 173 SupervisedUserServiceFactory::GetForProfile(browser_->profile()); |
173 base::string16 custodian = | 174 base::string16 custodian = |
174 base::UTF8ToUTF16(service->GetCustodianEmailAddress()); | 175 base::UTF8ToUTF16(service->GetCustodianEmailAddress()); |
175 if (browser_->profile()->IsLegacySupervised()) | 176 if (browser_->profile()->IsLegacySupervised()) |
176 return l10n_util::GetStringFUTF16(IDS_LEGACY_SUPERVISED_USER_INFO, | 177 return l10n_util::GetStringFUTF16(IDS_LEGACY_SUPERVISED_USER_INFO, |
177 custodian); | 178 custodian); |
178 base::string16 second_custodian = | 179 base::string16 second_custodian = |
179 base::UTF8ToUTF16(service->GetSecondCustodianEmailAddress()); | 180 base::UTF8ToUTF16(service->GetSecondCustodianEmailAddress()); |
180 if (second_custodian.empty()) { | 181 if (second_custodian.empty()) { |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 | 244 |
244 void AvatarMenu::OnProfileSigninRequiredChanged( | 245 void AvatarMenu::OnProfileSigninRequiredChanged( |
245 const base::FilePath& profile_path) { | 246 const base::FilePath& profile_path) { |
246 Update(); | 247 Update(); |
247 } | 248 } |
248 | 249 |
249 void AvatarMenu::OnProfileIsOmittedChanged(const base::FilePath& profile_path) { | 250 void AvatarMenu::OnProfileIsOmittedChanged(const base::FilePath& profile_path) { |
250 Update(); | 251 Update(); |
251 } | 252 } |
252 | 253 |
253 #if defined(ENABLE_SUPERVISED_USERS) | 254 #if BUILDFLAG(ENABLE_SUPERVISED_USERS) |
254 void AvatarMenu::OnCustodianInfoChanged() { | 255 void AvatarMenu::OnCustodianInfoChanged() { |
255 Update(); | 256 Update(); |
256 } | 257 } |
257 #endif | 258 #endif |
258 | 259 |
259 void AvatarMenu::Update() { | 260 void AvatarMenu::Update() { |
260 RebuildMenu(); | 261 RebuildMenu(); |
261 if (observer_) | 262 if (observer_) |
262 observer_->OnAvatarMenuChanged(this); | 263 observer_->OnAvatarMenuChanged(this); |
263 } | 264 } |
OLD | NEW |