| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_FAKE_OAUTH2_TOKEN_SERVICE_H_ | 5 #ifndef GOOGLE_APIS_GAIA_FAKE_OAUTH2_TOKEN_SERVICE_H_ |
| 6 #define GOOGLE_APIS_GAIA_FAKE_OAUTH2_TOKEN_SERVICE_H_ | 6 #define GOOGLE_APIS_GAIA_FAKE_OAUTH2_TOKEN_SERVICE_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "google_apis/gaia/oauth2_token_service.h" | 13 #include "google_apis/gaia/oauth2_token_service.h" |
| 14 | 14 |
| 15 namespace net { | 15 namespace net { |
| 16 class URLRequestContextGetter; | 16 class URLRequestContextGetter; |
| 17 } | 17 } |
| 18 | 18 |
| 19 // Do-nothing implementation of OAuth2TokenService. | 19 // Do-nothing implementation of OAuth2TokenService. |
| 20 class FakeOAuth2TokenService : public OAuth2TokenService { | 20 class FakeOAuth2TokenService : public OAuth2TokenService { |
| 21 public: | 21 public: |
| 22 FakeOAuth2TokenService(); | 22 FakeOAuth2TokenService(); |
| 23 virtual ~FakeOAuth2TokenService(); | 23 virtual ~FakeOAuth2TokenService(); |
| 24 | 24 |
| 25 virtual std::vector<std::string> GetAccounts() OVERRIDE; | 25 virtual std::vector<std::string> GetAccounts() override; |
| 26 | 26 |
| 27 void AddAccount(const std::string& account_id); | 27 void AddAccount(const std::string& account_id); |
| 28 void RemoveAccount(const std::string& account_id); | 28 void RemoveAccount(const std::string& account_id); |
| 29 | 29 |
| 30 // Helper routines to issue tokens for pending requests or complete them with | 30 // Helper routines to issue tokens for pending requests or complete them with |
| 31 // error. | 31 // error. |
| 32 void IssueAllTokensForAccount(const std::string& account_id, | 32 void IssueAllTokensForAccount(const std::string& account_id, |
| 33 const std::string& access_token, | 33 const std::string& access_token, |
| 34 const base::Time& expiration); | 34 const base::Time& expiration); |
| 35 void IssueErrorForAllPendingRequestsForAccount( | 35 void IssueErrorForAllPendingRequestsForAccount( |
| 36 const std::string& account_id, | 36 const std::string& account_id, |
| 37 const GoogleServiceAuthError& auth_error); | 37 const GoogleServiceAuthError& auth_error); |
| 38 | 38 |
| 39 void set_request_context(net::URLRequestContextGetter* request_context) { | 39 void set_request_context(net::URLRequestContextGetter* request_context) { |
| 40 request_context_ = request_context; | 40 request_context_ = request_context; |
| 41 } | 41 } |
| 42 | 42 |
| 43 protected: | 43 protected: |
| 44 // OAuth2TokenService overrides. | 44 // OAuth2TokenService overrides. |
| 45 virtual void FetchOAuth2Token(RequestImpl* request, | 45 virtual void FetchOAuth2Token(RequestImpl* request, |
| 46 const std::string& account_id, | 46 const std::string& account_id, |
| 47 net::URLRequestContextGetter* getter, | 47 net::URLRequestContextGetter* getter, |
| 48 const std::string& client_id, | 48 const std::string& client_id, |
| 49 const std::string& client_secret, | 49 const std::string& client_secret, |
| 50 const ScopeSet& scopes) OVERRIDE; | 50 const ScopeSet& scopes) override; |
| 51 | 51 |
| 52 virtual void InvalidateOAuth2Token(const std::string& account_id, | 52 virtual void InvalidateOAuth2Token(const std::string& account_id, |
| 53 const std::string& client_id, | 53 const std::string& client_id, |
| 54 const ScopeSet& scopes, | 54 const ScopeSet& scopes, |
| 55 const std::string& access_token) OVERRIDE; | 55 const std::string& access_token) override; |
| 56 | 56 |
| 57 virtual bool RefreshTokenIsAvailable(const std::string& account_id) const | 57 virtual bool RefreshTokenIsAvailable(const std::string& account_id) const |
| 58 OVERRIDE; | 58 override; |
| 59 | 59 |
| 60 private: | 60 private: |
| 61 struct PendingRequest { | 61 struct PendingRequest { |
| 62 PendingRequest(); | 62 PendingRequest(); |
| 63 ~PendingRequest(); | 63 ~PendingRequest(); |
| 64 | 64 |
| 65 std::string account_id; | 65 std::string account_id; |
| 66 std::string client_id; | 66 std::string client_id; |
| 67 std::string client_secret; | 67 std::string client_secret; |
| 68 ScopeSet scopes; | 68 ScopeSet scopes; |
| 69 base::WeakPtr<RequestImpl> request; | 69 base::WeakPtr<RequestImpl> request; |
| 70 }; | 70 }; |
| 71 | 71 |
| 72 // OAuth2TokenService overrides. | 72 // OAuth2TokenService overrides. |
| 73 virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE; | 73 virtual net::URLRequestContextGetter* GetRequestContext() override; |
| 74 | 74 |
| 75 virtual OAuth2AccessTokenFetcher* CreateAccessTokenFetcher( | 75 virtual OAuth2AccessTokenFetcher* CreateAccessTokenFetcher( |
| 76 const std::string& account_id, | 76 const std::string& account_id, |
| 77 net::URLRequestContextGetter* getter, | 77 net::URLRequestContextGetter* getter, |
| 78 OAuth2AccessTokenConsumer* consumer) OVERRIDE; | 78 OAuth2AccessTokenConsumer* consumer) override; |
| 79 | 79 |
| 80 std::set<std::string> account_ids_; | 80 std::set<std::string> account_ids_; |
| 81 std::vector<PendingRequest> pending_requests_; | 81 std::vector<PendingRequest> pending_requests_; |
| 82 | 82 |
| 83 net::URLRequestContextGetter* request_context_; // weak | 83 net::URLRequestContextGetter* request_context_; // weak |
| 84 | 84 |
| 85 DISALLOW_COPY_AND_ASSIGN(FakeOAuth2TokenService); | 85 DISALLOW_COPY_AND_ASSIGN(FakeOAuth2TokenService); |
| 86 }; | 86 }; |
| 87 | 87 |
| 88 #endif // GOOGLE_APIS_GAIA_FAKE_OAUTH2_TOKEN_SERVICE_H_ | 88 #endif // GOOGLE_APIS_GAIA_FAKE_OAUTH2_TOKEN_SERVICE_H_ |
| OLD | NEW |