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 CHROME_BROWSER_SIGNIN_FAKE_PROFILE_OAUTH2_TOKEN_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_SIGNIN_FAKE_PROFILE_OAUTH2_TOKEN_SERVICE_H_ |
6 #define CHROME_BROWSER_SIGNIN_FAKE_PROFILE_OAUTH2_TOKEN_SERVICE_H_ | 6 #define CHROME_BROWSER_SIGNIN_FAKE_PROFILE_OAUTH2_TOKEN_SERVICE_H_ |
7 | 7 |
8 #include "chrome/browser/signin/profile_oauth2_token_service.h" | 8 #include "chrome/browser/signin/profile_oauth2_token_service.h" |
9 | 9 |
10 #include <string> | 10 #include <string> |
(...skipping 25 matching lines...) Expand all Loading... |
36 // ... | 36 // ... |
37 // // ...or make them fail... | 37 // // ...or make them fail... |
38 // IssueErrorForScope(scopes, GoogleServiceAuthError(INVALID_GAIA_CREDENTIALS)); | 38 // IssueErrorForScope(scopes, GoogleServiceAuthError(INVALID_GAIA_CREDENTIALS)); |
39 // | 39 // |
40 class FakeProfileOAuth2TokenService : public ProfileOAuth2TokenService { | 40 class FakeProfileOAuth2TokenService : public ProfileOAuth2TokenService { |
41 public: | 41 public: |
42 struct PendingRequest { | 42 struct PendingRequest { |
43 PendingRequest(); | 43 PendingRequest(); |
44 ~PendingRequest(); | 44 ~PendingRequest(); |
45 | 45 |
| 46 std::string account_id; |
46 std::string client_id; | 47 std::string client_id; |
47 std::string client_secret; | 48 std::string client_secret; |
48 ScopeSet scopes; | 49 ScopeSet scopes; |
49 base::WeakPtr<RequestImpl> request; | 50 base::WeakPtr<RequestImpl> request; |
50 }; | 51 }; |
51 | 52 |
52 FakeProfileOAuth2TokenService(); | 53 FakeProfileOAuth2TokenService(); |
53 virtual ~FakeProfileOAuth2TokenService(); | 54 virtual ~FakeProfileOAuth2TokenService(); |
54 | 55 |
55 // Sets the current refresh token. If |token| is non-empty, this will invoke | 56 // Sets the current refresh token. If |token| is non-empty, this will invoke |
56 // OnRefreshTokenAvailable() on all Observers, otherwise this will invoke | 57 // OnRefreshTokenAvailable() on all Observers, otherwise this will invoke |
57 // OnRefreshTokenRevoked(). | 58 // OnRefreshTokenRevoked(). |
58 void IssueRefreshToken(const std::string& token); | 59 void IssueRefreshToken(const std::string& token); |
59 | 60 |
60 // Gets a list of active requests (can be used by tests to validate that the | 61 // Gets a list of active requests (can be used by tests to validate that the |
61 // correct request has been issued). | 62 // correct request has been issued). |
62 std::vector<PendingRequest> GetPendingRequests(); | 63 std::vector<PendingRequest> GetPendingRequests(); |
63 | 64 |
64 // Helper routines to issue tokens for pending requests. | 65 // Helper routines to issue tokens for pending requests. |
| 66 // TODO(fgorski): Add account IDs as parameters. |
65 void IssueTokenForScope(const ScopeSet& scopes, | 67 void IssueTokenForScope(const ScopeSet& scopes, |
66 const std::string& access_token, | 68 const std::string& access_token, |
67 const base::Time& expiration); | 69 const base::Time& expiration); |
68 | 70 |
69 void IssueErrorForScope(const ScopeSet& scopes, | 71 void IssueErrorForScope(const ScopeSet& scopes, |
70 const GoogleServiceAuthError& error); | 72 const GoogleServiceAuthError& error); |
71 | 73 |
72 void IssueTokenForAllPendingRequests(const std::string& access_token, | 74 void IssueTokenForAllPendingRequests(const std::string& access_token, |
73 const base::Time& expiration); | 75 const base::Time& expiration); |
74 | 76 |
75 void IssueErrorForAllPendingRequests(const GoogleServiceAuthError& error); | 77 void IssueErrorForAllPendingRequests(const GoogleServiceAuthError& error); |
76 | 78 |
| 79 virtual void Initialize(Profile* profile) OVERRIDE; |
77 virtual void Shutdown() OVERRIDE; | 80 virtual void Shutdown() OVERRIDE; |
78 | 81 |
79 // Helper function to be used with | 82 // Helper function to be used with |
80 // BrowserContextKeyedService::SetTestingFactory(). | 83 // BrowserContextKeyedService::SetTestingFactory(). |
81 static BrowserContextKeyedService* Build(content::BrowserContext* profile); | 84 static BrowserContextKeyedService* Build(content::BrowserContext* profile); |
82 | 85 |
83 protected: | 86 protected: |
84 // OAuth2TokenService overrides. | 87 // OAuth2TokenService overrides. |
85 virtual void FetchOAuth2Token(RequestImpl* request, | 88 virtual void FetchOAuth2Token(RequestImpl* request, |
| 89 const std::string& account_id, |
86 net::URLRequestContextGetter* getter, | 90 net::URLRequestContextGetter* getter, |
87 const std::string& client_id, | 91 const std::string& client_id, |
88 const std::string& client_secret, | 92 const std::string& client_secret, |
89 const ScopeSet& scopes) OVERRIDE; | 93 const ScopeSet& scopes) OVERRIDE; |
90 | 94 |
91 virtual std::string GetRefreshToken() OVERRIDE; | 95 virtual std::string GetRefreshToken(const std::string& account_id) OVERRIDE; |
92 | 96 |
93 virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE; | 97 virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE; |
94 | 98 |
95 private: | 99 private: |
96 // Helper function to complete pending requests - if |all_scopes| is true, | 100 // Helper function to complete pending requests - if |all_scopes| is true, |
97 // then all pending requests are completed, otherwise, only those requests | 101 // then all pending requests are completed, otherwise, only those requests |
98 // matching |scopes| are completed. | 102 // matching |scopes| are completed. |
99 void CompleteRequests(bool all_scopes, | 103 void CompleteRequests(bool all_scopes, |
100 const ScopeSet& scopes, | 104 const ScopeSet& scopes, |
101 const GoogleServiceAuthError& error, | 105 const GoogleServiceAuthError& error, |
102 const std::string& access_token, | 106 const std::string& access_token, |
103 const base::Time& expiration); | 107 const base::Time& expiration); |
104 | 108 |
105 std::vector<PendingRequest> pending_requests_; | 109 std::vector<PendingRequest> pending_requests_; |
106 std::string refresh_token_; | 110 std::string refresh_token_; |
| 111 bool is_initialized_; |
107 | 112 |
108 DISALLOW_COPY_AND_ASSIGN(FakeProfileOAuth2TokenService); | 113 DISALLOW_COPY_AND_ASSIGN(FakeProfileOAuth2TokenService); |
109 }; | 114 }; |
110 | 115 |
111 #endif // CHROME_BROWSER_SIGNIN_FAKE_PROFILE_OAUTH2_TOKEN_SERVICE_H_ | 116 #endif // CHROME_BROWSER_SIGNIN_FAKE_PROFILE_OAUTH2_TOKEN_SERVICE_H_ |
OLD | NEW |