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