| 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" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 #include "ui/base/l10n/l10n_util.h" | 33 #include "ui/base/l10n/l10n_util.h" |
| 34 #include "ui/base/resource/resource_bundle.h" | 34 #include "ui/base/resource/resource_bundle.h" |
| 35 | 35 |
| 36 #if defined(ENABLE_SUPERVISED_USERS) | 36 #if defined(ENABLE_SUPERVISED_USERS) |
| 37 #include "chrome/browser/supervised_user/supervised_user_service.h" | 37 #include "chrome/browser/supervised_user/supervised_user_service.h" |
| 38 #include "chrome/browser/supervised_user/supervised_user_service_factory.h" | 38 #include "chrome/browser/supervised_user/supervised_user_service_factory.h" |
| 39 #endif | 39 #endif |
| 40 | 40 |
| 41 using content::BrowserThread; | 41 using content::BrowserThread; |
| 42 | 42 |
| 43 AvatarMenu::AvatarMenu(ProfileInfoInterface* profile_cache, | 43 AvatarMenu::AvatarMenu(ProfileAttributesStorage* profile_storage, |
| 44 AvatarMenuObserver* observer, | 44 AvatarMenuObserver* observer, |
| 45 Browser* browser) | 45 Browser* browser) |
| 46 : profile_list_(ProfileList::Create(profile_cache)), | 46 : profile_list_(ProfileList::Create( |
| 47 &g_browser_process->profile_manager()->GetProfileInfoCache())), |
| 47 menu_actions_(AvatarMenuActions::Create()), | 48 menu_actions_(AvatarMenuActions::Create()), |
| 48 #if defined(ENABLE_SUPERVISED_USERS) | 49 #if defined(ENABLE_SUPERVISED_USERS) |
| 49 supervised_user_observer_(this), | 50 supervised_user_observer_(this), |
| 50 #endif | 51 #endif |
| 51 profile_info_(profile_cache), | 52 profile_info_( |
| 53 &g_browser_process->profile_manager()->GetProfileInfoCache()), |
| 52 observer_(observer), | 54 observer_(observer), |
| 53 browser_(browser) { | 55 browser_(browser) { |
| 54 DCHECK(profile_info_); | 56 DCHECK(profile_info_); |
| 55 // Don't DCHECK(browser_) so that unit tests can reuse this ctor. | 57 // Don't DCHECK(browser_) so that unit tests can reuse this ctor. |
| 56 | 58 |
| 57 ActiveBrowserChanged(browser_); | 59 ActiveBrowserChanged(browser_); |
| 58 | 60 |
| 59 // Register this as an observer of the info cache. | 61 // Register this as an observer of the info cache. |
| 60 g_browser_process->profile_manager()->GetProfileInfoCache().AddObserver(this); | 62 g_browser_process->profile_manager()->GetProfileInfoCache().AddObserver(this); |
| 61 | 63 |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 profile_list_->RebuildMenu(); | 151 profile_list_->RebuildMenu(); |
| 150 } | 152 } |
| 151 | 153 |
| 152 size_t AvatarMenu::GetNumberOfItems() const { | 154 size_t AvatarMenu::GetNumberOfItems() const { |
| 153 return profile_list_->GetNumberOfItems(); | 155 return profile_list_->GetNumberOfItems(); |
| 154 } | 156 } |
| 155 | 157 |
| 156 const AvatarMenu::Item& AvatarMenu::GetItemAt(size_t index) const { | 158 const AvatarMenu::Item& AvatarMenu::GetItemAt(size_t index) const { |
| 157 return profile_list_->GetItemAt(index); | 159 return profile_list_->GetItemAt(index); |
| 158 } | 160 } |
| 161 |
| 159 size_t AvatarMenu::GetActiveProfileIndex() { | 162 size_t AvatarMenu::GetActiveProfileIndex() { |
| 160 | |
| 161 // During singleton profile deletion, this function can be called with no | 163 // During singleton profile deletion, this function can be called with no |
| 162 // profiles in the model - crbug.com/102278 . | 164 // profiles in the model - crbug.com/102278 . |
| 163 if (profile_list_->GetNumberOfItems() == 0) | 165 if (profile_list_->GetNumberOfItems() == 0) |
| 164 return 0; | 166 return 0; |
| 165 | 167 |
| 166 Profile* active_profile = NULL; | 168 Profile* active_profile = NULL; |
| 167 if (!browser_) | 169 if (!browser_) |
| 168 active_profile = ProfileManager::GetLastUsedProfile(); | 170 active_profile = ProfileManager::GetLastUsedProfile(); |
| 169 else | 171 else |
| 170 active_profile = browser_->profile(); | 172 active_profile = browser_->profile(); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 if (observer_) | 270 if (observer_) |
| 269 observer_->OnAvatarMenuChanged(this); | 271 observer_->OnAvatarMenuChanged(this); |
| 270 } | 272 } |
| 271 #endif | 273 #endif |
| 272 | 274 |
| 273 void AvatarMenu::Update() { | 275 void AvatarMenu::Update() { |
| 274 RebuildMenu(); | 276 RebuildMenu(); |
| 275 if (observer_) | 277 if (observer_) |
| 276 observer_->OnAvatarMenuChanged(this); | 278 observer_->OnAvatarMenuChanged(this); |
| 277 } | 279 } |
| OLD | NEW |