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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 virtual ~Request(); | 62 virtual ~Request(); |
63 virtual std::string GetAccountId() const = 0; | 63 virtual std::string GetAccountId() const = 0; |
64 protected: | 64 protected: |
65 Request(); | 65 Request(); |
66 }; | 66 }; |
67 | 67 |
68 // Class representing the consumer of a Request passed to |StartRequest|, | 68 // Class representing the consumer of a Request passed to |StartRequest|, |
69 // which will be called back when the request completes. | 69 // which will be called back when the request completes. |
70 class Consumer { | 70 class Consumer { |
71 public: | 71 public: |
72 Consumer(const std::string& id); | 72 explicit Consumer(const std::string& id); |
73 virtual ~Consumer(); | 73 virtual ~Consumer(); |
74 | 74 |
75 std::string id() const { return id_; } | 75 std::string id() const { return id_; } |
76 | 76 |
77 // |request| is a Request that is started by this consumer and has | 77 // |request| is a Request that is started by this consumer and has |
78 // completed. | 78 // completed. |
79 virtual void OnGetTokenSuccess(const Request* request, | 79 virtual void OnGetTokenSuccess(const Request* request, |
80 const std::string& access_token, | 80 const std::string& access_token, |
81 const base::Time& expiration_time) = 0; | 81 const base::Time& expiration_time) = 0; |
82 virtual void OnGetTokenFailure(const Request* request, | 82 virtual void OnGetTokenFailure(const Request* request, |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 | 207 |
208 protected: | 208 protected: |
209 // Implements a cancelable |OAuth2TokenService::Request|, which should be | 209 // Implements a cancelable |OAuth2TokenService::Request|, which should be |
210 // operated on the UI thread. | 210 // operated on the UI thread. |
211 // TODO(davidroche): move this out of header file. | 211 // TODO(davidroche): move this out of header file. |
212 class RequestImpl : public base::SupportsWeakPtr<RequestImpl>, | 212 class RequestImpl : public base::SupportsWeakPtr<RequestImpl>, |
213 public base::NonThreadSafe, | 213 public base::NonThreadSafe, |
214 public Request { | 214 public Request { |
215 public: | 215 public: |
216 // |consumer| is required to outlive this. | 216 // |consumer| is required to outlive this. |
217 explicit RequestImpl(const std::string& account_id, Consumer* consumer); | 217 RequestImpl(const std::string& account_id, Consumer* consumer); |
218 ~RequestImpl() override; | 218 ~RequestImpl() override; |
219 | 219 |
220 // Overridden from Request: | 220 // Overridden from Request: |
221 std::string GetAccountId() const override; | 221 std::string GetAccountId() const override; |
222 | 222 |
223 std::string GetConsumerId() const; | 223 std::string GetConsumerId() const; |
224 | 224 |
225 // Informs |consumer_| that this request is completed. | 225 // Informs |consumer_| that this request is completed. |
226 void InformConsumer(const GoogleServiceAuthError& error, | 226 void InformConsumer(const GoogleServiceAuthError& error, |
227 const std::string& access_token, | 227 const std::string& access_token, |
228 const base::Time& expiration_date); | 228 const base::Time& expiration_date); |
229 | 229 |
230 private: | 230 private: |
231 // |consumer_| to call back when this request completes. | 231 // |consumer_| to call back when this request completes. |
232 const std::string account_id_; | 232 const std::string account_id_; |
233 Consumer* const consumer_; | 233 Consumer* const consumer_; |
234 }; | 234 }; |
235 | 235 |
236 // Helper class to scope batch changes. | 236 // Helper class to scope batch changes. |
237 class ScopedBacthChange { | 237 class ScopedBatchChange { |
238 public: | 238 public: |
239 ScopedBacthChange(OAuth2TokenService* token_service); | 239 explicit ScopedBatchChange(OAuth2TokenService* token_service); |
240 ~ScopedBacthChange(); | 240 ~ScopedBatchChange(); |
241 private: | 241 private: |
242 OAuth2TokenService* token_service_; // Weak. | 242 OAuth2TokenService* token_service_; // Weak. |
243 DISALLOW_COPY_AND_ASSIGN(ScopedBacthChange); | 243 DISALLOW_COPY_AND_ASSIGN(ScopedBatchChange); |
244 }; | 244 }; |
245 | 245 |
246 // Subclasses can override if they want to report errors to the user. | 246 // Subclasses can override if they want to report errors to the user. |
247 virtual void UpdateAuthError( | 247 virtual void UpdateAuthError( |
248 const std::string& account_id, | 248 const std::string& account_id, |
249 const GoogleServiceAuthError& error); | 249 const GoogleServiceAuthError& error); |
250 | 250 |
251 // Add a new entry to the cache. | 251 // Add a new entry to the cache. |
252 // Subclasses can override if there are implementation-specific reasons | 252 // Subclasses can override if there are implementation-specific reasons |
253 // that an access token should ever not be cached. | 253 // that an access token should ever not be cached. |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 static int max_fetch_retry_num_; | 398 static int max_fetch_retry_num_; |
399 | 399 |
400 FRIEND_TEST_ALL_PREFIXES(OAuth2TokenServiceTest, RequestParametersOrderTest); | 400 FRIEND_TEST_ALL_PREFIXES(OAuth2TokenServiceTest, RequestParametersOrderTest); |
401 FRIEND_TEST_ALL_PREFIXES(OAuth2TokenServiceTest, | 401 FRIEND_TEST_ALL_PREFIXES(OAuth2TokenServiceTest, |
402 SameScopesRequestedForDifferentClients); | 402 SameScopesRequestedForDifferentClients); |
403 | 403 |
404 DISALLOW_COPY_AND_ASSIGN(OAuth2TokenService); | 404 DISALLOW_COPY_AND_ASSIGN(OAuth2TokenService); |
405 }; | 405 }; |
406 | 406 |
407 #endif // GOOGLE_APIS_GAIA_OAUTH2_TOKEN_SERVICE_H_ | 407 #endif // GOOGLE_APIS_GAIA_OAUTH2_TOKEN_SERVICE_H_ |
OLD | NEW |