OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_model.h" | 5 #include "chrome/browser/profiles/avatar_menu_model.h" |
6 | 6 |
7 #include "base/stl_util.h" | 7 #include "base/stl_util.h" |
8 #include "base/string_number_conversions.h" | 8 #include "base/string_number_conversions.h" |
9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
10 #include "chrome/browser/profiles/avatar_menu_model_observer.h" | 10 #include "chrome/browser/profiles/avatar_menu_model_observer.h" |
11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/browser/profiles/profile_info_cache.h" | 12 #include "chrome/browser/profiles/profile_info_cache.h" |
| 13 #include "chrome/browser/profiles/profile_info_util.h" |
13 #include "chrome/browser/profiles/profile_manager.h" | 14 #include "chrome/browser/profiles/profile_manager.h" |
14 #include "chrome/browser/profiles/profile_metrics.h" | 15 #include "chrome/browser/profiles/profile_metrics.h" |
15 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" |
16 #include "chrome/browser/ui/browser_init.h" | 17 #include "chrome/browser/ui/browser_init.h" |
17 #include "chrome/browser/ui/browser_list.h" | 18 #include "chrome/browser/ui/browser_list.h" |
18 #include "chrome/browser/ui/browser_window.h" | 19 #include "chrome/browser/ui/browser_window.h" |
19 #include "chrome/common/chrome_notification_types.h" | 20 #include "chrome/common/chrome_notification_types.h" |
20 #include "chrome/common/url_constants.h" | 21 #include "chrome/common/url_constants.h" |
21 #include "content/public/browser/notification_service.h" | 22 #include "content/public/browser/notification_service.h" |
22 #include "grit/generated_resources.h" | 23 #include "grit/generated_resources.h" |
23 #include "ui/base/l10n/l10n_util.h" | 24 #include "ui/base/l10n/l10n_util.h" |
24 #include "ui/gfx/image/image.h" | |
25 | 25 |
26 using content::BrowserThread; | 26 using content::BrowserThread; |
27 | 27 |
28 namespace { | 28 namespace { |
29 | 29 |
30 class ProfileSwitchObserver : public ProfileManagerObserver { | 30 class ProfileSwitchObserver : public ProfileManagerObserver { |
31 public: | 31 public: |
32 virtual void OnProfileCreated(Profile* profile, Status status) OVERRIDE { | 32 virtual void OnProfileCreated(Profile* profile, Status status) OVERRIDE { |
33 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 33 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
34 | 34 |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 bool AvatarMenuModel::ShouldShowAvatarMenu() { | 144 bool AvatarMenuModel::ShouldShowAvatarMenu() { |
145 return ProfileManager::IsMultipleProfilesEnabled() && | 145 return ProfileManager::IsMultipleProfilesEnabled() && |
146 g_browser_process->profile_manager()->GetNumberOfProfiles() > 1; | 146 g_browser_process->profile_manager()->GetNumberOfProfiles() > 1; |
147 } | 147 } |
148 | 148 |
149 void AvatarMenuModel::RebuildMenu() { | 149 void AvatarMenuModel::RebuildMenu() { |
150 ClearMenu(); | 150 ClearMenu(); |
151 | 151 |
152 const size_t count = profile_info_->GetNumberOfProfiles(); | 152 const size_t count = profile_info_->GetNumberOfProfiles(); |
153 for (size_t i = 0; i < count; ++i) { | 153 for (size_t i = 0; i < count; ++i) { |
154 Item* item = new Item(i, profile_info_->GetAvatarIconOfProfileAtIndex(i)); | 154 bool is_gaia_picture = |
| 155 profile_info_->IsUsingGAIAPictureOfProfileAtIndex(i) && |
| 156 !profile_info_->GetGAIAPictureOfProfileAtIndex(i).IsNull(); |
| 157 gfx::Image icon = profiles::GetAvatarIconForMenu( |
| 158 profile_info_->GetAvatarIconOfProfileAtIndex(i), is_gaia_picture); |
| 159 |
| 160 Item* item = new Item(i, icon); |
155 item->name = profile_info_->GetNameOfProfileAtIndex(i); | 161 item->name = profile_info_->GetNameOfProfileAtIndex(i); |
156 item->sync_state = profile_info_->GetUserNameOfProfileAtIndex(i); | 162 item->sync_state = profile_info_->GetUserNameOfProfileAtIndex(i); |
157 if (item->sync_state.empty()) { | 163 if (item->sync_state.empty()) { |
158 item->sync_state = l10n_util::GetStringUTF16( | 164 item->sync_state = l10n_util::GetStringUTF16( |
159 IDS_PROFILES_LOCAL_PROFILE_STATE); | 165 IDS_PROFILES_LOCAL_PROFILE_STATE); |
160 } | 166 } |
161 if (browser_) { | 167 if (browser_) { |
162 FilePath path = profile_info_->GetPathOfProfileAtIndex(i); | 168 FilePath path = profile_info_->GetPathOfProfileAtIndex(i); |
163 item->active = browser_->profile()->GetPath() == path; | 169 item->active = browser_->profile()->GetPath() == path; |
164 } | 170 } |
165 items_.push_back(item); | 171 items_.push_back(item); |
166 } | 172 } |
167 } | 173 } |
168 | 174 |
169 void AvatarMenuModel::ClearMenu() { | 175 void AvatarMenuModel::ClearMenu() { |
170 STLDeleteContainerPointers(items_.begin(), items_.end()); | 176 STLDeleteContainerPointers(items_.begin(), items_.end()); |
171 items_.clear(); | 177 items_.clear(); |
172 } | 178 } |
OLD | NEW |