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_model.h" | 5 #include "chrome/browser/profiles/avatar_menu_model.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/metrics/field_trial.h" |
8 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
9 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
10 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
11 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
12 #include "chrome/browser/profiles/avatar_menu_model_observer.h" | 13 #include "chrome/browser/profiles/avatar_menu_model_observer.h" |
13 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/browser/profiles/profile_info_cache.h" | 15 #include "chrome/browser/profiles/profile_info_cache.h" |
15 #include "chrome/browser/profiles/profile_info_util.h" | 16 #include "chrome/browser/profiles/profile_info_util.h" |
16 #include "chrome/browser/profiles/profile_manager.h" | 17 #include "chrome/browser/profiles/profile_manager.h" |
17 #include "chrome/browser/profiles/profile_metrics.h" | 18 #include "chrome/browser/profiles/profile_metrics.h" |
(...skipping 23 matching lines...) Expand all Loading... |
41 if (status == Profile::CREATE_STATUS_INITIALIZED) { | 42 if (status == Profile::CREATE_STATUS_INITIALIZED) { |
42 ProfileManager::FindOrCreateNewWindowForProfile( | 43 ProfileManager::FindOrCreateNewWindowForProfile( |
43 profile, | 44 profile, |
44 chrome::startup::IS_NOT_PROCESS_STARTUP, | 45 chrome::startup::IS_NOT_PROCESS_STARTUP, |
45 chrome::startup::IS_NOT_FIRST_RUN, | 46 chrome::startup::IS_NOT_FIRST_RUN, |
46 desktop_type, | 47 desktop_type, |
47 always_create); | 48 always_create); |
48 } | 49 } |
49 } | 50 } |
50 | 51 |
| 52 // Constants for the show profile switcher experiment |
| 53 const char kShowProfileSwitcherFieldTrialName[] = "ShowProfileSwitcher"; |
| 54 const char kAlwaysShowSwitcherGroupName[] = "AlwaysShow"; |
| 55 |
51 } // namespace | 56 } // namespace |
52 | 57 |
53 AvatarMenuModel::AvatarMenuModel(ProfileInfoInterface* profile_cache, | 58 AvatarMenuModel::AvatarMenuModel(ProfileInfoInterface* profile_cache, |
54 AvatarMenuModelObserver* observer, | 59 AvatarMenuModelObserver* observer, |
55 Browser* browser) | 60 Browser* browser) |
56 : profile_info_(profile_cache), | 61 : profile_info_(profile_cache), |
57 observer_(observer), | 62 observer_(observer), |
58 browser_(browser) { | 63 browser_(browser) { |
59 DCHECK(profile_info_); | 64 DCHECK(profile_info_); |
60 // Don't DCHECK(browser_) so that unit tests can reuse this ctor. | 65 // Don't DCHECK(browser_) so that unit tests can reuse this ctor. |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 const content::NotificationSource& source, | 165 const content::NotificationSource& source, |
161 const content::NotificationDetails& details) { | 166 const content::NotificationDetails& details) { |
162 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, type); | 167 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, type); |
163 RebuildMenu(); | 168 RebuildMenu(); |
164 if (observer_) | 169 if (observer_) |
165 observer_->OnAvatarMenuModelChanged(this); | 170 observer_->OnAvatarMenuModelChanged(this); |
166 } | 171 } |
167 | 172 |
168 // static | 173 // static |
169 bool AvatarMenuModel::ShouldShowAvatarMenu() { | 174 bool AvatarMenuModel::ShouldShowAvatarMenu() { |
| 175 if (base::FieldTrialList::FindFullName(kShowProfileSwitcherFieldTrialName) == |
| 176 kAlwaysShowSwitcherGroupName) { |
| 177 // We should only be in this group when multi-profiles is enabled. |
| 178 DCHECK(ProfileManager::IsMultipleProfilesEnabled()); |
| 179 return true; |
| 180 } |
170 return ProfileManager::IsMultipleProfilesEnabled() && | 181 return ProfileManager::IsMultipleProfilesEnabled() && |
171 g_browser_process->profile_manager()->GetNumberOfProfiles() > 1; | 182 g_browser_process->profile_manager()->GetNumberOfProfiles() > 1; |
172 } | 183 } |
173 | 184 |
174 void AvatarMenuModel::RebuildMenu() { | 185 void AvatarMenuModel::RebuildMenu() { |
175 ClearMenu(); | 186 ClearMenu(); |
176 | 187 |
177 const size_t count = profile_info_->GetNumberOfProfiles(); | 188 const size_t count = profile_info_->GetNumberOfProfiles(); |
178 for (size_t i = 0; i < count; ++i) { | 189 for (size_t i = 0; i < count; ++i) { |
179 bool is_gaia_picture = | 190 bool is_gaia_picture = |
(...skipping 14 matching lines...) Expand all Loading... |
194 FilePath path = profile_info_->GetPathOfProfileAtIndex(i); | 205 FilePath path = profile_info_->GetPathOfProfileAtIndex(i); |
195 item->active = browser_->profile()->GetPath() == path; | 206 item->active = browser_->profile()->GetPath() == path; |
196 } | 207 } |
197 items_.push_back(item); | 208 items_.push_back(item); |
198 } | 209 } |
199 } | 210 } |
200 | 211 |
201 void AvatarMenuModel::ClearMenu() { | 212 void AvatarMenuModel::ClearMenu() { |
202 STLDeleteElements(&items_); | 213 STLDeleteElements(&items_); |
203 } | 214 } |
OLD | NEW |