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

Side by Side Diff: google_apis/gaia/oauth2_token_service.h

Issue 2910983003: Replace deprecated base::NonThreadSafe in google_apis/gaia in favor of SequenceChecker. (Closed)
Patch Set: Created 3 years, 6 months 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
« no previous file with comments | « no previous file | google_apis/gaia/oauth2_token_service.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #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 <memory>
12 #include <set> 12 #include <set>
13 #include <string> 13 #include <string>
14 14
15 #include "base/gtest_prod_util.h" 15 #include "base/gtest_prod_util.h"
16 #include "base/macros.h" 16 #include "base/macros.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/sequence_checker.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;
27 } 27 }
28 28
29 class GoogleServiceAuthError; 29 class GoogleServiceAuthError;
(...skipping 16 matching lines...) Expand all
46 // never be called back. 46 // never be called back.
47 // Note in this case, the actual network requests are not canceled and the 47 // Note in this case, the actual network requests are not canceled and the
48 // cache will be populated with the fetched results; it is just the consumer 48 // cache will be populated with the fetched results; it is just the consumer
49 // callback that is aborted. 49 // callback that is aborted.
50 // 50 //
51 // - Otherwise the consumer will be called back with the request and the fetch 51 // - Otherwise the consumer will be called back with the request and the fetch
52 // results. 52 // results.
53 // 53 //
54 // The caller of StartRequest() owns the returned request and is responsible to 54 // The caller of StartRequest() owns the returned request and is responsible to
55 // delete the request even once the callback has been invoked. 55 // delete the request even once the callback has been invoked.
56 class OAuth2TokenService : public base::NonThreadSafe { 56 class OAuth2TokenService {
57 public: 57 public:
58 // A set of scopes in OAuth2 authentication. 58 // A set of scopes in OAuth2 authentication.
59 typedef std::set<std::string> ScopeSet; 59 typedef std::set<std::string> ScopeSet;
60 60
61 // Class representing a request that fetches an OAuth2 access token. 61 // Class representing a request that fetches an OAuth2 access token.
62 class Request { 62 class Request {
63 public: 63 public:
64 virtual ~Request(); 64 virtual ~Request();
65 virtual std::string GetAccountId() const = 0; 65 virtual std::string GetAccountId() const = 0;
66 protected: 66 protected:
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 const ScopeSet& scopes) const; 214 const ScopeSet& scopes) const;
215 215
216 OAuth2TokenServiceDelegate* GetDelegate(); 216 OAuth2TokenServiceDelegate* GetDelegate();
217 const OAuth2TokenServiceDelegate* GetDelegate() const; 217 const OAuth2TokenServiceDelegate* GetDelegate() const;
218 218
219 protected: 219 protected:
220 // Implements a cancelable |OAuth2TokenService::Request|, which should be 220 // Implements a cancelable |OAuth2TokenService::Request|, which should be
221 // operated on the UI thread. 221 // operated on the UI thread.
222 // TODO(davidroche): move this out of header file. 222 // TODO(davidroche): move this out of header file.
223 class RequestImpl : public base::SupportsWeakPtr<RequestImpl>, 223 class RequestImpl : public base::SupportsWeakPtr<RequestImpl>,
224 public base::NonThreadSafe,
225 public Request { 224 public Request {
226 public: 225 public:
227 // |consumer| is required to outlive this. 226 // |consumer| is required to outlive this.
228 RequestImpl(const std::string& account_id, Consumer* consumer); 227 RequestImpl(const std::string& account_id, Consumer* consumer);
229 ~RequestImpl() override; 228 ~RequestImpl() override;
230 229
231 // Overridden from Request: 230 // Overridden from Request:
232 std::string GetAccountId() const override; 231 std::string GetAccountId() const override;
233 232
234 std::string GetConsumerId() const; 233 std::string GetConsumerId() const;
235 234
236 // Informs |consumer_| that this request is completed. 235 // Informs |consumer_| that this request is completed.
237 void InformConsumer(const GoogleServiceAuthError& error, 236 void InformConsumer(const GoogleServiceAuthError& error,
238 const std::string& access_token, 237 const std::string& access_token,
239 const base::Time& expiration_date); 238 const base::Time& expiration_date);
240 239
241 private: 240 private:
242 // |consumer_| to call back when this request completes. 241 // |consumer_| to call back when this request completes.
243 const std::string account_id_; 242 const std::string account_id_;
244 Consumer* const consumer_; 243 Consumer* const consumer_;
244
245 SEQUENCE_CHECKER(sequence_checker_);
245 }; 246 };
246 247
247 // Implement it in delegates if they want to report errors to the user. 248 // Implement it in delegates if they want to report errors to the user.
248 void UpdateAuthError(const std::string& account_id, 249 void UpdateAuthError(const std::string& account_id,
249 const GoogleServiceAuthError& error); 250 const GoogleServiceAuthError& error);
250 251
251 // Add a new entry to the cache. 252 // Add a new entry to the cache.
252 // Subclasses can override if there are implementation-specific reasons 253 // Subclasses can override if there are implementation-specific reasons
253 // that an access token should ever not be cached. 254 // that an access token should ever not be cached.
254 virtual void RegisterCacheEntry(const std::string& client_id, 255 virtual void RegisterCacheEntry(const std::string& client_id,
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 int batch_change_depth_; 382 int batch_change_depth_;
382 383
383 // Maximum number of retries in fetching an OAuth2 access token. 384 // Maximum number of retries in fetching an OAuth2 access token.
384 static int max_fetch_retry_num_; 385 static int max_fetch_retry_num_;
385 386
386 FRIEND_TEST_ALL_PREFIXES(OAuth2TokenServiceTest, RequestParametersOrderTest); 387 FRIEND_TEST_ALL_PREFIXES(OAuth2TokenServiceTest, RequestParametersOrderTest);
387 FRIEND_TEST_ALL_PREFIXES(OAuth2TokenServiceTest, 388 FRIEND_TEST_ALL_PREFIXES(OAuth2TokenServiceTest,
388 SameScopesRequestedForDifferentClients); 389 SameScopesRequestedForDifferentClients);
389 FRIEND_TEST_ALL_PREFIXES(OAuth2TokenServiceTest, UpdateClearsCache); 390 FRIEND_TEST_ALL_PREFIXES(OAuth2TokenServiceTest, UpdateClearsCache);
390 391
392 SEQUENCE_CHECKER(sequence_checker_);
393
391 DISALLOW_COPY_AND_ASSIGN(OAuth2TokenService); 394 DISALLOW_COPY_AND_ASSIGN(OAuth2TokenService);
392 }; 395 };
393 396
394 #endif // GOOGLE_APIS_GAIA_OAUTH2_TOKEN_SERVICE_H_ 397 #endif // GOOGLE_APIS_GAIA_OAUTH2_TOKEN_SERVICE_H_
OLDNEW
« no previous file with comments | « no previous file | google_apis/gaia/oauth2_token_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698