OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/sync/signin_manager.h" | 5 #include "chrome/browser/sync/signin_manager.h" |
6 | 6 |
| 7 #include "base/command_line.h" |
7 #include "base/string_util.h" | 8 #include "base/string_util.h" |
8 #include "chrome/browser/net/gaia/token_service.h" | 9 #include "chrome/browser/net/gaia/token_service.h" |
9 #include "chrome/browser/prefs/pref_service.h" | 10 #include "chrome/browser/prefs/pref_service.h" |
10 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/sync/profile_sync_service.h" |
11 #include "chrome/common/net/gaia/gaia_constants.h" | 13 #include "chrome/common/net/gaia/gaia_constants.h" |
12 #include "chrome/common/pref_names.h" | 14 #include "chrome/common/pref_names.h" |
| 15 #include "chrome/common/chrome_switches.h" |
13 #include "content/common/notification_service.h" | 16 #include "content/common/notification_service.h" |
14 | 17 |
15 const char kGetInfoEmailKey[] = "email"; | 18 const char kGetInfoEmailKey[] = "email"; |
16 | 19 |
17 SigninManager::SigninManager() | 20 SigninManager::SigninManager() |
18 : profile_(NULL), had_two_factor_error_(false) {} | 21 : profile_(NULL), had_two_factor_error_(false) {} |
19 | 22 |
20 SigninManager::~SigninManager() {} | 23 SigninManager::~SigninManager() {} |
21 | 24 |
22 // static | 25 // static |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 | 65 |
63 client_login_.reset(new GaiaAuthFetcher(this, | 66 client_login_.reset(new GaiaAuthFetcher(this, |
64 GaiaConstants::kChromeSource, | 67 GaiaConstants::kChromeSource, |
65 profile_->GetRequestContext())); | 68 profile_->GetRequestContext())); |
66 client_login_->StartClientLogin(username, | 69 client_login_->StartClientLogin(username, |
67 password, | 70 password, |
68 "", | 71 "", |
69 login_token, | 72 login_token, |
70 login_captcha, | 73 login_captcha, |
71 GaiaAuthFetcher::HostedAccountsNotAllowed); | 74 GaiaAuthFetcher::HostedAccountsNotAllowed); |
| 75 |
| 76 // Register for token availability. The signin manager will pre-login the |
| 77 // user when the GAIA service token is ready for use. Only do this if we |
| 78 // are not running in ChomiumOS, since it handles pre-login itself. |
| 79 #if !defined(OS_CHROMEOS) |
| 80 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
| 81 switches::kDisableAutoLogin)) { |
| 82 registrar_.Add(this, |
| 83 NotificationType::TOKEN_AVAILABLE, |
| 84 NotificationService::AllSources()); |
| 85 } |
| 86 #endif |
72 } | 87 } |
73 | 88 |
74 void SigninManager::ProvideSecondFactorAccessCode( | 89 void SigninManager::ProvideSecondFactorAccessCode( |
75 const std::string& access_code) { | 90 const std::string& access_code) { |
76 DCHECK(!username_.empty() && !password_.empty() && | 91 DCHECK(!username_.empty() && !password_.empty() && |
77 last_result_.data.empty()); | 92 last_result_.data.empty()); |
78 | 93 |
79 client_login_.reset(new GaiaAuthFetcher(this, | 94 client_login_.reset(new GaiaAuthFetcher(this, |
80 GaiaConstants::kChromeSource, | 95 GaiaConstants::kChromeSource, |
81 profile_->GetRequestContext())); | 96 profile_->GetRequestContext())); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 bool invalid_gaia = error.state() == | 169 bool invalid_gaia = error.state() == |
155 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS; | 170 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS; |
156 if (error.state() == GoogleServiceAuthError::TWO_FACTOR || | 171 if (error.state() == GoogleServiceAuthError::TWO_FACTOR || |
157 (had_two_factor_error_ && invalid_gaia)) { | 172 (had_two_factor_error_ && invalid_gaia)) { |
158 had_two_factor_error_ = true; | 173 had_two_factor_error_ = true; |
159 return; | 174 return; |
160 } | 175 } |
161 | 176 |
162 SignOut(); | 177 SignOut(); |
163 } | 178 } |
| 179 |
| 180 void SigninManager::Observe(NotificationType type, |
| 181 const NotificationSource& source, |
| 182 const NotificationDetails& details) { |
| 183 #if !defined(OS_CHROMEOS) |
| 184 DCHECK(type == NotificationType::TOKEN_AVAILABLE); |
| 185 TokenService::TokenAvailableDetails* tok_details = |
| 186 Details<TokenService::TokenAvailableDetails>(details).ptr(); |
| 187 |
| 188 // If a GAIA service token has become available, use it to pre-login the |
| 189 // user to other services that depend on GAIA credentials. |
| 190 if (tok_details->service() == GaiaConstants::kGaiaService) { |
| 191 if (client_login_.get() == NULL) { |
| 192 client_login_.reset(new GaiaAuthFetcher(this, |
| 193 GaiaConstants::kChromeSource, |
| 194 profile_->GetRequestContext())); |
| 195 } |
| 196 |
| 197 client_login_->StartTokenAuth(tok_details->token()); |
| 198 |
| 199 // We only want to do this once per sign-in. |
| 200 registrar_.Remove(this, |
| 201 NotificationType::TOKEN_AVAILABLE, |
| 202 NotificationService::AllSources()); |
| 203 } |
| 204 #endif |
| 205 } |
OLD | NEW |