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