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/command_line.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "chrome/browser/net/gaia/token_service.h" | 9 #include "chrome/browser/net/gaia/token_service.h" |
10 #include "chrome/browser/prefs/pref_service.h" | 10 #include "chrome/browser/prefs/pref_service.h" |
11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/browser/sync/profile_sync_service.h" | 12 #include "chrome/browser/sync/profile_sync_service.h" |
13 #include "chrome/browser/sync/util/oauth.h" | 13 #include "chrome/browser/sync/util/oauth.h" |
14 #include "chrome/common/chrome_notification_types.h" | 14 #include "chrome/common/chrome_notification_types.h" |
15 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
16 #include "chrome/common/net/gaia/gaia_constants.h" | 16 #include "chrome/common/net/gaia/gaia_constants.h" |
17 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
18 #include "content/common/notification_service.h" | 18 #include "content/public/browser/notification_service.h" |
19 | 19 |
20 const char kGetInfoEmailKey[] = "email"; | 20 const char kGetInfoEmailKey[] = "email"; |
21 | 21 |
22 SigninManager::SigninManager() | 22 SigninManager::SigninManager() |
23 : profile_(NULL), had_two_factor_error_(false) {} | 23 : profile_(NULL), had_two_factor_error_(false) {} |
24 | 24 |
25 SigninManager::~SigninManager() {} | 25 SigninManager::~SigninManager() {} |
26 | 26 |
27 // static | 27 // static |
28 void SigninManager::RegisterUserPrefs(PrefService* user_prefs) { | 28 void SigninManager::RegisterUserPrefs(PrefService* user_prefs) { |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 const std::string& value) { | 191 const std::string& value) { |
192 DCHECK(!browser_sync::IsUsingOAuth()); | 192 DCHECK(!browser_sync::IsUsingOAuth()); |
193 DCHECK(key == kGetInfoEmailKey); | 193 DCHECK(key == kGetInfoEmailKey); |
194 | 194 |
195 username_ = value; | 195 username_ = value; |
196 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, username_); | 196 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, username_); |
197 profile_->GetPrefs()->SetBoolean(prefs::kSyncUsingOAuth, false); | 197 profile_->GetPrefs()->SetBoolean(prefs::kSyncUsingOAuth, false); |
198 profile_->GetPrefs()->ScheduleSavePersistentPrefs(); | 198 profile_->GetPrefs()->ScheduleSavePersistentPrefs(); |
199 | 199 |
200 GoogleServiceSigninSuccessDetails details(username_, password_); | 200 GoogleServiceSigninSuccessDetails details(username_, password_); |
201 NotificationService::current()->Notify( | 201 content::NotificationService::current()->Notify( |
202 chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL, | 202 chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL, |
203 content::Source<Profile>(profile_), | 203 content::Source<Profile>(profile_), |
204 content::Details<const GoogleServiceSigninSuccessDetails>(&details)); | 204 content::Details<const GoogleServiceSigninSuccessDetails>(&details)); |
205 | 205 |
206 password_.clear(); // Don't need it anymore. | 206 password_.clear(); // Don't need it anymore. |
207 | 207 |
208 profile_->GetTokenService()->UpdateCredentials(last_result_); | 208 profile_->GetTokenService()->UpdateCredentials(last_result_); |
209 DCHECK(profile_->GetTokenService()->AreCredentialsValid()); | 209 DCHECK(profile_->GetTokenService()->AreCredentialsValid()); |
210 profile_->GetTokenService()->StartFetchingTokens(); | 210 profile_->GetTokenService()->StartFetchingTokens(); |
211 } | 211 } |
(...skipping 16 matching lines...) Expand all Loading... |
228 void SigninManager::OnTokenAuthFailure(const GoogleServiceAuthError& error) { | 228 void SigninManager::OnTokenAuthFailure(const GoogleServiceAuthError& error) { |
229 DCHECK(!browser_sync::IsUsingOAuth()); | 229 DCHECK(!browser_sync::IsUsingOAuth()); |
230 #if !defined(OS_CHROMEOS) | 230 #if !defined(OS_CHROMEOS) |
231 VLOG(1) << "Unable to retrieve the token auth."; | 231 VLOG(1) << "Unable to retrieve the token auth."; |
232 CleanupNotificationRegistration(); | 232 CleanupNotificationRegistration(); |
233 #endif | 233 #endif |
234 } | 234 } |
235 | 235 |
236 void SigninManager::OnClientLoginFailure(const GoogleServiceAuthError& error) { | 236 void SigninManager::OnClientLoginFailure(const GoogleServiceAuthError& error) { |
237 DCHECK(!browser_sync::IsUsingOAuth()); | 237 DCHECK(!browser_sync::IsUsingOAuth()); |
238 NotificationService::current()->Notify( | 238 content::NotificationService::current()->Notify( |
239 chrome::NOTIFICATION_GOOGLE_SIGNIN_FAILED, | 239 chrome::NOTIFICATION_GOOGLE_SIGNIN_FAILED, |
240 content::Source<Profile>(profile_), | 240 content::Source<Profile>(profile_), |
241 content::Details<const GoogleServiceAuthError>(&error)); | 241 content::Details<const GoogleServiceAuthError>(&error)); |
242 | 242 |
243 // We don't sign-out if the password was valid and we're just dealing with | 243 // We don't sign-out if the password was valid and we're just dealing with |
244 // a second factor error, and we don't sign out if we're dealing with | 244 // a second factor error, and we don't sign out if we're dealing with |
245 // an invalid access code (again, because the password was valid). | 245 // an invalid access code (again, because the password was valid). |
246 bool invalid_gaia = error.state() == | 246 bool invalid_gaia = error.state() == |
247 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS; | 247 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS; |
248 if (error.state() == GoogleServiceAuthError::TWO_FACTOR || | 248 if (error.state() == GoogleServiceAuthError::TWO_FACTOR || |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 | 295 |
296 VLOG(1) << "Sync signin for " << email << " is complete."; | 296 VLOG(1) << "Sync signin for " << email << " is complete."; |
297 oauth_username_ = email; | 297 oauth_username_ = email; |
298 profile_->GetPrefs()->SetString( | 298 profile_->GetPrefs()->SetString( |
299 prefs::kGoogleServicesUsername, oauth_username_); | 299 prefs::kGoogleServicesUsername, oauth_username_); |
300 profile_->GetPrefs()->SetBoolean(prefs::kSyncUsingOAuth, true); | 300 profile_->GetPrefs()->SetBoolean(prefs::kSyncUsingOAuth, true); |
301 profile_->GetPrefs()->ScheduleSavePersistentPrefs(); | 301 profile_->GetPrefs()->ScheduleSavePersistentPrefs(); |
302 | 302 |
303 DCHECK(password_.empty()); | 303 DCHECK(password_.empty()); |
304 GoogleServiceSigninSuccessDetails details(oauth_username_, ""); | 304 GoogleServiceSigninSuccessDetails details(oauth_username_, ""); |
305 NotificationService::current()->Notify( | 305 content::NotificationService::current()->Notify( |
306 chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL, | 306 chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL, |
307 content::Source<Profile>(profile_), | 307 content::Source<Profile>(profile_), |
308 content::Details<const GoogleServiceSigninSuccessDetails>(&details)); | 308 content::Details<const GoogleServiceSigninSuccessDetails>(&details)); |
309 | 309 |
310 DCHECK(token_service->HasOAuthCredentials()); | 310 DCHECK(token_service->HasOAuthCredentials()); |
311 token_service->StartFetchingOAuthTokens(); | 311 token_service->StartFetchingOAuthTokens(); |
312 } | 312 } |
313 | 313 |
314 void SigninManager::OnUserInfoFailure(const GoogleServiceAuthError& error) { | 314 void SigninManager::OnUserInfoFailure(const GoogleServiceAuthError& error) { |
315 DCHECK(browser_sync::IsUsingOAuth()); | 315 DCHECK(browser_sync::IsUsingOAuth()); |
(...skipping 18 matching lines...) Expand all Loading... |
334 profile_->GetRequestContext())); | 334 profile_->GetRequestContext())); |
335 } | 335 } |
336 | 336 |
337 client_login_->StartMergeSession(tok_details->token()); | 337 client_login_->StartMergeSession(tok_details->token()); |
338 | 338 |
339 // We only want to do this once per sign-in. | 339 // We only want to do this once per sign-in. |
340 CleanupNotificationRegistration(); | 340 CleanupNotificationRegistration(); |
341 } | 341 } |
342 #endif | 342 #endif |
343 } | 343 } |
OLD | NEW |