| 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/ui/sync/one_click_signin_sync_starter.h" | 5 #include "chrome/browser/ui/sync/one_click_signin_sync_starter.h" |
| 6 | 6 |
| 7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 10 | 10 |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 base::Bind(&OneClickSigninSyncStarter::CompleteInitForNewProfile, | 191 base::Bind(&OneClickSigninSyncStarter::CompleteInitForNewProfile, |
| 192 weak_pointer_factory_.GetWeakPtr(), desktop_type_), | 192 weak_pointer_factory_.GetWeakPtr(), desktop_type_), |
| 193 false); | 193 false); |
| 194 } | 194 } |
| 195 | 195 |
| 196 void OneClickSigninSyncStarter::CompleteInitForNewProfile( | 196 void OneClickSigninSyncStarter::CompleteInitForNewProfile( |
| 197 chrome::HostDesktopType desktop_type, | 197 chrome::HostDesktopType desktop_type, |
| 198 Profile* new_profile, | 198 Profile* new_profile, |
| 199 Profile::CreateStatus status) { | 199 Profile::CreateStatus status) { |
| 200 DCHECK_NE(profile_, new_profile); | 200 DCHECK_NE(profile_, new_profile); |
| 201 if (status == Profile::CREATE_STATUS_FAIL) { | |
| 202 // TODO(atwilson): On error, unregister the client to release the DMToken | |
| 203 // and surface a better error for the user. | |
| 204 NOTREACHED() << "Error creating new profile"; | |
| 205 CancelSigninAndDelete(); | |
| 206 return; | |
| 207 } | |
| 208 | 201 |
| 209 // Wait until the profile is initialized before we transfer credentials. | 202 // TODO(atwilson): On error, unregister the client to release the DMToken |
| 210 if (status == Profile::CREATE_STATUS_INITIALIZED) { | 203 // and surface a better error for the user. |
| 211 SigninManager* old_signin_manager = | 204 switch (status) { |
| 212 SigninManagerFactory::GetForProfile(profile_); | 205 case Profile::CREATE_STATUS_LOCAL_FAIL: |
| 213 SigninManager* new_signin_manager = | 206 case Profile::CREATE_STATUS_REMOTE_FAIL: { |
| 214 SigninManagerFactory::GetForProfile(new_profile); | 207 NOTREACHED() << "Error creating new profile"; |
| 215 DCHECK(!old_signin_manager->GetUsernameForAuthInProgress().empty()); | 208 CancelSigninAndDelete(); |
| 216 DCHECK(old_signin_manager->GetAuthenticatedUsername().empty()); | 209 return; |
| 217 DCHECK(new_signin_manager->GetAuthenticatedUsername().empty()); | 210 } |
| 218 DCHECK(policy_client_); | 211 case Profile::CREATE_STATUS_CREATED: { |
| 212 break; |
| 213 } |
| 214 case Profile::CREATE_STATUS_INITIALIZED: { |
| 215 // Wait until the profile is initialized before we transfer credentials. |
| 216 SigninManager* old_signin_manager = |
| 217 SigninManagerFactory::GetForProfile(profile_); |
| 218 SigninManager* new_signin_manager = |
| 219 SigninManagerFactory::GetForProfile(new_profile); |
| 220 DCHECK(!old_signin_manager->GetUsernameForAuthInProgress().empty()); |
| 221 DCHECK(old_signin_manager->GetAuthenticatedUsername().empty()); |
| 222 DCHECK(new_signin_manager->GetAuthenticatedUsername().empty()); |
| 223 DCHECK(policy_client_); |
| 219 | 224 |
| 220 // Copy credentials from the old profile to the just-created profile, | 225 // Copy credentials from the old profile to the just-created profile, |
| 221 // and switch over to tracking that profile. | 226 // and switch over to tracking that profile. |
| 222 new_signin_manager->CopyCredentialsFrom(*old_signin_manager); | 227 new_signin_manager->CopyCredentialsFrom(*old_signin_manager); |
| 223 FinishProfileSyncServiceSetup(); | 228 FinishProfileSyncServiceSetup(); |
| 224 Initialize(new_profile, NULL); | 229 Initialize(new_profile, NULL); |
| 225 DCHECK_EQ(profile_, new_profile); | 230 DCHECK_EQ(profile_, new_profile); |
| 226 | 231 |
| 227 // We've transferred our credentials to the new profile - notify that | 232 // We've transferred our credentials to the new profile - notify that |
| 228 // the signin for the original profile was cancelled (must do this after | 233 // the signin for the original profile was cancelled (must do this after |
| 229 // we have called Initialize() with the new profile, as otherwise this | 234 // we have called Initialize() with the new profile, as otherwise this |
| 230 // object will get freed when the signin on the old profile is cancelled. | 235 // object will get freed when the signin on the old profile is cancelled. |
| 231 old_signin_manager->SignOut(); | 236 old_signin_manager->SignOut(); |
| 232 | 237 |
| 233 // Load policy for the just-created profile - once policy has finished | 238 // Load policy for the just-created profile - once policy has finished |
| 234 // loading the signin process will complete. | 239 // loading the signin process will complete. |
| 235 LoadPolicyWithCachedClient(); | 240 LoadPolicyWithCachedClient(); |
| 236 | 241 |
| 237 // Open the profile's first window, after all initialization. | 242 // Open the profile's first window, after all initialization. |
| 238 ProfileManager::FindOrCreateNewWindowForProfile( | 243 ProfileManager::FindOrCreateNewWindowForProfile( |
| 239 new_profile, | 244 new_profile, |
| 240 chrome::startup::IS_PROCESS_STARTUP, | 245 chrome::startup::IS_PROCESS_STARTUP, |
| 241 chrome::startup::IS_FIRST_RUN, | 246 chrome::startup::IS_FIRST_RUN, |
| 242 desktop_type, | 247 desktop_type, |
| 243 false); | 248 false); |
| 249 } |
| 250 case Profile::MAX_CREATE_STATUS: { |
| 251 NOTREACHED() << "Invalid profile creation status"; |
| 252 CancelSigninAndDelete(); |
| 253 return; |
| 254 } |
| 244 } | 255 } |
| 245 } | 256 } |
| 246 #endif | 257 #endif |
| 247 | 258 |
| 248 void OneClickSigninSyncStarter::ConfirmAndSignin() { | 259 void OneClickSigninSyncStarter::ConfirmAndSignin() { |
| 249 SigninManager* signin = SigninManagerFactory::GetForProfile(profile_); | 260 SigninManager* signin = SigninManagerFactory::GetForProfile(profile_); |
| 250 // browser_ can be null for unit tests. | 261 // browser_ can be null for unit tests. |
| 251 if (browser_ && confirmation_required_ == CONFIRM_UNTRUSTED_SIGNIN) { | 262 if (browser_ && confirmation_required_ == CONFIRM_UNTRUSTED_SIGNIN) { |
| 252 // Display a confirmation dialog to the user. | 263 // Display a confirmation dialog to the user. |
| 253 browser_->window()->ShowOneClickSigninBubble( | 264 browser_->window()->ShowOneClickSigninBubble( |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 | 406 |
| 396 void OneClickSigninSyncStarter::ShowSyncSettingsPageOnSameTab() { | 407 void OneClickSigninSyncStarter::ShowSyncSettingsPageOnSameTab() { |
| 397 std::string url = std::string(chrome::kChromeUISettingsURL) + | 408 std::string url = std::string(chrome::kChromeUISettingsURL) + |
| 398 chrome::kSyncSetupSubPage; | 409 chrome::kSyncSetupSubPage; |
| 399 chrome::NavigateParams params( | 410 chrome::NavigateParams params( |
| 400 browser_, GURL(url), content::PAGE_TRANSITION_AUTO_TOPLEVEL); | 411 browser_, GURL(url), content::PAGE_TRANSITION_AUTO_TOPLEVEL); |
| 401 params.disposition = CURRENT_TAB; | 412 params.disposition = CURRENT_TAB; |
| 402 params.window_action = chrome::NavigateParams::SHOW_WINDOW; | 413 params.window_action = chrome::NavigateParams::SHOW_WINDOW; |
| 403 chrome::Navigate(¶ms); | 414 chrome::Navigate(¶ms); |
| 404 } | 415 } |
| OLD | NEW |