| 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 |
| 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 | 13 |
| 14 #if defined(OS_ANDROID) | 14 #if defined(OS_ANDROID) |
| 15 #include "chrome/browser/signin/android_profile_oauth2_token_service.h" | 15 #include "chrome/browser/signin/android_profile_oauth2_token_service.h" |
| 16 #else | 16 #else |
| 17 #include "chrome/browser/signin/profile_oauth2_token_service.h" | 17 #include "chrome/browser/signin/profile_oauth2_token_service.h" |
| 18 #endif | 18 #endif |
| 19 | 19 |
| 20 namespace content { | |
| 21 class BrowserContext; | |
| 22 } | |
| 23 | |
| 24 // Helper class to simplify writing unittests that depend on an instance of | 20 // Helper class to simplify writing unittests that depend on an instance of |
| 25 // ProfileOAuth2TokenService. | 21 // ProfileOAuth2TokenService. |
| 26 // | 22 // |
| 27 // Tests would typically do something like the following: | 23 // Tests would typically do something like the following: |
| 28 // | 24 // |
| 29 // FakeProfileOAuth2TokenService service; | 25 // FakeProfileOAuth2TokenService service; |
| 30 // ... | 26 // ... |
| 31 // service.IssueRefreshToken("token"); // Issue refresh token/notify observers | 27 // service.IssueRefreshToken("token"); // Issue refresh token/notify observers |
| 32 // ... | 28 // ... |
| 33 // // Confirm that there is at least one active request. | 29 // // Confirm that there is at least one active request. |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 | 97 |
| 102 void IssueTokenForAllPendingRequests(const std::string& access_token, | 98 void IssueTokenForAllPendingRequests(const std::string& access_token, |
| 103 const base::Time& expiration); | 99 const base::Time& expiration); |
| 104 | 100 |
| 105 void IssueErrorForAllPendingRequests(const GoogleServiceAuthError& error); | 101 void IssueErrorForAllPendingRequests(const GoogleServiceAuthError& error); |
| 106 | 102 |
| 107 void set_auto_post_fetch_response_on_message_loop(bool auto_post_response) { | 103 void set_auto_post_fetch_response_on_message_loop(bool auto_post_response) { |
| 108 auto_post_fetch_response_on_message_loop_ = auto_post_response; | 104 auto_post_fetch_response_on_message_loop_ = auto_post_response; |
| 109 } | 105 } |
| 110 | 106 |
| 111 // Helper function to be used with | |
| 112 // BrowserContextKeyedService::SetTestingFactory(). | |
| 113 static BrowserContextKeyedService* Build(content::BrowserContext* profile); | |
| 114 | |
| 115 // Helper function to be used with | |
| 116 // BrowserContextKeyedService::SetTestingFactory() that creates a | |
| 117 // FakeProfileOAuth2TokenService object that posts fetch responses on the | |
| 118 // current message loop. | |
| 119 static BrowserContextKeyedService* BuildAutoIssuingTokenService( | |
| 120 content::BrowserContext* profile); | |
| 121 | |
| 122 protected: | 107 protected: |
| 123 // OAuth2TokenService overrides. | 108 // OAuth2TokenService overrides. |
| 124 virtual void FetchOAuth2Token(RequestImpl* request, | 109 virtual void FetchOAuth2Token(RequestImpl* request, |
| 125 const std::string& account_id, | 110 const std::string& account_id, |
| 126 net::URLRequestContextGetter* getter, | 111 net::URLRequestContextGetter* getter, |
| 127 const std::string& client_id, | 112 const std::string& client_id, |
| 128 const std::string& client_secret, | 113 const std::string& client_secret, |
| 129 const ScopeSet& scopes) OVERRIDE; | 114 const ScopeSet& scopes) OVERRIDE; |
| 130 | 115 |
| 131 virtual void InvalidateOAuth2Token(const std::string& account_id, | 116 virtual void InvalidateOAuth2Token(const std::string& account_id, |
| (...skipping 23 matching lines...) Expand all Loading... |
| 155 | 140 |
| 156 // If true, then this fake service will post responses to | 141 // If true, then this fake service will post responses to |
| 157 // |FetchOAuth2Token| on the current run loop. There is no need to call | 142 // |FetchOAuth2Token| on the current run loop. There is no need to call |
| 158 // |IssueTokenForScope| in this case. | 143 // |IssueTokenForScope| in this case. |
| 159 bool auto_post_fetch_response_on_message_loop_; | 144 bool auto_post_fetch_response_on_message_loop_; |
| 160 | 145 |
| 161 DISALLOW_COPY_AND_ASSIGN(FakeProfileOAuth2TokenService); | 146 DISALLOW_COPY_AND_ASSIGN(FakeProfileOAuth2TokenService); |
| 162 }; | 147 }; |
| 163 | 148 |
| 164 #endif // CHROME_BROWSER_SIGNIN_FAKE_PROFILE_OAUTH2_TOKEN_SERVICE_H_ | 149 #endif // CHROME_BROWSER_SIGNIN_FAKE_PROFILE_OAUTH2_TOKEN_SERVICE_H_ |
| OLD | NEW |