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