| 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" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 | 37 |
| 38 #if defined(ENABLE_MANAGED_USERS) | 38 #if defined(ENABLE_MANAGED_USERS) |
| 39 #include "chrome/browser/managed_mode/managed_user_service.h" | 39 #include "chrome/browser/managed_mode/managed_user_service.h" |
| 40 #include "chrome/browser/managed_mode/managed_user_service_factory.h" | 40 #include "chrome/browser/managed_mode/managed_user_service_factory.h" |
| 41 #endif | 41 #endif |
| 42 | 42 |
| 43 using content::BrowserThread; | 43 using content::BrowserThread; |
| 44 | 44 |
| 45 namespace { | 45 namespace { |
| 46 | 46 |
| 47 void OnProfileCreated(bool always_create, | |
| 48 chrome::HostDesktopType desktop_type, | |
| 49 Profile* profile, | |
| 50 Profile::CreateStatus status) { | |
| 51 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 52 | |
| 53 if (status == Profile::CREATE_STATUS_INITIALIZED) { | |
| 54 ProfileManager::FindOrCreateNewWindowForProfile( | |
| 55 profile, | |
| 56 chrome::startup::IS_NOT_PROCESS_STARTUP, | |
| 57 chrome::startup::IS_NOT_FIRST_RUN, | |
| 58 desktop_type, | |
| 59 always_create); | |
| 60 } | |
| 61 } | |
| 62 | |
| 63 // Constants for the show profile switcher experiment | 47 // Constants for the show profile switcher experiment |
| 64 const char kShowProfileSwitcherFieldTrialName[] = "ShowProfileSwitcher"; | 48 const char kShowProfileSwitcherFieldTrialName[] = "ShowProfileSwitcher"; |
| 65 const char kAlwaysShowSwitcherGroupName[] = "AlwaysShow"; | 49 const char kAlwaysShowSwitcherGroupName[] = "AlwaysShow"; |
| 66 | 50 |
| 67 | 51 |
| 68 class SignoutTracker : public content::WebContentsObserver { | 52 class SignoutTracker : public content::WebContentsObserver { |
| 69 public: | 53 public: |
| 70 SignoutTracker(Profile* profile, const GURL& signout_landing_url, | 54 SignoutTracker(Profile* profile, const GURL& signout_landing_url, |
| 71 content::WebContents* contents); | 55 content::WebContents* contents); |
| 72 | 56 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 DCHECK(ProfileManager::IsMultipleProfilesEnabled() || | 127 DCHECK(ProfileManager::IsMultipleProfilesEnabled() || |
| 144 index == GetActiveProfileIndex()); | 128 index == GetActiveProfileIndex()); |
| 145 const Item& item = GetItemAt(index); | 129 const Item& item = GetItemAt(index); |
| 146 base::FilePath path = | 130 base::FilePath path = |
| 147 profile_info_->GetPathOfProfileAtIndex(item.model_index); | 131 profile_info_->GetPathOfProfileAtIndex(item.model_index); |
| 148 | 132 |
| 149 chrome::HostDesktopType desktop_type = chrome::GetActiveDesktop(); | 133 chrome::HostDesktopType desktop_type = chrome::GetActiveDesktop(); |
| 150 if (browser_) | 134 if (browser_) |
| 151 desktop_type = browser_->host_desktop_type(); | 135 desktop_type = browser_->host_desktop_type(); |
| 152 | 136 |
| 153 g_browser_process->profile_manager()->CreateProfileAsync( | 137 ProfileManager::SwitchToProfile(path, desktop_type, always_create); |
| 154 path, | |
| 155 base::Bind(&OnProfileCreated, | |
| 156 always_create, | |
| 157 desktop_type), | |
| 158 string16(), | |
| 159 string16(), | |
| 160 false); | |
| 161 | |
| 162 ProfileMetrics::LogProfileSwitchUser(ProfileMetrics::SWITCH_PROFILE_ICON); | 138 ProfileMetrics::LogProfileSwitchUser(ProfileMetrics::SWITCH_PROFILE_ICON); |
| 163 } | 139 } |
| 164 | 140 |
| 165 void AvatarMenuModel::EditProfile(size_t index) { | 141 void AvatarMenuModel::EditProfile(size_t index) { |
| 166 Browser* browser = browser_; | 142 Browser* browser = browser_; |
| 167 if (!browser) { | 143 if (!browser) { |
| 168 Profile* profile = g_browser_process->profile_manager()->GetProfileByPath( | 144 Profile* profile = g_browser_process->profile_manager()->GetProfileByPath( |
| 169 profile_info_->GetPathOfProfileAtIndex(GetItemAt(index).model_index)); | 145 profile_info_->GetPathOfProfileAtIndex(GetItemAt(index).model_index)); |
| 170 browser = new Browser(Browser::CreateParams(profile, | 146 browser = new Browser(Browser::CreateParams(profile, |
| 171 chrome::GetActiveDesktop())); | 147 chrome::GetActiveDesktop())); |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 contents->GetController().LoadURL( | 316 contents->GetController().LoadURL( |
| 341 logout_url, content::Referrer(), | 317 logout_url, content::Referrer(), |
| 342 content::PAGE_TRANSITION_GENERATED, std::string()); | 318 content::PAGE_TRANSITION_GENERATED, std::string()); |
| 343 | 319 |
| 344 // This object may be destructed when the menu closes but we need something | 320 // This object may be destructed when the menu closes but we need something |
| 345 // around to finish the sign-out process and close the profile windows. | 321 // around to finish the sign-out process and close the profile windows. |
| 346 new SignoutTracker(current_profile, GURL(landing_url), contents); | 322 new SignoutTracker(current_profile, GURL(landing_url), contents); |
| 347 | 323 |
| 348 return contents; // returned for testing purposes | 324 return contents; // returned for testing purposes |
| 349 } | 325 } |
| OLD | NEW |