Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef COMPONENTS_SIGNIN_CORE_BROWSER_ACCESS_TOKEN_FETCHER_H_ | |
| 6 #define COMPONENTS_SIGNIN_CORE_BROWSER_ACCESS_TOKEN_FETCHER_H_ | |
| 7 | |
| 8 #include <memory> | |
| 9 #include <string> | |
| 10 | |
| 11 #include "base/callback.h" | |
| 12 #include "base/macros.h" | |
| 13 #include "base/memory/weak_ptr.h" | |
| 14 #include "google_apis/gaia/oauth2_token_service.h" | |
| 15 | |
| 16 class SigninManagerBase; | |
| 17 | |
| 18 // Helper class to ease the task of obtaining an OAuth2 access token. This | |
| 19 // handles various special cases, e.g. when the refresh token isn't loaded yet | |
| 20 // (during startup). | |
| 21 // May only be used on the UI thread. | |
| 22 class AccessTokenFetcher : public OAuth2TokenService::Observer, | |
| 23 public OAuth2TokenService::Consumer { | |
| 24 public: | |
| 25 using TokenCallback = base::Callback<void(const std::string&)>; | |
| 26 | |
| 27 // Instantiates a fetcher and immediately starts the process of obtaining an | |
| 28 // OAuth2 access token for the given |scopes|. The |callback| will be called | |
| 29 // with the access token on success, or with an empty string on failure. If | |
| 30 // the AccessTokenFetcher is destroyed before the process completes, the | |
| 31 // callback will not be called. | |
| 32 AccessTokenFetcher(const std::string& oauth_consumer_name, | |
| 33 const SigninManagerBase* signin_manager, | |
| 34 OAuth2TokenService* token_service, | |
| 35 const OAuth2TokenService::ScopeSet& scopes, | |
| 36 const TokenCallback& callback); | |
|
msarda
2017/01/18 21:55:19
I would expect 2 things:
* either the token callba
Marc Treib
2017/01/19 15:03:56
I assume you mean GoogleServiceAuthError? The issu
msarda
2017/01/23 17:08:09
Yes, this is what I had in mind. I still think we
| |
| 37 | |
| 38 ~AccessTokenFetcher() override; | |
| 39 | |
| 40 private: | |
| 41 void Start(); | |
| 42 | |
| 43 void NotSignedInCallback(); | |
|
msarda
2017/01/18 21:55:19
This method names is very unclear.
Marc Treib
2017/01/19 15:03:56
Renamed to "RunCallbackNotSignedIn" - better?
| |
| 44 | |
| 45 // OAuth2TokenService::Observer implementation. | |
| 46 void OnRefreshTokenAvailable(const std::string& account_id) override; | |
| 47 void OnRefreshTokensLoaded() override; | |
| 48 | |
| 49 void StartAccessTokenRequest(); | |
|
msarda
2017/01/18 21:55:19
Move this method next to the NotSignedInCallback a
Marc Treib
2017/01/19 15:03:56
Done.
| |
| 50 | |
| 51 // OAuth2TokenService::Consumer implementation. | |
| 52 void OnGetTokenSuccess(const OAuth2TokenService::Request* request, | |
| 53 const std::string& access_token, | |
| 54 const base::Time& expiration_time) override; | |
| 55 void OnGetTokenFailure(const OAuth2TokenService::Request* request, | |
| 56 const GoogleServiceAuthError& error) override; | |
| 57 | |
| 58 const SigninManagerBase* signin_manager_; | |
| 59 OAuth2TokenService* token_service_; | |
| 60 OAuth2TokenService::ScopeSet scopes_; | |
| 61 | |
| 62 TokenCallback callback_; | |
| 63 | |
| 64 bool waiting_for_refresh_token_ = false; | |
|
msarda
2017/01/18 21:55:19
I think we prefer values to be initialized on the
Marc Treib
2017/01/19 15:03:56
AFAIK there's no general preference for one over t
| |
| 65 | |
| 66 std::unique_ptr<OAuth2TokenService::Request> access_token_request_; | |
| 67 | |
| 68 // When a token request gets canceled, we want to retry once. | |
| 69 bool access_token_retried_ = false; | |
| 70 | |
| 71 base::WeakPtrFactory<AccessTokenFetcher> weak_ptr_factory_; | |
| 72 | |
| 73 DISALLOW_COPY_AND_ASSIGN(AccessTokenFetcher); | |
| 74 }; | |
| 75 | |
| 76 #endif // COMPONENTS_SIGNIN_CORE_BROWSER_ACCESS_TOKEN_FETCHER_H_ | |
| OLD | NEW |