| 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 "chrome/browser/profiles/profile.h" | 7 #include "chrome/browser/profiles/profile.h" |
| 8 #include "chrome/browser/signin/signin_manager.h" | 8 #include "chrome/browser/signin/signin_manager.h" |
| 9 #include "chrome/browser/signin/signin_manager_factory.h" | 9 #include "chrome/browser/signin/signin_manager_factory.h" |
| 10 #include "chrome/browser/sync/profile_sync_service.h" | 10 #include "chrome/browser/sync/profile_sync_service.h" |
| 11 #include "chrome/browser/sync/profile_sync_service_factory.h" | 11 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 12 #include "chrome/browser/sync/sync_prefs.h" |
| 12 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
| 13 #include "chrome/browser/ui/webui/signin/login_ui_service.h" | 14 #include "chrome/browser/ui/webui/signin/login_ui_service.h" |
| 14 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" | 15 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" |
| 15 | 16 |
| 16 OneClickSigninSyncStarter::OneClickSigninSyncStarter( | 17 OneClickSigninSyncStarter::OneClickSigninSyncStarter( |
| 17 Browser* browser, | 18 Browser* browser, |
| 18 const std::string& session_index, | 19 const std::string& session_index, |
| 19 const std::string& email, | 20 const std::string& email, |
| 20 const std::string& password, | 21 const std::string& password, |
| 21 StartSyncMode start_mode) | 22 StartSyncMode start_mode) |
| 22 : browser_(browser), | 23 : browser_(browser), |
| 23 signin_tracker_(browser_->profile(), this), | 24 signin_tracker_(browser_->profile(), this), |
| 24 start_mode_(start_mode) { | 25 start_mode_(start_mode) { |
| 25 DCHECK(browser_); | 26 DCHECK(browser_); |
| 26 | 27 |
| 28 // Let the sync service know that setup is in progress so it doesn't start |
| 29 // syncing until the user has finished any configuration. |
| 27 ProfileSyncService* profile_sync_service = | 30 ProfileSyncService* profile_sync_service = |
| 28 ProfileSyncServiceFactory::GetForProfile(browser_->profile()); | 31 ProfileSyncServiceFactory::GetForProfile(browser_->profile()); |
| 29 // Let the sync service know that setup is in progress so it doesn't start | |
| 30 // syncing until the user has finished any configuration. | |
| 31 profile_sync_service->SetSetupInProgress(true); | 32 profile_sync_service->SetSetupInProgress(true); |
| 33 |
| 34 // Make sure the syncing is not suppressed, otherwise the SigninManager |
| 35 // will not be able to compelte sucessfully. |
| 36 browser_sync::SyncPrefs sync_prefs(browser_->profile()->GetPrefs()); |
| 37 sync_prefs.SetStartSuppressed(false); |
| 38 |
| 32 SigninManager* manager = SigninManagerFactory::GetForProfile( | 39 SigninManager* manager = SigninManagerFactory::GetForProfile( |
| 33 browser_->profile()); | 40 browser_->profile()); |
| 34 manager->StartSignInWithCredentials(session_index, email, password); | 41 manager->StartSignInWithCredentials(session_index, email, password); |
| 35 } | 42 } |
| 36 | 43 |
| 37 OneClickSigninSyncStarter::~OneClickSigninSyncStarter() { | 44 OneClickSigninSyncStarter::~OneClickSigninSyncStarter() { |
| 38 } | 45 } |
| 39 | 46 |
| 40 void OneClickSigninSyncStarter::GaiaCredentialsValid() { | 47 void OneClickSigninSyncStarter::GaiaCredentialsValid() { |
| 41 } | 48 } |
| 42 | 49 |
| 43 void OneClickSigninSyncStarter::SigninFailed( | 50 void OneClickSigninSyncStarter::SigninFailed( |
| 44 const GoogleServiceAuthError& error) { | 51 const GoogleServiceAuthError& error) { |
| 45 ProfileSyncService* profile_sync_service = | 52 ProfileSyncService* profile_sync_service = |
| 46 ProfileSyncServiceFactory::GetForProfile(browser_->profile()); | 53 ProfileSyncServiceFactory::GetForProfile(browser_->profile()); |
| 47 profile_sync_service->SetSetupInProgress(false); | 54 profile_sync_service->SetSetupInProgress(false); |
| 48 delete this; | 55 delete this; |
| 49 } | 56 } |
| 50 | 57 |
| 51 void OneClickSigninSyncStarter::SigninSuccess() { | 58 void OneClickSigninSyncStarter::SigninSuccess() { |
| 52 ProfileSyncService* profile_sync_service = | 59 ProfileSyncService* profile_sync_service = |
| 53 ProfileSyncServiceFactory::GetForProfile(browser_->profile()); | 60 ProfileSyncServiceFactory::GetForProfile(browser_->profile()); |
| 54 | 61 |
| 55 if (start_mode_ == SYNC_WITH_DEFAULT_SETTINGS) { | 62 if (start_mode_ == SYNC_WITH_DEFAULT_SETTINGS) { |
| 56 // Just kick off the sync machine, no need to configure it first. | 63 // Just kick off the sync machine, no need to configure it first. |
| 57 profile_sync_service->SetSyncSetupCompleted(); | 64 profile_sync_service->SetSyncSetupCompleted(); |
| 58 profile_sync_service->SetSetupInProgress(false); | 65 profile_sync_service->SetSetupInProgress(false); |
| 59 profile_sync_service->UnsuppressAndStart(); | |
| 60 } else { | 66 } else { |
| 61 // Give the user a chance to configure things. We don't clear the | 67 // Give the user a chance to configure things. We don't clear the |
| 62 // ProfileSyncService::setup_in_progress flag because we don't want sync | 68 // ProfileSyncService::setup_in_progress flag because we don't want sync |
| 63 // to start up until after the configure UI is displayed (the configure UI | 69 // to start up until after the configure UI is displayed (the configure UI |
| 64 // will clear the flag when the user is done setting up sync). | 70 // will clear the flag when the user is done setting up sync). |
| 65 LoginUIServiceFactory::GetForProfile(browser_->profile())->ShowLoginUI( | 71 LoginUIServiceFactory::GetForProfile(browser_->profile())->ShowLoginUI( |
| 66 browser_); | 72 browser_); |
| 67 } | 73 } |
| 68 | 74 |
| 69 delete this; | 75 delete this; |
| 70 } | 76 } |
| OLD | NEW |