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 NOTREACHED() << "Error creating new profile"; |
214 SigninManagerFactory::GetForProfile(new_profile); | 207 CancelSigninAndDelete(); |
215 DCHECK(!old_signin_manager->GetUsernameForAuthInProgress().empty()); | 208 return; |
216 DCHECK(old_signin_manager->GetAuthenticatedUsername().empty()); | 209 } |
217 DCHECK(new_signin_manager->GetAuthenticatedUsername().empty()); | 210 case Profile::CREATE_STATUS_CREATED: { |
218 DCHECK(policy_client_); | 211 break; |
| 212 } |
| 213 case Profile::CREATE_STATUS_INITIALIZED: { |
| 214 // Wait until the profile is initialized before we transfer credentials. |
| 215 SigninManager* old_signin_manager = |
| 216 SigninManagerFactory::GetForProfile(profile_); |
| 217 SigninManager* new_signin_manager = |
| 218 SigninManagerFactory::GetForProfile(new_profile); |
| 219 DCHECK(!old_signin_manager->GetUsernameForAuthInProgress().empty()); |
| 220 DCHECK(old_signin_manager->GetAuthenticatedUsername().empty()); |
| 221 DCHECK(new_signin_manager->GetAuthenticatedUsername().empty()); |
| 222 DCHECK(policy_client_); |
219 | 223 |
220 // Copy credentials from the old profile to the just-created profile, | 224 // Copy credentials from the old profile to the just-created profile, |
221 // and switch over to tracking that profile. | 225 // and switch over to tracking that profile. |
222 new_signin_manager->CopyCredentialsFrom(*old_signin_manager); | 226 new_signin_manager->CopyCredentialsFrom(*old_signin_manager); |
223 FinishProfileSyncServiceSetup(); | 227 FinishProfileSyncServiceSetup(); |
224 Initialize(new_profile, NULL); | 228 Initialize(new_profile, NULL); |
225 DCHECK_EQ(profile_, new_profile); | 229 DCHECK_EQ(profile_, new_profile); |
226 | 230 |
227 // We've transferred our credentials to the new profile - notify that | 231 // We've transferred our credentials to the new profile - notify that |
228 // the signin for the original profile was cancelled (must do this after | 232 // the signin for the original profile was cancelled (must do this after |
229 // we have called Initialize() with the new profile, as otherwise this | 233 // 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. | 234 // object will get freed when the signin on the old profile is cancelled. |
231 old_signin_manager->SignOut(); | 235 old_signin_manager->SignOut(); |
232 | 236 |
233 // Load policy for the just-created profile - once policy has finished | 237 // Load policy for the just-created profile - once policy has finished |
234 // loading the signin process will complete. | 238 // loading the signin process will complete. |
235 LoadPolicyWithCachedClient(); | 239 LoadPolicyWithCachedClient(); |
236 | 240 |
237 // Open the profile's first window, after all initialization. | 241 // Open the profile's first window, after all initialization. |
238 ProfileManager::FindOrCreateNewWindowForProfile( | 242 ProfileManager::FindOrCreateNewWindowForProfile( |
239 new_profile, | 243 new_profile, |
240 chrome::startup::IS_PROCESS_STARTUP, | 244 chrome::startup::IS_PROCESS_STARTUP, |
241 chrome::startup::IS_FIRST_RUN, | 245 chrome::startup::IS_FIRST_RUN, |
242 desktop_type, | 246 desktop_type, |
243 false); | 247 false); |
| 248 } |
| 249 case Profile::CREATE_STATUS_REMOTE_FAIL: |
| 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 |