Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/signin/core/browser/profile_oauth2_token_service.h" | 5 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "google_apis/gaia/oauth2_token_service_delegate.h" |
| 8 #include "base/message_loop/message_loop.h" | |
| 9 #include "base/stl_util.h" | |
| 10 #include "base/time/time.h" | |
| 11 #include "components/signin/core/browser/signin_client.h" | |
| 12 #include "components/signin/core/browser/signin_error_controller.h" | |
| 13 #include "google_apis/gaia/gaia_auth_util.h" | |
| 14 #include "net/url_request/url_request_context_getter.h" | 8 #include "net/url_request/url_request_context_getter.h" |
| 15 | 9 |
| 16 ProfileOAuth2TokenService::ProfileOAuth2TokenService() | 10 ProfileOAuth2TokenService::ProfileOAuth2TokenService( |
| 17 : client_(NULL), | 11 OAuth2TokenServiceDelegate* delegate) |
| 18 signin_error_controller_(NULL) {} | 12 : OAuth2TokenService(delegate) { |
| 13 } | |
| 19 | 14 |
| 20 ProfileOAuth2TokenService::~ProfileOAuth2TokenService() {} | 15 ProfileOAuth2TokenService::~ProfileOAuth2TokenService() {} |
| 21 | 16 |
| 22 void ProfileOAuth2TokenService::Initialize( | |
| 23 SigninClient* client, | |
| 24 SigninErrorController* signin_error_controller) { | |
| 25 DCHECK(client); | |
| 26 DCHECK(!client_); | |
| 27 DCHECK(signin_error_controller); | |
| 28 DCHECK(!signin_error_controller_); | |
| 29 client_ = client; | |
| 30 signin_error_controller_ = signin_error_controller; | |
| 31 } | |
| 32 | |
| 33 void ProfileOAuth2TokenService::Shutdown() { | 17 void ProfileOAuth2TokenService::Shutdown() { |
| 34 DCHECK(client_) << "Shutdown() called without matching call to Initialize()"; | 18 CancelAllRequests(); |
| 19 GetDelegate()->Shutdown(); | |
| 35 } | 20 } |
| 36 | 21 |
| 37 net::URLRequestContextGetter* ProfileOAuth2TokenService::GetRequestContext() { | 22 net::URLRequestContextGetter* ProfileOAuth2TokenService::GetRequestContext() { |
| 38 return NULL; | 23 return GetDelegate()->GetRequestContext(); |
| 39 } | |
| 40 | |
| 41 void ProfileOAuth2TokenService::UpdateAuthError( | |
| 42 const std::string& account_id, | |
| 43 const GoogleServiceAuthError& error) { | |
| 44 NOTREACHED(); | |
| 45 } | |
| 46 | |
| 47 void ProfileOAuth2TokenService::ValidateAccountId( | |
| 48 const std::string& account_id) const { | |
| 49 DCHECK(!account_id.empty()); | |
| 50 | |
| 51 // If the account is given as an email, make sure its a canonical email. | |
| 52 // Note that some tests don't use email strings as account id, and after | |
| 53 // the gaia id migration it won't be an email. So only check for | |
| 54 // canonicalization if the account_id is suspected to be an email. | |
| 55 if (account_id.find('@') != std::string::npos) | |
| 56 DCHECK_EQ(gaia::CanonicalizeEmail(account_id), account_id); | |
| 57 } | |
| 58 | |
| 59 std::vector<std::string> ProfileOAuth2TokenService::GetAccounts() { | |
| 60 NOTREACHED(); | |
| 61 return std::vector<std::string>(); | |
| 62 } | 24 } |
| 63 | 25 |
| 64 void ProfileOAuth2TokenService::LoadCredentials( | 26 void ProfileOAuth2TokenService::LoadCredentials( |
| 65 const std::string& primary_account_id) { | 27 const std::string& primary_account_id) { |
| 66 // Empty implementation by default. | 28 CancelAllRequests(); |
| 29 GetDelegate()->LoadCredentials(primary_account_id); | |
| 67 } | 30 } |
| 68 | 31 |
| 69 void ProfileOAuth2TokenService::UpdateCredentials( | 32 void ProfileOAuth2TokenService::UpdateCredentials( |
| 70 const std::string& account_id, | 33 const std::string& account_id, |
| 71 const std::string& refresh_token) { | 34 const std::string& refresh_token) { |
| 72 NOTREACHED(); | 35 std::string present_refresh_token = |
| 36 GetDelegate()->GetRefreshToken(account_id); | |
| 37 if (!present_refresh_token.empty() && | |
| 38 present_refresh_token == refresh_token) { | |
| 39 CancelRequestsForAccount(account_id); | |
| 40 ClearCacheForAccount(account_id); | |
| 41 } | |
|
Roger Tawa OOO till Jul 10th
2015/05/24 21:13:18
Should always cancel requests and clear the cache
gogerald1
2015/05/25 21:10:57
what if the update credential is the current crede
Roger Tawa OOO till Jul 10th
2015/05/28 14:54:43
Acknowledged.
| |
| 42 GetDelegate()->UpdateCredentials(account_id, refresh_token); | |
| 73 } | 43 } |
| 74 | 44 |
| 75 void ProfileOAuth2TokenService::RevokeAllCredentials() { | 45 void ProfileOAuth2TokenService::RevokeCredentials( |
| 76 // Empty implementation by default. | 46 const std::string& account_id) { |
| 77 } | 47 GetDelegate()->RevokeCredentials(account_id); |
| 48 } | |
| OLD | NEW |