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" |
11 #include "chrome/browser/chrome_notification_types.h" | 11 #include "chrome/browser/chrome_notification_types.h" |
12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/browser/signin/signin_global_error.h" | 13 #include "chrome/browser/signin/signin_global_error.h" |
14 #include "chrome/browser/signin/signin_manager.h" | 14 #include "chrome/browser/signin/signin_manager.h" |
15 #include "chrome/browser/signin/signin_manager_factory.h" | 15 #include "chrome/browser/signin/signin_manager_factory.h" |
16 #include "chrome/browser/ui/global_error/global_error_service.h" | 16 #include "chrome/browser/ui/global_error/global_error_service.h" |
17 #include "chrome/browser/ui/global_error/global_error_service_factory.h" | 17 #include "chrome/browser/ui/global_error/global_error_service_factory.h" |
18 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
19 #include "content/public/browser/notification_details.h" | 19 #include "content/public/browser/notification_details.h" |
20 #include "content/public/browser/notification_source.h" | 20 #include "content/public/browser/notification_source.h" |
21 #include "google_apis/gaia/gaia_auth_fetcher.h" | 21 #include "google_apis/gaia/gaia_auth_fetcher.h" |
22 #include "google_apis/gaia/gaia_constants.h" | 22 #include "google_apis/gaia/gaia_constants.h" |
23 #include "google_apis/gaia/google_service_auth_error.h" | 23 #include "google_apis/gaia/google_service_auth_error.h" |
24 #include "net/url_request/url_request_context_getter.h" | 24 #include "net/url_request/url_request_context_getter.h" |
25 | 25 |
26 namespace { | |
27 | |
28 // This class sends a request to GAIA to revoke the given refresh token from | |
29 // the server. This is a best effort attempt only. This class deletes itself | |
30 // when done sucessfully or otherwise. | |
31 class RevokeServerRefreshToken : public GaiaAuthConsumer { | |
32 public: | |
33 RevokeServerRefreshToken(const std::string& account_id, | |
34 net::URLRequestContextGetter* request_context); | |
35 virtual ~RevokeServerRefreshToken(); | |
36 | |
37 private: | |
38 // GaiaAuthConsumer overrides: | |
39 virtual void OnOAuth2RevokeTokenCompleted() OVERRIDE; | |
40 | |
41 scoped_refptr<net::URLRequestContextGetter> request_context_; | |
42 scoped_ptr<GaiaAuthFetcher> fetcher_; | |
43 | |
44 DISALLOW_COPY_AND_ASSIGN(RevokeServerRefreshToken); | |
45 }; | |
46 | |
47 RevokeServerRefreshToken::RevokeServerRefreshToken( | |
48 const std::string& refresh_token, | |
49 net::URLRequestContextGetter* request_context) | |
50 : request_context_(request_context) { | |
51 fetcher_.reset( | |
52 new GaiaAuthFetcher(this, | |
53 GaiaConstants::kChromeSource, | |
54 request_context_.get())); | |
55 fetcher_->StartRevokeOAuth2Token(refresh_token); | |
56 } | |
57 | |
58 RevokeServerRefreshToken::~RevokeServerRefreshToken() {} | |
59 | |
60 void RevokeServerRefreshToken::OnOAuth2RevokeTokenCompleted() { | |
61 delete this; | |
62 } | |
63 | |
64 } // namespace | |
65 | |
66 | |
67 ProfileOAuth2TokenService::AccountInfo::AccountInfo( | 26 ProfileOAuth2TokenService::AccountInfo::AccountInfo( |
68 ProfileOAuth2TokenService* token_service, | 27 ProfileOAuth2TokenService* token_service, |
69 const std::string& account_id, | 28 const std::string& account_id, |
70 const std::string& refresh_token) | 29 const std::string& refresh_token) |
71 : token_service_(token_service), | 30 : token_service_(token_service), |
72 account_id_(account_id), | 31 account_id_(account_id), |
73 refresh_token_(refresh_token), | 32 refresh_token_(refresh_token), |
74 last_auth_error_(GoogleServiceAuthError::NONE) { | 33 last_auth_error_(GoogleServiceAuthError::NONE) { |
75 DCHECK(token_service_); | 34 DCHECK(token_service_); |
76 DCHECK(!account_id_.empty()); | 35 DCHECK(!account_id_.empty()); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 | 88 |
130 std::string ProfileOAuth2TokenService::GetRefreshToken( | 89 std::string ProfileOAuth2TokenService::GetRefreshToken( |
131 const std::string& account_id) { | 90 const std::string& account_id) { |
132 AccountInfoMap::const_iterator iter = refresh_tokens_.find(account_id); | 91 AccountInfoMap::const_iterator iter = refresh_tokens_.find(account_id); |
133 if (iter != refresh_tokens_.end()) | 92 if (iter != refresh_tokens_.end()) |
134 return iter->second->refresh_token(); | 93 return iter->second->refresh_token(); |
135 return std::string(); | 94 return std::string(); |
136 } | 95 } |
137 | 96 |
138 net::URLRequestContextGetter* ProfileOAuth2TokenService::GetRequestContext() { | 97 net::URLRequestContextGetter* ProfileOAuth2TokenService::GetRequestContext() { |
139 return profile_->GetRequestContext(); | 98 return NULL; |
140 } | 99 } |
141 | 100 |
142 void ProfileOAuth2TokenService::UpdateAuthError( | 101 void ProfileOAuth2TokenService::UpdateAuthError( |
143 const std::string& account_id, | 102 const std::string& account_id, |
144 const GoogleServiceAuthError& error) { | 103 const GoogleServiceAuthError& error) { |
145 // Do not report connection errors as these are not actually auth errors. | 104 // Do not report connection errors as these are not actually auth errors. |
146 // We also want to avoid masking a "real" auth error just because we | 105 // We also want to avoid masking a "real" auth error just because we |
147 // subsequently get a transient network error. | 106 // subsequently get a transient network error. |
148 if (error.state() == GoogleServiceAuthError::CONNECTION_FAILED || | 107 if (error.state() == GoogleServiceAuthError::CONNECTION_FAILED || |
149 error.state() == GoogleServiceAuthError::SERVICE_UNAVAILABLE) | 108 error.state() == GoogleServiceAuthError::SERVICE_UNAVAILABLE) |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 | 213 |
255 // TODO(fgorski): Notify diagnostic observers. | 214 // TODO(fgorski): Notify diagnostic observers. |
256 } | 215 } |
257 | 216 |
258 void ProfileOAuth2TokenService::LoadCredentials() { | 217 void ProfileOAuth2TokenService::LoadCredentials() { |
259 // Empty implementation by default. | 218 // Empty implementation by default. |
260 } | 219 } |
261 | 220 |
262 void ProfileOAuth2TokenService::RevokeCredentialsOnServer( | 221 void ProfileOAuth2TokenService::RevokeCredentialsOnServer( |
263 const std::string& refresh_token) { | 222 const std::string& refresh_token) { |
264 // RevokeServerRefreshToken deletes itself when done. | 223 // Empty implementation by default. |
265 new RevokeServerRefreshToken(refresh_token, GetRequestContext()); | |
266 } | 224 } |
OLD | NEW |