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 <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
| 11 #include <memory> |
11 #include <set> | 12 #include <set> |
12 #include <string> | 13 #include <string> |
13 | 14 |
14 #include "base/gtest_prod_util.h" | 15 #include "base/gtest_prod_util.h" |
15 #include "base/macros.h" | 16 #include "base/macros.h" |
16 #include "base/memory/scoped_ptr.h" | |
17 #include "base/memory/weak_ptr.h" | 17 #include "base/memory/weak_ptr.h" |
18 #include "base/observer_list.h" | 18 #include "base/observer_list.h" |
19 #include "base/threading/non_thread_safe.h" | 19 #include "base/threading/non_thread_safe.h" |
20 #include "base/time/time.h" | 20 #include "base/time/time.h" |
21 #include "google_apis/gaia/google_service_auth_error.h" | 21 #include "google_apis/gaia/google_service_auth_error.h" |
22 #include "google_apis/gaia/oauth2_access_token_consumer.h" | 22 #include "google_apis/gaia/oauth2_access_token_consumer.h" |
23 #include "google_apis/gaia/oauth2_access_token_fetcher.h" | 23 #include "google_apis/gaia/oauth2_access_token_fetcher.h" |
24 | 24 |
25 namespace net { | 25 namespace net { |
26 class URLRequestContextGetter; | 26 class URLRequestContextGetter; |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 void AddDiagnosticsObserver(DiagnosticsObserver* observer); | 143 void AddDiagnosticsObserver(DiagnosticsObserver* observer); |
144 void RemoveDiagnosticsObserver(DiagnosticsObserver* observer); | 144 void RemoveDiagnosticsObserver(DiagnosticsObserver* observer); |
145 | 145 |
146 // Checks in the cache for a valid access token for a specified |account_id| | 146 // Checks in the cache for a valid access token for a specified |account_id| |
147 // and |scopes|, and if not found starts a request for an OAuth2 access token | 147 // and |scopes|, and if not found starts a request for an OAuth2 access token |
148 // using the OAuth2 refresh token maintained by this instance for that | 148 // using the OAuth2 refresh token maintained by this instance for that |
149 // |account_id|. The caller owns the returned Request. | 149 // |account_id|. The caller owns the returned Request. |
150 // |scopes| is the set of scopes to get an access token for, |consumer| is | 150 // |scopes| is the set of scopes to get an access token for, |consumer| is |
151 // the object that will be called back with results if the returned request | 151 // the object that will be called back with results if the returned request |
152 // is not deleted. Virtual for mocking. | 152 // is not deleted. Virtual for mocking. |
153 virtual scoped_ptr<Request> StartRequest(const std::string& account_id, | 153 virtual std::unique_ptr<Request> StartRequest(const std::string& account_id, |
154 const ScopeSet& scopes, | 154 const ScopeSet& scopes, |
155 Consumer* consumer); | 155 Consumer* consumer); |
156 | 156 |
157 // This method does the same as |StartRequest| except it uses |client_id| and | 157 // This method does the same as |StartRequest| except it uses |client_id| and |
158 // |client_secret| to identify OAuth client app instead of using | 158 // |client_secret| to identify OAuth client app instead of using |
159 // Chrome's default values. | 159 // Chrome's default values. |
160 scoped_ptr<Request> StartRequestForClient( | 160 std::unique_ptr<Request> StartRequestForClient( |
161 const std::string& account_id, | 161 const std::string& account_id, |
162 const std::string& client_id, | 162 const std::string& client_id, |
163 const std::string& client_secret, | 163 const std::string& client_secret, |
164 const ScopeSet& scopes, | 164 const ScopeSet& scopes, |
165 Consumer* consumer); | 165 Consumer* consumer); |
166 | 166 |
167 // This method does the same as |StartRequest| except it uses the request | 167 // This method does the same as |StartRequest| except it uses the request |
168 // context given by |getter| instead of using the one returned by | 168 // context given by |getter| instead of using the one returned by |
169 // |GetRequestContext| implemented by derived classes. | 169 // |GetRequestContext| implemented by derived classes. |
170 scoped_ptr<Request> StartRequestWithContext( | 170 std::unique_ptr<Request> StartRequestWithContext( |
171 const std::string& account_id, | 171 const std::string& account_id, |
172 net::URLRequestContextGetter* getter, | 172 net::URLRequestContextGetter* getter, |
173 const ScopeSet& scopes, | 173 const ScopeSet& scopes, |
174 Consumer* consumer); | 174 Consumer* consumer); |
175 | 175 |
176 // Lists account IDs of all accounts with a refresh token maintained by this | 176 // Lists account IDs of all accounts with a refresh token maintained by this |
177 // instance. | 177 // instance. |
178 std::vector<std::string> GetAccounts() const; | 178 std::vector<std::string> GetAccounts() const; |
179 | 179 |
180 // Returns true if a refresh token exists for |account_id|. If false, calls to | 180 // Returns true if a refresh token exists for |account_id|. If false, calls to |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 | 318 |
319 // Struct that contains the information of an OAuth2 access token. | 319 // Struct that contains the information of an OAuth2 access token. |
320 struct CacheEntry { | 320 struct CacheEntry { |
321 std::string access_token; | 321 std::string access_token; |
322 base::Time expiration_date; | 322 base::Time expiration_date; |
323 }; | 323 }; |
324 | 324 |
325 // This method does the same as |StartRequestWithContext| except it | 325 // This method does the same as |StartRequestWithContext| except it |
326 // uses |client_id| and |client_secret| to identify OAuth | 326 // uses |client_id| and |client_secret| to identify OAuth |
327 // client app instead of using Chrome's default values. | 327 // client app instead of using Chrome's default values. |
328 scoped_ptr<Request> StartRequestForClientWithContext( | 328 std::unique_ptr<Request> StartRequestForClientWithContext( |
329 const std::string& account_id, | 329 const std::string& account_id, |
330 net::URLRequestContextGetter* getter, | 330 net::URLRequestContextGetter* getter, |
331 const std::string& client_id, | 331 const std::string& client_id, |
332 const std::string& client_secret, | 332 const std::string& client_secret, |
333 const ScopeSet& scopes, | 333 const ScopeSet& scopes, |
334 Consumer* consumer); | 334 Consumer* consumer); |
335 | 335 |
336 // Returns true if GetCacheEntry would return a valid cache entry for the | 336 // Returns true if GetCacheEntry would return a valid cache entry for the |
337 // given scopes. | 337 // given scopes. |
338 bool HasCacheEntry(const RequestParameters& client_scopes); | 338 bool HasCacheEntry(const RequestParameters& client_scopes); |
(...skipping 18 matching lines...) Expand all Loading... |
357 // Called when |fetcher| finishes fetching. | 357 // Called when |fetcher| finishes fetching. |
358 void OnFetchComplete(Fetcher* fetcher); | 358 void OnFetchComplete(Fetcher* fetcher); |
359 | 359 |
360 // Called when a number of fetchers need to be canceled. | 360 // Called when a number of fetchers need to be canceled. |
361 void CancelFetchers(std::vector<Fetcher*> fetchers_to_cancel); | 361 void CancelFetchers(std::vector<Fetcher*> fetchers_to_cancel); |
362 | 362 |
363 // The cache of currently valid tokens. | 363 // The cache of currently valid tokens. |
364 typedef std::map<RequestParameters, CacheEntry> TokenCache; | 364 typedef std::map<RequestParameters, CacheEntry> TokenCache; |
365 TokenCache token_cache_; | 365 TokenCache token_cache_; |
366 | 366 |
367 scoped_ptr<OAuth2TokenServiceDelegate> delegate_; | 367 std::unique_ptr<OAuth2TokenServiceDelegate> delegate_; |
368 | 368 |
369 // A map from fetch parameters to a fetcher that is fetching an OAuth2 access | 369 // A map from fetch parameters to a fetcher that is fetching an OAuth2 access |
370 // token using these parameters. | 370 // token using these parameters. |
371 PendingFetcherMap pending_fetchers_; | 371 PendingFetcherMap pending_fetchers_; |
372 | 372 |
373 // List of observers to notify when access token status changes. | 373 // List of observers to notify when access token status changes. |
374 base::ObserverList<DiagnosticsObserver, true> diagnostics_observer_list_; | 374 base::ObserverList<DiagnosticsObserver, true> diagnostics_observer_list_; |
375 | 375 |
376 // The depth of batch changes. | 376 // The depth of batch changes. |
377 int batch_change_depth_; | 377 int batch_change_depth_; |
378 | 378 |
379 // Maximum number of retries in fetching an OAuth2 access token. | 379 // Maximum number of retries in fetching an OAuth2 access token. |
380 static int max_fetch_retry_num_; | 380 static int max_fetch_retry_num_; |
381 | 381 |
382 FRIEND_TEST_ALL_PREFIXES(OAuth2TokenServiceTest, RequestParametersOrderTest); | 382 FRIEND_TEST_ALL_PREFIXES(OAuth2TokenServiceTest, RequestParametersOrderTest); |
383 FRIEND_TEST_ALL_PREFIXES(OAuth2TokenServiceTest, | 383 FRIEND_TEST_ALL_PREFIXES(OAuth2TokenServiceTest, |
384 SameScopesRequestedForDifferentClients); | 384 SameScopesRequestedForDifferentClients); |
385 FRIEND_TEST_ALL_PREFIXES(OAuth2TokenServiceTest, UpdateClearsCache); | 385 FRIEND_TEST_ALL_PREFIXES(OAuth2TokenServiceTest, UpdateClearsCache); |
386 | 386 |
387 DISALLOW_COPY_AND_ASSIGN(OAuth2TokenService); | 387 DISALLOW_COPY_AND_ASSIGN(OAuth2TokenService); |
388 }; | 388 }; |
389 | 389 |
390 #endif // GOOGLE_APIS_GAIA_OAUTH2_TOKEN_SERVICE_H_ | 390 #endif // GOOGLE_APIS_GAIA_OAUTH2_TOKEN_SERVICE_H_ |
OLD | NEW |