Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(113)

Side by Side Diff: chrome/browser/signin/mutable_profile_oauth2_token_service.cc

Issue 101633009: Move RevokeCredentialsOnServer to MutableProfileOAuth2TokenService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address code review. Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 GaiaAuthFetcher fetcher_;
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_(this, GaiaConstants::kChromeSource, request_context) {
64 fetcher_.StartRevokeOAuth2Token(refresh_token);
65 }
66
67 RevokeServerRefreshToken::~RevokeServerRefreshToken() {}
68
69 void RevokeServerRefreshToken::OnOAuth2RevokeTokenCompleted() {
70 delete this;
71 }
72
37 } // namespace 73 } // namespace
38 74
39 MutableProfileOAuth2TokenService::MutableProfileOAuth2TokenService() 75 MutableProfileOAuth2TokenService::MutableProfileOAuth2TokenService()
40 : web_data_service_request_(0) { 76 : web_data_service_request_(0) {
41 } 77 }
42 78
43 MutableProfileOAuth2TokenService::~MutableProfileOAuth2TokenService() { 79 MutableProfileOAuth2TokenService::~MutableProfileOAuth2TokenService() {
44 } 80 }
45 81
46 void MutableProfileOAuth2TokenService::Shutdown() { 82 void MutableProfileOAuth2TokenService::Shutdown() {
47 if (web_data_service_request_ != 0) { 83 if (web_data_service_request_ != 0) {
48 scoped_refptr<TokenWebData> token_web_data = 84 scoped_refptr<TokenWebData> token_web_data =
49 TokenWebData::FromBrowserContext(profile()); 85 TokenWebData::FromBrowserContext(profile());
50 DCHECK(token_web_data.get()); 86 DCHECK(token_web_data.get());
51 token_web_data->CancelRequest(web_data_service_request_); 87 token_web_data->CancelRequest(web_data_service_request_);
52 web_data_service_request_ = 0; 88 web_data_service_request_ = 0;
53 } 89 }
54 ProfileOAuth2TokenService::Shutdown(); 90 ProfileOAuth2TokenService::Shutdown();
55 } 91 }
56 92
93 net::URLRequestContextGetter*
94 MutableProfileOAuth2TokenService::GetRequestContext() {
95 return profile()->GetRequestContext();
96 }
97
57 void MutableProfileOAuth2TokenService::LoadCredentials() { 98 void MutableProfileOAuth2TokenService::LoadCredentials() {
58 DCHECK_EQ(0, web_data_service_request_); 99 DCHECK_EQ(0, web_data_service_request_);
59 100
60 CancelAllRequests(); 101 CancelAllRequests();
61 refresh_tokens().clear(); 102 refresh_tokens().clear();
62 scoped_refptr<TokenWebData> token_web_data = 103 scoped_refptr<TokenWebData> token_web_data =
63 TokenWebData::FromBrowserContext(profile()); 104 TokenWebData::FromBrowserContext(profile());
64 if (token_web_data.get()) 105 if (token_web_data.get())
65 web_data_service_request_ = token_web_data->GetAllTokens(this); 106 web_data_service_request_ = token_web_data->GetAllTokens(this);
66 } 107 }
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 MutableProfileOAuth2TokenService::GetAccountIdForMigratingRefreshToken() { 202 MutableProfileOAuth2TokenService::GetAccountIdForMigratingRefreshToken() {
162 #if defined(ENABLE_MANAGED_USERS) 203 #if defined(ENABLE_MANAGED_USERS)
163 // TODO(bauerb): Make sure that only services that can deal with supervised 204 // TODO(bauerb): Make sure that only services that can deal with supervised
164 // users see the supervised user token. 205 // users see the supervised user token.
165 if (profile()->IsManaged()) 206 if (profile()->IsManaged())
166 return managed_users::kManagedUserPseudoEmail; 207 return managed_users::kManagedUserPseudoEmail;
167 #endif 208 #endif
168 209
169 return GetPrimaryAccountId(); 210 return GetPrimaryAccountId();
170 } 211 }
212
213 void MutableProfileOAuth2TokenService::RevokeCredentialsOnServer(
214 const std::string& refresh_token) {
215 // RevokeServerRefreshToken deletes itself when done.
216 new RevokeServerRefreshToken(refresh_token, GetRequestContext());
217 }
OLDNEW
« no previous file with comments | « chrome/browser/signin/mutable_profile_oauth2_token_service.h ('k') | chrome/browser/signin/profile_oauth2_token_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698