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/mutable_profile_oauth2_token_service.h" | 5 #include "chrome/browser/signin/mutable_profile_oauth2_token_service.h" |
| 6 | 6 |
| 7 #include "chrome/browser/profiles/profile.h" | 7 #include "chrome/browser/profiles/profile.h" |
| 8 #include "chrome/browser/webdata/token_web_data.h" | 8 #include "chrome/browser/webdata/token_web_data.h" |
| 9 #include "components/webdata/common/web_data_service_base.h" | 9 #include "components/webdata/common/web_data_service_base.h" |
| 10 #include "google_apis/gaia/gaia_auth_fetcher.h" | |
| 10 #include "google_apis/gaia/gaia_constants.h" | 11 #include "google_apis/gaia/gaia_constants.h" |
| 12 #include "google_apis/gaia/google_service_auth_error.h" | |
| 13 #include "net/url_request/url_request_context_getter.h" | |
| 11 | 14 |
| 12 #if defined(ENABLE_MANAGED_USERS) | 15 #if defined(ENABLE_MANAGED_USERS) |
| 13 #include "chrome/browser/managed_mode/managed_user_constants.h" | 16 #include "chrome/browser/managed_mode/managed_user_constants.h" |
| 14 #endif | 17 #endif |
| 15 | 18 |
| 16 namespace { | 19 namespace { |
| 17 | 20 |
| 18 const char kAccountIdPrefix[] = "AccountId-"; | 21 const char kAccountIdPrefix[] = "AccountId-"; |
| 19 const size_t kAccountIdPrefixLength = 10; | 22 const size_t kAccountIdPrefixLength = 10; |
| 20 | 23 |
| 21 std::string ApplyAccountIdPrefix(const std::string& account_id) { | 24 std::string ApplyAccountIdPrefix(const std::string& account_id) { |
| 22 return kAccountIdPrefix + account_id; | 25 return kAccountIdPrefix + account_id; |
| 23 } | 26 } |
| 24 | 27 |
| 25 bool IsLegacyRefreshTokenId(const std::string& service_id) { | 28 bool IsLegacyRefreshTokenId(const std::string& service_id) { |
| 26 return service_id == GaiaConstants::kGaiaOAuth2LoginRefreshToken; | 29 return service_id == GaiaConstants::kGaiaOAuth2LoginRefreshToken; |
| 27 } | 30 } |
| 28 | 31 |
| 29 bool IsLegacyServiceId(const std::string& account_id) { | 32 bool IsLegacyServiceId(const std::string& account_id) { |
| 30 return account_id.compare(0u, kAccountIdPrefixLength, kAccountIdPrefix) != 0; | 33 return account_id.compare(0u, kAccountIdPrefixLength, kAccountIdPrefix) != 0; |
| 31 } | 34 } |
| 32 | 35 |
| 33 std::string RemoveAccountIdPrefix(const std::string& prefixed_account_id) { | 36 std::string RemoveAccountIdPrefix(const std::string& prefixed_account_id) { |
| 34 return prefixed_account_id.substr(kAccountIdPrefixLength); | 37 return prefixed_account_id.substr(kAccountIdPrefixLength); |
| 35 } | 38 } |
| 36 | 39 |
| 40 // This class sends a request to GAIA to revoke the given refresh token from | |
| 41 // the server. This is a best effort attempt only. This class deletes itself | |
| 42 // when done sucessfully or otherwise. | |
| 43 class RevokeServerRefreshToken : public GaiaAuthConsumer { | |
| 44 public: | |
| 45 RevokeServerRefreshToken(const std::string& account_id, | |
| 46 net::URLRequestContextGetter* request_context); | |
| 47 virtual ~RevokeServerRefreshToken(); | |
| 48 | |
| 49 private: | |
| 50 // GaiaAuthConsumer overrides: | |
| 51 virtual void OnOAuth2RevokeTokenCompleted() OVERRIDE; | |
| 52 | |
| 53 scoped_refptr<net::URLRequestContextGetter> request_context_; | |
| 54 scoped_ptr<GaiaAuthFetcher> fetcher_; | |
|
Roger Tawa OOO till Jul 10th
2013/12/19 13:43:58
While you're here, can you change this member from
msarda
2013/12/19 17:35:35
Done.
If GaiaAuthFetcher had used a ref counted p
| |
| 55 | |
| 56 DISALLOW_COPY_AND_ASSIGN(RevokeServerRefreshToken); | |
| 57 }; | |
| 58 | |
| 59 RevokeServerRefreshToken::RevokeServerRefreshToken( | |
| 60 const std::string& refresh_token, | |
| 61 net::URLRequestContextGetter* request_context) | |
| 62 : request_context_(request_context) { | |
| 63 fetcher_.reset( | |
| 64 new GaiaAuthFetcher(this, | |
| 65 GaiaConstants::kChromeSource, | |
| 66 request_context_.get())); | |
| 67 fetcher_->StartRevokeOAuth2Token(refresh_token); | |
| 68 } | |
| 69 | |
| 70 RevokeServerRefreshToken::~RevokeServerRefreshToken() {} | |
| 71 | |
| 72 void RevokeServerRefreshToken::OnOAuth2RevokeTokenCompleted() { | |
| 73 delete this; | |
| 74 } | |
| 75 | |
| 37 } // namespace | 76 } // namespace |
| 38 | 77 |
| 39 MutableProfileOAuth2TokenService::MutableProfileOAuth2TokenService() | 78 MutableProfileOAuth2TokenService::MutableProfileOAuth2TokenService() |
| 40 : web_data_service_request_(0) { | 79 : web_data_service_request_(0) { |
| 41 } | 80 } |
| 42 | 81 |
| 43 MutableProfileOAuth2TokenService::~MutableProfileOAuth2TokenService() { | 82 MutableProfileOAuth2TokenService::~MutableProfileOAuth2TokenService() { |
| 44 } | 83 } |
| 45 | 84 |
| 46 void MutableProfileOAuth2TokenService::Shutdown() { | 85 void MutableProfileOAuth2TokenService::Shutdown() { |
| 47 if (web_data_service_request_ != 0) { | 86 if (web_data_service_request_ != 0) { |
| 48 scoped_refptr<TokenWebData> token_web_data = | 87 scoped_refptr<TokenWebData> token_web_data = |
| 49 TokenWebData::FromBrowserContext(profile()); | 88 TokenWebData::FromBrowserContext(profile()); |
| 50 DCHECK(token_web_data.get()); | 89 DCHECK(token_web_data.get()); |
| 51 token_web_data->CancelRequest(web_data_service_request_); | 90 token_web_data->CancelRequest(web_data_service_request_); |
| 52 web_data_service_request_ = 0; | 91 web_data_service_request_ = 0; |
| 53 } | 92 } |
| 54 ProfileOAuth2TokenService::Shutdown(); | 93 ProfileOAuth2TokenService::Shutdown(); |
| 55 } | 94 } |
| 56 | 95 |
| 96 net::URLRequestContextGetter* | |
| 97 MutableProfileOAuth2TokenService::GetRequestContext() { | |
| 98 return profile()->GetRequestContext(); | |
| 99 } | |
| 100 | |
| 57 void MutableProfileOAuth2TokenService::LoadCredentials() { | 101 void MutableProfileOAuth2TokenService::LoadCredentials() { |
| 58 DCHECK_EQ(0, web_data_service_request_); | 102 DCHECK_EQ(0, web_data_service_request_); |
| 59 | 103 |
| 60 CancelAllRequests(); | 104 CancelAllRequests(); |
| 61 refresh_tokens().clear(); | 105 refresh_tokens().clear(); |
| 62 scoped_refptr<TokenWebData> token_web_data = | 106 scoped_refptr<TokenWebData> token_web_data = |
| 63 TokenWebData::FromBrowserContext(profile()); | 107 TokenWebData::FromBrowserContext(profile()); |
| 64 if (token_web_data.get()) | 108 if (token_web_data.get()) |
| 65 web_data_service_request_ = token_web_data->GetAllTokens(this); | 109 web_data_service_request_ = token_web_data->GetAllTokens(this); |
| 66 } | 110 } |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 161 MutableProfileOAuth2TokenService::GetAccountIdForMigratingRefreshToken() { | 205 MutableProfileOAuth2TokenService::GetAccountIdForMigratingRefreshToken() { |
| 162 #if defined(ENABLE_MANAGED_USERS) | 206 #if defined(ENABLE_MANAGED_USERS) |
| 163 // TODO(bauerb): Make sure that only services that can deal with supervised | 207 // TODO(bauerb): Make sure that only services that can deal with supervised |
| 164 // users see the supervised user token. | 208 // users see the supervised user token. |
| 165 if (profile()->IsManaged()) | 209 if (profile()->IsManaged()) |
| 166 return managed_users::kManagedUserPseudoEmail; | 210 return managed_users::kManagedUserPseudoEmail; |
| 167 #endif | 211 #endif |
| 168 | 212 |
| 169 return GetPrimaryAccountId(); | 213 return GetPrimaryAccountId(); |
| 170 } | 214 } |
| 215 | |
| 216 void MutableProfileOAuth2TokenService::RevokeCredentialsOnServer( | |
| 217 const std::string& refresh_token) { | |
| 218 // RevokeServerRefreshToken deletes itself when done. | |
| 219 new RevokeServerRefreshToken(refresh_token, GetRequestContext()); | |
| 220 } | |
| OLD | NEW |