Chromium Code Reviews| 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 51 std::string account_id; | 51 std::string account_id; |
| 52 std::string client_id; | 52 std::string client_id; |
| 53 std::string client_secret; | 53 std::string client_secret; |
| 54 ScopeSet scopes; | 54 ScopeSet scopes; |
| 55 base::WeakPtr<RequestImpl> request; | 55 base::WeakPtr<RequestImpl> request; |
| 56 }; | 56 }; |
| 57 | 57 |
| 58 FakeProfileOAuth2TokenService(); | 58 FakeProfileOAuth2TokenService(); |
| 59 ~FakeProfileOAuth2TokenService() override; | 59 ~FakeProfileOAuth2TokenService() override; |
| 60 | 60 |
| 61 // Overriden to make sure it works on Android. | |
| 62 bool RefreshTokenIsAvailable(const std::string& account_id) const override; | |
| 63 | |
| 64 // Overriden to make sure it works on iOS. | |
| 65 void LoadCredentials(const std::string& primary_account_id) override; | |
| 66 | |
| 67 std::vector<std::string> GetAccounts() override; | |
| 68 | |
| 69 // Overriden to make sure it works on Android. Simply calls | |
| 70 // IssueRefreshToken(). | |
| 71 void UpdateCredentials(const std::string& account_id, | |
| 72 const std::string& refresh_token) override; | |
| 73 | |
| 74 // Sets the current refresh token. If |token| is non-empty, this will invoke | 61 // Sets the current refresh token. If |token| is non-empty, this will invoke |
| 75 // OnRefreshTokenAvailable() on all Observers, otherwise this will invoke | 62 // OnRefreshTokenAvailable() on all Observers, otherwise this will invoke |
| 76 // OnRefreshTokenRevoked(). | 63 // OnRefreshTokenRevoked(). |
| 77 void IssueRefreshToken(const std::string& token); | 64 void IssueRefreshToken(const std::string& token); |
| 78 | 65 |
| 79 // TODO(fgorski,rogerta): Merge with UpdateCredentials when this class fully | 66 // TODO(fgorski,rogerta): Merge with UpdateCredentials when this class fully |
| 80 // supports multiple accounts. | 67 // supports multiple accounts. |
| 81 void IssueRefreshTokenForUser(const std::string& account_id, | 68 void IssueRefreshTokenForUser(const std::string& account_id, |
| 82 const std::string& token); | 69 const std::string& token); |
| 83 | 70 |
| 84 // Fire OnRefreshTokensLoaded on all observers. | 71 // Fire OnRefreshTokensLoaded on all observers. |
| 85 void IssueAllRefreshTokensLoaded(); | 72 void IssueAllRefreshTokensLoaded(); |
|
Roger Tawa OOO till Jul 10th
2015/05/28 14:54:43
We don't need the three IssueXXX methods above, si
gogerald1
2015/06/03 18:12:58
Done.
| |
| 86 | 73 |
| 87 // Gets a list of active requests (can be used by tests to validate that the | 74 // Gets a list of active requests (can be used by tests to validate that the |
| 88 // correct request has been issued). | 75 // correct request has been issued). |
| 89 std::vector<PendingRequest> GetPendingRequests(); | 76 std::vector<PendingRequest> GetPendingRequests(); |
| 90 | 77 |
| 91 // Helper routines to issue tokens for pending requests. | 78 // Helper routines to issue tokens for pending requests. |
| 92 void IssueAllTokensForAccount(const std::string& account_id, | 79 void IssueAllTokensForAccount(const std::string& account_id, |
| 93 const std::string& access_token, | 80 const std::string& access_token, |
| 94 const base::Time& expiration); | 81 const base::Time& expiration); |
| 95 | 82 |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 115 | 102 |
| 116 protected: | 103 protected: |
| 117 // OAuth2TokenService overrides. | 104 // OAuth2TokenService overrides. |
| 118 void FetchOAuth2Token(RequestImpl* request, | 105 void FetchOAuth2Token(RequestImpl* request, |
| 119 const std::string& account_id, | 106 const std::string& account_id, |
| 120 net::URLRequestContextGetter* getter, | 107 net::URLRequestContextGetter* getter, |
| 121 const std::string& client_id, | 108 const std::string& client_id, |
| 122 const std::string& client_secret, | 109 const std::string& client_secret, |
| 123 const ScopeSet& scopes) override; | 110 const ScopeSet& scopes) override; |
| 124 | 111 |
| 125 OAuth2AccessTokenFetcher* CreateAccessTokenFetcher( | |
| 126 const std::string& account_id, | |
| 127 net::URLRequestContextGetter* getter, | |
| 128 OAuth2AccessTokenConsumer* consumer) override; | |
| 129 | |
| 130 void InvalidateOAuth2Token(const std::string& account_id, | 112 void InvalidateOAuth2Token(const std::string& account_id, |
| 131 const std::string& client_id, | 113 const std::string& client_id, |
| 132 const ScopeSet& scopes, | 114 const ScopeSet& scopes, |
| 133 const std::string& access_token) override; | 115 const std::string& access_token) override; |
| 134 | |
| 135 net::URLRequestContextGetter* GetRequestContext() override; | |
| 136 | |
| 137 private: | 116 private: |
| 138 // Helper function to complete pending requests - if |all_scopes| is true, | 117 // Helper function to complete pending requests - if |all_scopes| is true, |
| 139 // then all pending requests are completed, otherwise, only those requests | 118 // then all pending requests are completed, otherwise, only those requests |
| 140 // matching |scopes| are completed. If |account_id| is empty, then pending | 119 // matching |scopes| are completed. If |account_id| is empty, then pending |
| 141 // requests for all accounts are completed, otherwise only requests for the | 120 // requests for all accounts are completed, otherwise only requests for the |
| 142 // given account. | 121 // given account. |
| 143 void CompleteRequests(const std::string& account_id, | 122 void CompleteRequests(const std::string& account_id, |
| 144 bool all_scopes, | 123 bool all_scopes, |
| 145 const ScopeSet& scopes, | 124 const ScopeSet& scopes, |
| 146 const GoogleServiceAuthError& error, | 125 const GoogleServiceAuthError& error, |
| 147 const std::string& access_token, | 126 const std::string& access_token, |
| 148 const base::Time& expiration); | 127 const base::Time& expiration); |
| 149 | 128 |
| 150 std::string GetRefreshToken(const std::string& account_id) const; | |
| 151 | |
| 152 std::vector<PendingRequest> pending_requests_; | 129 std::vector<PendingRequest> pending_requests_; |
| 153 | 130 |
| 154 // Maps account ids to their refresh token strings. | |
| 155 std::map<std::string, std::string> refresh_tokens_; | |
| 156 | |
| 157 // If true, then this fake service will post responses to | 131 // If true, then this fake service will post responses to |
| 158 // |FetchOAuth2Token| on the current run loop. There is no need to call | 132 // |FetchOAuth2Token| on the current run loop. There is no need to call |
| 159 // |IssueTokenForScope| in this case. | 133 // |IssueTokenForScope| in this case. |
| 160 bool auto_post_fetch_response_on_message_loop_; | 134 bool auto_post_fetch_response_on_message_loop_; |
| 161 | 135 |
| 162 base::WeakPtrFactory<FakeProfileOAuth2TokenService> weak_ptr_factory_; | 136 base::WeakPtrFactory<FakeProfileOAuth2TokenService> weak_ptr_factory_; |
| 163 | 137 |
| 164 DISALLOW_COPY_AND_ASSIGN(FakeProfileOAuth2TokenService); | 138 DISALLOW_COPY_AND_ASSIGN(FakeProfileOAuth2TokenService); |
| 165 }; | 139 }; |
| 166 | 140 |
| 167 #endif // CHROME_BROWSER_SIGNIN_FAKE_PROFILE_OAUTH2_TOKEN_SERVICE_H_ | 141 #endif // CHROME_BROWSER_SIGNIN_FAKE_PROFILE_OAUTH2_TOKEN_SERVICE_H_ |
| OLD | NEW |