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 ~FakeOAuth2TokenService() override; |
24 | 24 |
25 virtual std::vector<std::string> GetAccounts() override; | 25 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 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 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 bool RefreshTokenIsAvailable(const std::string& account_id) const override; |
58 override; | |
59 | 58 |
60 private: | 59 private: |
61 struct PendingRequest { | 60 struct PendingRequest { |
62 PendingRequest(); | 61 PendingRequest(); |
63 ~PendingRequest(); | 62 ~PendingRequest(); |
64 | 63 |
65 std::string account_id; | 64 std::string account_id; |
66 std::string client_id; | 65 std::string client_id; |
67 std::string client_secret; | 66 std::string client_secret; |
68 ScopeSet scopes; | 67 ScopeSet scopes; |
69 base::WeakPtr<RequestImpl> request; | 68 base::WeakPtr<RequestImpl> request; |
70 }; | 69 }; |
71 | 70 |
72 // OAuth2TokenService overrides. | 71 // OAuth2TokenService overrides. |
73 virtual net::URLRequestContextGetter* GetRequestContext() override; | 72 net::URLRequestContextGetter* GetRequestContext() override; |
74 | 73 |
75 virtual OAuth2AccessTokenFetcher* CreateAccessTokenFetcher( | 74 OAuth2AccessTokenFetcher* CreateAccessTokenFetcher( |
76 const std::string& account_id, | 75 const std::string& account_id, |
77 net::URLRequestContextGetter* getter, | 76 net::URLRequestContextGetter* getter, |
78 OAuth2AccessTokenConsumer* consumer) override; | 77 OAuth2AccessTokenConsumer* consumer) override; |
79 | 78 |
80 std::set<std::string> account_ids_; | 79 std::set<std::string> account_ids_; |
81 std::vector<PendingRequest> pending_requests_; | 80 std::vector<PendingRequest> pending_requests_; |
82 | 81 |
83 net::URLRequestContextGetter* request_context_; // weak | 82 net::URLRequestContextGetter* request_context_; // weak |
84 | 83 |
85 DISALLOW_COPY_AND_ASSIGN(FakeOAuth2TokenService); | 84 DISALLOW_COPY_AND_ASSIGN(FakeOAuth2TokenService); |
86 }; | 85 }; |
87 | 86 |
88 #endif // GOOGLE_APIS_GAIA_FAKE_OAUTH2_TOKEN_SERVICE_H_ | 87 #endif // GOOGLE_APIS_GAIA_FAKE_OAUTH2_TOKEN_SERVICE_H_ |
OLD | NEW |