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 #ifndef GOOGLE_APIS_GAIA_OAUTH2_TOKEN_SERVICE_H_ | 5 #ifndef GOOGLE_APIS_GAIA_OAUTH2_TOKEN_SERVICE_H_ |
6 #define GOOGLE_APIS_GAIA_OAUTH2_TOKEN_SERVICE_H_ | 6 #define GOOGLE_APIS_GAIA_OAUTH2_TOKEN_SERVICE_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
49 // results. | 49 // results. |
50 // | 50 // |
51 // The caller of StartRequest() owns the returned request and is responsible to | 51 // The caller of StartRequest() owns the returned request and is responsible to |
52 // delete the request even once the callback has been invoked. | 52 // delete the request even once the callback has been invoked. |
53 class OAuth2TokenService : public base::NonThreadSafe { | 53 class OAuth2TokenService : public base::NonThreadSafe { |
54 public: | 54 public: |
55 // Class representing a request that fetches an OAuth2 access token. | 55 // Class representing a request that fetches an OAuth2 access token. |
56 class Request { | 56 class Request { |
57 public: | 57 public: |
58 virtual ~Request(); | 58 virtual ~Request(); |
59 virtual std::string GetAccountId() const = 0; | |
Andrew T Wilson (Slow)
2013/11/05 09:28:48
Why is this necessary? Nobody calls this, and it s
| |
59 protected: | 60 protected: |
60 Request(); | 61 Request(); |
61 }; | 62 }; |
62 | 63 |
63 // Class representing the consumer of a Request passed to |StartRequest|, | 64 // Class representing the consumer of a Request passed to |StartRequest|, |
64 // which will be called back when the request completes. | 65 // which will be called back when the request completes. |
65 class Consumer { | 66 class Consumer { |
66 public: | 67 public: |
67 Consumer(); | 68 Consumer(); |
68 virtual ~Consumer(); | 69 virtual ~Consumer(); |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
170 | 171 |
171 protected: | 172 protected: |
172 // Implements a cancelable |OAuth2TokenService::Request|, which should be | 173 // Implements a cancelable |OAuth2TokenService::Request|, which should be |
173 // operated on the UI thread. | 174 // operated on the UI thread. |
174 // TODO(davidroche): move this out of header file. | 175 // TODO(davidroche): move this out of header file. |
175 class RequestImpl : public base::SupportsWeakPtr<RequestImpl>, | 176 class RequestImpl : public base::SupportsWeakPtr<RequestImpl>, |
176 public base::NonThreadSafe, | 177 public base::NonThreadSafe, |
177 public Request { | 178 public Request { |
178 public: | 179 public: |
179 // |consumer| is required to outlive this. | 180 // |consumer| is required to outlive this. |
180 explicit RequestImpl(Consumer* consumer); | 181 explicit RequestImpl(const std::string& account_id, Consumer* consumer); |
181 virtual ~RequestImpl(); | 182 virtual ~RequestImpl(); |
182 | 183 |
184 // Overridden from Request: | |
185 virtual std::string GetAccountId() const OVERRIDE; | |
186 | |
183 // Informs |consumer_| that this request is completed. | 187 // Informs |consumer_| that this request is completed. |
184 void InformConsumer(const GoogleServiceAuthError& error, | 188 void InformConsumer(const GoogleServiceAuthError& error, |
185 const std::string& access_token, | 189 const std::string& access_token, |
186 const base::Time& expiration_date); | 190 const base::Time& expiration_date); |
187 | 191 |
188 private: | 192 private: |
189 // |consumer_| to call back when this request completes. | 193 // |consumer_| to call back when this request completes. |
194 const std::string account_id_; | |
190 Consumer* const consumer_; | 195 Consumer* const consumer_; |
191 }; | 196 }; |
192 | 197 |
193 // Subclasses should return the maintained refresh token for |account_id|. | 198 // Subclasses should return the maintained refresh token for |account_id|. |
194 // If no token is available, return an empty string. | 199 // If no token is available, return an empty string. |
195 virtual std::string GetRefreshToken(const std::string& account_id) = 0; | 200 virtual std::string GetRefreshToken(const std::string& account_id) = 0; |
196 | 201 |
197 // Subclasses can override if they want to report errors to the user. | 202 // Subclasses can override if they want to report errors to the user. |
198 virtual void UpdateAuthError( | 203 virtual void UpdateAuthError( |
199 const std::string& account_id, | 204 const std::string& account_id, |
(...skipping 23 matching lines...) Expand all Loading... | |
223 void CancelRequestsForAccount(const std::string& account_id); | 228 void CancelRequestsForAccount(const std::string& account_id); |
224 | 229 |
225 // Called by subclasses to notify observers. | 230 // Called by subclasses to notify observers. |
226 virtual void FireRefreshTokenAvailable(const std::string& account_id); | 231 virtual void FireRefreshTokenAvailable(const std::string& account_id); |
227 virtual void FireRefreshTokenRevoked(const std::string& account_id); | 232 virtual void FireRefreshTokenRevoked(const std::string& account_id); |
228 virtual void FireRefreshTokensLoaded(); | 233 virtual void FireRefreshTokensLoaded(); |
229 | 234 |
230 // Creates a request implementation. Can be overriden by derived classes to | 235 // Creates a request implementation. Can be overriden by derived classes to |
231 // provide additional control of token consumption. |consumer| will outlive | 236 // provide additional control of token consumption. |consumer| will outlive |
232 // the created request. | 237 // the created request. |
233 virtual scoped_ptr<RequestImpl> CreateRequest(Consumer* consumer); | 238 virtual scoped_ptr<RequestImpl> CreateRequest( |
239 const std::string& account_id, | |
240 Consumer* consumer); | |
234 | 241 |
235 // Fetches an OAuth token for the specified client/scopes. Virtual so it can | 242 // Fetches an OAuth token for the specified client/scopes. Virtual so it can |
236 // be overridden for tests and for platform-specific behavior on Android. | 243 // be overridden for tests and for platform-specific behavior on Android. |
237 virtual void FetchOAuth2Token(RequestImpl* request, | 244 virtual void FetchOAuth2Token(RequestImpl* request, |
238 const std::string& account_id, | 245 const std::string& account_id, |
239 net::URLRequestContextGetter* getter, | 246 net::URLRequestContextGetter* getter, |
240 const std::string& client_id, | 247 const std::string& client_id, |
241 const std::string& client_secret, | 248 const std::string& client_secret, |
242 const ScopeSet& scopes); | 249 const ScopeSet& scopes); |
243 | 250 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
335 static int max_fetch_retry_num_; | 342 static int max_fetch_retry_num_; |
336 | 343 |
337 FRIEND_TEST_ALL_PREFIXES(OAuth2TokenServiceTest, RequestParametersOrderTest); | 344 FRIEND_TEST_ALL_PREFIXES(OAuth2TokenServiceTest, RequestParametersOrderTest); |
338 FRIEND_TEST_ALL_PREFIXES(OAuth2TokenServiceTest, | 345 FRIEND_TEST_ALL_PREFIXES(OAuth2TokenServiceTest, |
339 SameScopesRequestedForDifferentClients); | 346 SameScopesRequestedForDifferentClients); |
340 | 347 |
341 DISALLOW_COPY_AND_ASSIGN(OAuth2TokenService); | 348 DISALLOW_COPY_AND_ASSIGN(OAuth2TokenService); |
342 }; | 349 }; |
343 | 350 |
344 #endif // GOOGLE_APIS_GAIA_OAUTH2_TOKEN_SERVICE_H_ | 351 #endif // GOOGLE_APIS_GAIA_OAUTH2_TOKEN_SERVICE_H_ |
OLD | NEW |