| 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); | |
| 28 void RemoveAccount(const std::string& account_id); | |
| 29 | |
| 30 // Helper routines to issue tokens for pending requests or complete them with | 21 // Helper routines to issue tokens for pending requests or complete them with |
| 31 // error. | 22 // error. |
| 32 void IssueAllTokensForAccount(const std::string& account_id, | 23 void IssueAllTokensForAccount(const std::string& account_id, |
| 33 const std::string& access_token, | 24 const std::string& access_token, |
| 34 const base::Time& expiration); | 25 const base::Time& expiration); |
| 35 void IssueErrorForAllPendingRequestsForAccount( | 26 void IssueErrorForAllPendingRequestsForAccount( |
| 36 const std::string& account_id, | 27 const std::string& account_id, |
| 37 const GoogleServiceAuthError& auth_error); | 28 const GoogleServiceAuthError& auth_error); |
| 38 | 29 |
| 39 void set_request_context(net::URLRequestContextGetter* request_context) { | 30 FakeOAuth2TokenServiceDelegate* GetFakeOAuth2TokenServiceDelegate(); |
| 40 request_context_ = request_context; | |
| 41 } | |
| 42 | 31 |
| 43 protected: | 32 protected: |
| 44 // OAuth2TokenService overrides. | 33 // OAuth2TokenService overrides. |
| 45 void FetchOAuth2Token(RequestImpl* request, | 34 void FetchOAuth2Token(RequestImpl* request, |
| 46 const std::string& account_id, | 35 const std::string& account_id, |
| 47 net::URLRequestContextGetter* getter, | 36 net::URLRequestContextGetter* getter, |
| 48 const std::string& client_id, | 37 const std::string& client_id, |
| 49 const std::string& client_secret, | 38 const std::string& client_secret, |
| 50 const ScopeSet& scopes) override; | 39 const ScopeSet& scopes) override; |
| 51 | 40 |
| 52 void InvalidateOAuth2Token(const std::string& account_id, | 41 void InvalidateAccessTokenImpl(const std::string& account_id, |
| 53 const std::string& client_id, | 42 const std::string& client_id, |
| 54 const ScopeSet& scopes, | 43 const ScopeSet& scopes, |
| 55 const std::string& access_token) override; | 44 const std::string& access_token) override; |
| 56 | |
| 57 bool RefreshTokenIsAvailable(const std::string& account_id) const override; | |
| 58 | 45 |
| 59 private: | 46 private: |
| 60 struct PendingRequest { | 47 struct PendingRequest { |
| 61 PendingRequest(); | 48 PendingRequest(); |
| 62 ~PendingRequest(); | 49 ~PendingRequest(); |
| 63 | 50 |
| 64 std::string account_id; | 51 std::string account_id; |
| 65 std::string client_id; | 52 std::string client_id; |
| 66 std::string client_secret; | 53 std::string client_secret; |
| 67 ScopeSet scopes; | 54 ScopeSet scopes; |
| 68 base::WeakPtr<RequestImpl> request; | 55 base::WeakPtr<RequestImpl> request; |
| 69 }; | 56 }; |
| 70 | 57 |
| 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_; | 58 std::vector<PendingRequest> pending_requests_; |
| 81 | 59 |
| 82 net::URLRequestContextGetter* request_context_; // weak | |
| 83 | |
| 84 DISALLOW_COPY_AND_ASSIGN(FakeOAuth2TokenService); | 60 DISALLOW_COPY_AND_ASSIGN(FakeOAuth2TokenService); |
| 85 }; | 61 }; |
| 86 | 62 |
| 87 #endif // GOOGLE_APIS_GAIA_FAKE_OAUTH2_TOKEN_SERVICE_H_ | 63 #endif // GOOGLE_APIS_GAIA_FAKE_OAUTH2_TOKEN_SERVICE_H_ |
| OLD | NEW |