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