| 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/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| 11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.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_model_observer.h" | 15 #include "chrome/browser/profiles/avatar_menu_model_observer.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/profiles/profile_info_cache.h" | 17 #include "chrome/browser/profiles/profile_info_cache.h" |
| 18 #include "chrome/browser/profiles/profile_info_util.h" | 18 #include "chrome/browser/profiles/profile_info_util.h" |
| 19 #include "chrome/browser/profiles/profile_manager.h" | 19 #include "chrome/browser/profiles/profile_manager.h" |
| 20 #include "chrome/browser/profiles/profile_metrics.h" | 20 #include "chrome/browser/profiles/profile_metrics.h" |
| 21 #include "chrome/browser/profiles/profile_window.h" |
| 22 #include "chrome/browser/profiles/profiles_state.h" |
| 21 #include "chrome/browser/ui/browser.h" | 23 #include "chrome/browser/ui/browser.h" |
| 22 #include "chrome/browser/ui/browser_list.h" | 24 #include "chrome/browser/ui/browser_list.h" |
| 23 #include "chrome/browser/ui/browser_window.h" | 25 #include "chrome/browser/ui/browser_window.h" |
| 24 #include "chrome/browser/ui/chrome_pages.h" | 26 #include "chrome/browser/ui/chrome_pages.h" |
| 25 #include "chrome/browser/ui/host_desktop.h" | 27 #include "chrome/browser/ui/host_desktop.h" |
| 26 #include "chrome/browser/ui/startup/startup_browser_creator.h" | 28 #include "chrome/browser/ui/startup/startup_browser_creator.h" |
| 27 #include "chrome/common/chrome_switches.h" | 29 #include "chrome/common/chrome_switches.h" |
| 28 #include "chrome/common/url_constants.h" | 30 #include "chrome/common/url_constants.h" |
| 29 #include "content/public/browser/browser_thread.h" | 31 #include "content/public/browser/browser_thread.h" |
| 30 #include "content/public/browser/notification_service.h" | 32 #include "content/public/browser/notification_service.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 44 | 46 |
| 45 namespace { | 47 namespace { |
| 46 | 48 |
| 47 void OnProfileCreated(bool always_create, | 49 void OnProfileCreated(bool always_create, |
| 48 chrome::HostDesktopType desktop_type, | 50 chrome::HostDesktopType desktop_type, |
| 49 Profile* profile, | 51 Profile* profile, |
| 50 Profile::CreateStatus status) { | 52 Profile::CreateStatus status) { |
| 51 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 53 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 52 | 54 |
| 53 if (status == Profile::CREATE_STATUS_INITIALIZED) { | 55 if (status == Profile::CREATE_STATUS_INITIALIZED) { |
| 54 ProfileManager::FindOrCreateNewWindowForProfile( | 56 profiles::FindOrCreateNewWindowForProfile( |
| 55 profile, | 57 profile, |
| 56 chrome::startup::IS_NOT_PROCESS_STARTUP, | 58 chrome::startup::IS_NOT_PROCESS_STARTUP, |
| 57 chrome::startup::IS_NOT_FIRST_RUN, | 59 chrome::startup::IS_NOT_FIRST_RUN, |
| 58 desktop_type, | 60 desktop_type, |
| 59 always_create); | 61 always_create); |
| 60 } | 62 } |
| 61 } | 63 } |
| 62 | 64 |
| 63 // Constants for the show profile switcher experiment | 65 // Constants for the show profile switcher experiment |
| 64 const char kShowProfileSwitcherFieldTrialName[] = "ShowProfileSwitcher"; | 66 const char kShowProfileSwitcherFieldTrialName[] = "ShowProfileSwitcher"; |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 active(false), | 135 active(false), |
| 134 signed_in(false), | 136 signed_in(false), |
| 135 signin_required(false), | 137 signin_required(false), |
| 136 model_index(model_index) { | 138 model_index(model_index) { |
| 137 } | 139 } |
| 138 | 140 |
| 139 AvatarMenuModel::Item::~Item() { | 141 AvatarMenuModel::Item::~Item() { |
| 140 } | 142 } |
| 141 | 143 |
| 142 void AvatarMenuModel::SwitchToProfile(size_t index, bool always_create) { | 144 void AvatarMenuModel::SwitchToProfile(size_t index, bool always_create) { |
| 143 DCHECK(ProfileManager::IsMultipleProfilesEnabled() || | 145 DCHECK(profiles::IsMultipleProfilesEnabled() || |
| 144 index == GetActiveProfileIndex()); | 146 index == GetActiveProfileIndex()); |
| 145 const Item& item = GetItemAt(index); | 147 const Item& item = GetItemAt(index); |
| 146 base::FilePath path = | 148 base::FilePath path = |
| 147 profile_info_->GetPathOfProfileAtIndex(item.model_index); | 149 profile_info_->GetPathOfProfileAtIndex(item.model_index); |
| 148 | 150 |
| 149 chrome::HostDesktopType desktop_type = chrome::GetActiveDesktop(); | 151 chrome::HostDesktopType desktop_type = chrome::GetActiveDesktop(); |
| 150 if (browser_) | 152 if (browser_) |
| 151 desktop_type = browser_->host_desktop_type(); | 153 desktop_type = browser_->host_desktop_type(); |
| 152 | 154 |
| 153 g_browser_process->profile_manager()->CreateProfileAsync( | 155 g_browser_process->profile_manager()->CreateProfileAsync( |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 // static | 276 // static |
| 275 bool AvatarMenuModel::ShouldShowAvatarMenu() { | 277 bool AvatarMenuModel::ShouldShowAvatarMenu() { |
| 276 #if defined(OS_CHROMEOS) | 278 #if defined(OS_CHROMEOS) |
| 277 // On Chrome OS we use different UI for multi-profiles. | 279 // On Chrome OS we use different UI for multi-profiles. |
| 278 return false; | 280 return false; |
| 279 #endif | 281 #endif |
| 280 | 282 |
| 281 if (base::FieldTrialList::FindFullName(kShowProfileSwitcherFieldTrialName) == | 283 if (base::FieldTrialList::FindFullName(kShowProfileSwitcherFieldTrialName) == |
| 282 kAlwaysShowSwitcherGroupName) { | 284 kAlwaysShowSwitcherGroupName) { |
| 283 // We should only be in this group when multi-profiles is enabled. | 285 // We should only be in this group when multi-profiles is enabled. |
| 284 DCHECK(ProfileManager::IsMultipleProfilesEnabled()); | 286 DCHECK(profiles::IsMultipleProfilesEnabled()); |
| 285 return true; | 287 return true; |
| 286 } | 288 } |
| 287 if (ProfileManager::IsMultipleProfilesEnabled()) { | 289 if (profiles::IsMultipleProfilesEnabled()) { |
| 288 return ProfileManager::IsNewProfileManagementEnabled() || | 290 return profiles::IsNewProfileManagementEnabled() || |
| 289 (g_browser_process->profile_manager() && | 291 (g_browser_process->profile_manager() && |
| 290 g_browser_process->profile_manager()->GetNumberOfProfiles() > 1); | 292 g_browser_process->profile_manager()->GetNumberOfProfiles() > 1); |
| 291 } | 293 } |
| 292 return false; | 294 return false; |
| 293 } | 295 } |
| 294 | 296 |
| 295 void AvatarMenuModel::RebuildMenu() { | 297 void AvatarMenuModel::RebuildMenu() { |
| 296 ClearMenu(); | 298 ClearMenu(); |
| 297 | 299 |
| 298 const size_t count = profile_info_->GetNumberOfProfiles(); | 300 const size_t count = profile_info_->GetNumberOfProfiles(); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 contents->GetController().LoadURL( | 357 contents->GetController().LoadURL( |
| 356 logout_url, content::Referrer(), | 358 logout_url, content::Referrer(), |
| 357 content::PAGE_TRANSITION_GENERATED, std::string()); | 359 content::PAGE_TRANSITION_GENERATED, std::string()); |
| 358 | 360 |
| 359 // This object may be destructed when the menu closes but we need something | 361 // This object may be destructed when the menu closes but we need something |
| 360 // around to finish the sign-out process and close the profile windows. | 362 // around to finish the sign-out process and close the profile windows. |
| 361 new SignoutTracker(current_profile, GURL(landing_url), contents); | 363 new SignoutTracker(current_profile, GURL(landing_url), contents); |
| 362 | 364 |
| 363 return contents; // returned for testing purposes | 365 return contents; // returned for testing purposes |
| 364 } | 366 } |
| OLD | NEW |