Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/signin/profile_oauth2_token_service.h" | 5 #include "chrome/browser/signin/profile_oauth2_token_service.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 115 const GoogleServiceAuthError& error) { | 115 const GoogleServiceAuthError& error) { |
| 116 // Do not report connection errors as these are not actually auth errors. | 116 // Do not report connection errors as these are not actually auth errors. |
| 117 // We also want to avoid masking a "real" auth error just because we | 117 // We also want to avoid masking a "real" auth error just because we |
| 118 // subsequently get a transient network error. | 118 // subsequently get a transient network error. |
| 119 if (error.state() == GoogleServiceAuthError::CONNECTION_FAILED) | 119 if (error.state() == GoogleServiceAuthError::CONNECTION_FAILED) |
| 120 return; | 120 return; |
| 121 | 121 |
| 122 if (error.state() != last_auth_error_.state()) { | 122 if (error.state() != last_auth_error_.state()) { |
| 123 last_auth_error_ = error; | 123 last_auth_error_ = error; |
| 124 signin_global_error_->AuthStatusChanged(); | 124 signin_global_error_->AuthStatusChanged(); |
| 125 | |
| 126 if (last_auth_error_.state() == | |
| 127 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS) { | |
| 128 RevokeCredentials(GetAccountId(profile_)); | |
|
Andrew T Wilson (Slow)
2013/08/30 09:03:33
Still extremely nervous about this. Are you sure w
Roger Tawa OOO till Jul 10th
2013/08/30 15:55:40
Yeah, me too. Changed to no longe revoke and chec
| |
| 129 } | |
| 125 } | 130 } |
| 126 } | 131 } |
| 127 | 132 |
| 128 void ProfileOAuth2TokenService::Observe( | 133 void ProfileOAuth2TokenService::Observe( |
| 129 int type, | 134 int type, |
| 130 const content::NotificationSource& source, | 135 const content::NotificationSource& source, |
| 131 const content::NotificationDetails& details) { | 136 const content::NotificationDetails& details) { |
| 132 switch (type) { | 137 switch (type) { |
| 133 case chrome::NOTIFICATION_TOKEN_AVAILABLE: { | 138 case chrome::NOTIFICATION_TOKEN_AVAILABLE: { |
| 134 TokenService::TokenAvailableDetails* tok_details = | 139 TokenService::TokenAvailableDetails* tok_details = |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 237 CancelRequestsForToken(refresh_tokens_[account_id]); | 242 CancelRequestsForToken(refresh_tokens_[account_id]); |
| 238 refresh_tokens_.erase(account_id); | 243 refresh_tokens_.erase(account_id); |
| 239 scoped_refptr<TokenWebData> token_web_data = | 244 scoped_refptr<TokenWebData> token_web_data = |
| 240 TokenWebData::FromBrowserContext(profile_); | 245 TokenWebData::FromBrowserContext(profile_); |
| 241 if (token_web_data.get()) | 246 if (token_web_data.get()) |
| 242 token_web_data->RemoveTokenForService(ApplyAccountIdPrefix(account_id)); | 247 token_web_data->RemoveTokenForService(ApplyAccountIdPrefix(account_id)); |
| 243 FireRefreshTokenRevoked(account_id); | 248 FireRefreshTokenRevoked(account_id); |
| 244 | 249 |
| 245 // TODO(fgorski): Notify diagnostic observers. | 250 // TODO(fgorski): Notify diagnostic observers. |
| 246 } | 251 } |
| 252 | |
| 253 // Remove the token from TokenService if this corresponds to the connected | |
| 254 // account. | |
| 255 if (account_id == GetAccountId(profile_)) { | |
| 256 TokenService* token_service = | |
| 257 TokenServiceFactory::GetForProfile(profile_); | |
| 258 token_service->ClearOAuth2Credentials(); | |
| 259 DCHECK(!token_service->HasOAuthLoginToken()); | |
| 260 } | |
| 247 } | 261 } |
| 248 | 262 |
| 249 void ProfileOAuth2TokenService::RevokeAllCredentials() { | 263 void ProfileOAuth2TokenService::RevokeAllCredentials() { |
| 250 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 264 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 251 | 265 |
| 252 CancelAllRequests(); | 266 CancelAllRequests(); |
| 253 for (std::map<std::string, std::string>::const_iterator iter = | 267 for (std::map<std::string, std::string>::const_iterator iter = |
| 254 refresh_tokens_.begin(); | 268 refresh_tokens_.begin(); |
| 255 iter != refresh_tokens_.end(); | 269 iter != refresh_tokens_.end(); |
| 256 ++iter) { | 270 ++iter) { |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 323 } | 337 } |
| 324 } | 338 } |
| 325 | 339 |
| 326 if (!old_login_token.empty() && | 340 if (!old_login_token.empty() && |
| 327 refresh_tokens_.count(GetAccountId(profile_)) == 0) { | 341 refresh_tokens_.count(GetAccountId(profile_)) == 0) { |
| 328 UpdateCredentials(GetAccountId(profile_), old_login_token); | 342 UpdateCredentials(GetAccountId(profile_), old_login_token); |
| 329 } | 343 } |
| 330 | 344 |
| 331 FireRefreshTokensLoaded(); | 345 FireRefreshTokensLoaded(); |
| 332 } | 346 } |
| OLD | NEW |