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 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 SigninManager* new_signin_manager = | 213 SigninManager* new_signin_manager = |
214 SigninManagerFactory::GetForProfile(new_profile); | 214 SigninManagerFactory::GetForProfile(new_profile); |
215 DCHECK(!old_signin_manager->GetUsernameForAuthInProgress().empty()); | 215 DCHECK(!old_signin_manager->GetUsernameForAuthInProgress().empty()); |
216 DCHECK(old_signin_manager->GetAuthenticatedUsername().empty()); | 216 DCHECK(old_signin_manager->GetAuthenticatedUsername().empty()); |
217 DCHECK(new_signin_manager->GetAuthenticatedUsername().empty()); | 217 DCHECK(new_signin_manager->GetAuthenticatedUsername().empty()); |
218 DCHECK(policy_client_); | 218 DCHECK(policy_client_); |
219 | 219 |
220 // Copy credentials from the old profile to the just-created profile, | 220 // Copy credentials from the old profile to the just-created profile, |
221 // and switch over to tracking that profile. | 221 // and switch over to tracking that profile. |
222 new_signin_manager->CopyCredentialsFrom(*old_signin_manager); | 222 new_signin_manager->CopyCredentialsFrom(*old_signin_manager); |
223 ProfileSyncService* profile_sync_service = GetProfileSyncService(); | 223 FinishProfileSyncServiceSetup(); |
224 if (profile_sync_service) | |
225 profile_sync_service->SetSetupInProgress(false); | |
226 Initialize(new_profile, NULL); | 224 Initialize(new_profile, NULL); |
227 DCHECK_EQ(profile_, new_profile); | 225 DCHECK_EQ(profile_, new_profile); |
228 | 226 |
229 // We've transferred our credentials to the new profile - notify that | 227 // We've transferred our credentials to the new profile - notify that |
230 // the signin for the original profile was cancelled (must do this after | 228 // the signin for the original profile was cancelled (must do this after |
231 // we have called Initialize() with the new profile, as otherwise this | 229 // we have called Initialize() with the new profile, as otherwise this |
232 // object will get freed when the signin on the old profile is cancelled. | 230 // object will get freed when the signin on the old profile is cancelled. |
233 old_signin_manager->SignOut(); | 231 old_signin_manager->SignOut(); |
234 | 232 |
235 // Load policy for the just-created profile - once policy has finished | 233 // Load policy for the just-created profile - once policy has finished |
(...skipping 30 matching lines...) Expand all Loading... |
266 if (response == CONFIGURE_SYNC_FIRST) | 264 if (response == CONFIGURE_SYNC_FIRST) |
267 start_mode_ = response; | 265 start_mode_ = response; |
268 SigninManager* signin = SigninManagerFactory::GetForProfile(profile_); | 266 SigninManager* signin = SigninManagerFactory::GetForProfile(profile_); |
269 signin->CompletePendingSignin(); | 267 signin->CompletePendingSignin(); |
270 } | 268 } |
271 } | 269 } |
272 | 270 |
273 | 271 |
274 void OneClickSigninSyncStarter::SigninFailed( | 272 void OneClickSigninSyncStarter::SigninFailed( |
275 const GoogleServiceAuthError& error) { | 273 const GoogleServiceAuthError& error) { |
276 ProfileSyncService* profile_sync_service = GetProfileSyncService(); | 274 FinishProfileSyncServiceSetup(); |
277 if (profile_sync_service) | |
278 profile_sync_service->SetSetupInProgress(false); | |
279 if (confirmation_required_ == CONFIRM_AFTER_SIGNIN) { | 275 if (confirmation_required_ == CONFIRM_AFTER_SIGNIN) { |
280 switch (error.state()) { | 276 switch (error.state()) { |
281 case GoogleServiceAuthError::SERVICE_UNAVAILABLE: | 277 case GoogleServiceAuthError::SERVICE_UNAVAILABLE: |
282 DisplayFinalConfirmationBubble(l10n_util::GetStringUTF16( | 278 DisplayFinalConfirmationBubble(l10n_util::GetStringUTF16( |
283 IDS_SYNC_UNRECOVERABLE_ERROR)); | 279 IDS_SYNC_UNRECOVERABLE_ERROR)); |
284 break; | 280 break; |
285 case GoogleServiceAuthError::REQUEST_CANCELED: | 281 case GoogleServiceAuthError::REQUEST_CANCELED: |
286 // No error notification needed if the user manually cancelled signin. | 282 // No error notification needed if the user manually cancelled signin. |
287 break; | 283 break; |
288 default: | 284 default: |
289 DisplayFinalConfirmationBubble(l10n_util::GetStringUTF16( | 285 DisplayFinalConfirmationBubble(l10n_util::GetStringUTF16( |
290 IDS_SYNC_ERROR_SIGNING_IN)); | 286 IDS_SYNC_ERROR_SIGNING_IN)); |
291 break; | 287 break; |
292 } | 288 } |
293 } | 289 } |
294 delete this; | 290 delete this; |
295 } | 291 } |
296 | 292 |
297 void OneClickSigninSyncStarter::SigninSuccess() { | 293 void OneClickSigninSyncStarter::SigninSuccess() { |
298 ProfileSyncService* profile_sync_service = GetProfileSyncService(); | 294 ProfileSyncService* profile_sync_service = GetProfileSyncService(); |
299 switch (start_mode_) { | 295 switch (start_mode_) { |
300 case SYNC_WITH_DEFAULT_SETTINGS: | 296 case SYNC_WITH_DEFAULT_SETTINGS: |
301 if (profile_sync_service) { | 297 if (profile_sync_service) { |
302 // Just kick off the sync machine, no need to configure it first. | 298 // Just kick off the sync machine, no need to configure it first. |
303 profile_sync_service->OnUserChoseDatatypes(true, | 299 profile_sync_service->OnUserChoseDatatypes(true, |
304 syncer::ModelTypeSet()); | 300 syncer::ModelTypeSet()); |
305 profile_sync_service->SetSyncSetupCompleted(); | 301 profile_sync_service->SetSyncSetupCompleted(); |
306 profile_sync_service->SetSetupInProgress(false); | |
307 } | 302 } |
| 303 FinishProfileSyncServiceSetup(); |
308 if (confirmation_required_ == CONFIRM_AFTER_SIGNIN) { | 304 if (confirmation_required_ == CONFIRM_AFTER_SIGNIN) { |
309 string16 message; | 305 string16 message; |
310 if (!profile_sync_service) { | 306 if (!profile_sync_service) { |
311 // Sync is disabled by policy. | 307 // Sync is disabled by policy. |
312 message = l10n_util::GetStringUTF16( | 308 message = l10n_util::GetStringUTF16( |
313 IDS_ONE_CLICK_SIGNIN_BUBBLE_SYNC_DISABLED_MESSAGE); | 309 IDS_ONE_CLICK_SIGNIN_BUBBLE_SYNC_DISABLED_MESSAGE); |
314 } | 310 } |
315 DisplayFinalConfirmationBubble(message); | 311 DisplayFinalConfirmationBubble(message); |
316 } | 312 } |
317 break; | 313 break; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 EnsureBrowser(); | 358 EnsureBrowser(); |
363 if (profile_sync_service) { | 359 if (profile_sync_service) { |
364 // Need to navigate to the settings page and display the sync UI. | 360 // Need to navigate to the settings page and display the sync UI. |
365 if (force_same_tab_navigation_) { | 361 if (force_same_tab_navigation_) { |
366 ShowSyncSettingsPageOnSameTab(); | 362 ShowSyncSettingsPageOnSameTab(); |
367 } else { | 363 } else { |
368 chrome::ShowSettingsSubPage(browser_, chrome::kSyncSetupSubPage); | 364 chrome::ShowSettingsSubPage(browser_, chrome::kSyncSetupSubPage); |
369 } | 365 } |
370 } else { | 366 } else { |
371 // Sync is disabled - just display the settings page. | 367 // Sync is disabled - just display the settings page. |
| 368 FinishProfileSyncServiceSetup(); |
372 chrome::ShowSettings(browser_); | 369 chrome::ShowSettings(browser_); |
373 } | 370 } |
374 } | 371 } |
375 } | 372 } |
376 | 373 |
377 ProfileSyncService* OneClickSigninSyncStarter::GetProfileSyncService() { | 374 ProfileSyncService* OneClickSigninSyncStarter::GetProfileSyncService() { |
378 ProfileSyncService* service = NULL; | 375 ProfileSyncService* service = NULL; |
379 if (profile_->IsSyncAccessible()) | 376 if (profile_->IsSyncAccessible()) |
380 service = ProfileSyncServiceFactory::GetForProfile(profile_); | 377 service = ProfileSyncServiceFactory::GetForProfile(profile_); |
381 return service; | 378 return service; |
382 } | 379 } |
383 | 380 |
| 381 void OneClickSigninSyncStarter::FinishProfileSyncServiceSetup() { |
| 382 ProfileSyncService* service = |
| 383 ProfileSyncServiceFactory::GetForProfile(profile_); |
| 384 if (service) |
| 385 service->SetSetupInProgress(false); |
| 386 } |
| 387 |
384 void OneClickSigninSyncStarter::ShowSyncSettingsPageOnSameTab() { | 388 void OneClickSigninSyncStarter::ShowSyncSettingsPageOnSameTab() { |
385 std::string url = std::string(chrome::kChromeUISettingsURL) + | 389 std::string url = std::string(chrome::kChromeUISettingsURL) + |
386 chrome::kSyncSetupSubPage; | 390 chrome::kSyncSetupSubPage; |
387 chrome::NavigateParams params( | 391 chrome::NavigateParams params( |
388 browser_, GURL(url), content::PAGE_TRANSITION_AUTO_TOPLEVEL); | 392 browser_, GURL(url), content::PAGE_TRANSITION_AUTO_TOPLEVEL); |
389 params.disposition = CURRENT_TAB; | 393 params.disposition = CURRENT_TAB; |
390 params.window_action = chrome::NavigateParams::SHOW_WINDOW; | 394 params.window_action = chrome::NavigateParams::SHOW_WINDOW; |
391 chrome::Navigate(¶ms); | 395 chrome::Navigate(¶ms); |
392 } | 396 } |
OLD | NEW |