Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 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_ACCOUNT_SERVICE_FLAG_FETCHER_H_ | |
| 6 #define COMPONENTS_SIGNIN_CORE_BROWSER_ACCOUNT_SERVICE_FLAG_FETCHER_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "base/callback.h" | |
| 12 #include "base/memory/scoped_ptr.h" | |
| 13 #include "google_apis/gaia/gaia_auth_consumer.h" | |
| 14 #include "google_apis/gaia/gaia_auth_fetcher.h" | |
| 15 #include "google_apis/gaia/oauth2_token_service.h" | |
| 16 | |
| 17 class ProfileOAuth2TokenService; | |
| 18 | |
| 19 namespace net { | |
| 20 class URLRequestContextGetter; | |
| 21 } | |
| 22 | |
| 23 // Downloads an account's list of Gaia service flags. | |
|
Andrew T Wilson (Slow)
2014/05/23 14:51:59
Can you add a bit of information about how to use
Marc Treib
2014/05/26 12:31:40
Done.
| |
| 24 class AccountServiceFlagFetcher : public GaiaAuthConsumer, | |
| 25 public OAuth2TokenService::Observer, | |
| 26 public OAuth2TokenService::Consumer { | |
| 27 public: | |
| 28 enum ResultCode { | |
| 29 SUCCESS, | |
| 30 TOKEN_ERROR, // Failed to get OAuth2 token. | |
| 31 SERVICE_ERROR, // Service returned an error or malformed reply. | |
| 32 }; | |
| 33 // If the flag download is successful, this will return the list of service | |
|
Andrew T Wilson (Slow)
2014/05/23 14:51:59
nit: blank line above
Marc Treib
2014/05/26 12:31:40
Done.
| |
| 34 // flags that are set for the given account. | |
| 35 typedef base::Callback<void(ResultCode /* result */, | |
| 36 const std::vector<std::string>& /* flags */)> | |
| 37 Callback; | |
|
Andrew T Wilson (Slow)
2014/05/23 14:51:59
This is OK, I guess, except you're now hiding base
Marc Treib
2014/05/26 12:31:40
I called it "ResultCallback"; I think the "Service
| |
| 38 | |
| 39 // Immediately starts fetching the flags. | |
| 40 AccountServiceFlagFetcher(const std::string& account_id, | |
| 41 ProfileOAuth2TokenService* token_service, | |
| 42 net::URLRequestContextGetter* request_context, | |
| 43 const Callback& callback); | |
| 44 // Destructing the object before the callback is called cancels the request. | |
|
Andrew T Wilson (Slow)
2014/05/23 14:51:59
nit: blank line above
Marc Treib
2014/05/26 12:31:40
Done.
| |
| 45 virtual ~AccountServiceFlagFetcher(); | |
| 46 | |
| 47 private: | |
| 48 void Start(); | |
| 49 void StartFetchingOAuth2AccessToken(); | |
| 50 | |
| 51 // Overridden from OAuth2TokenService::Observer: | |
| 52 virtual void OnRefreshTokenAvailable(const std::string& account_id) OVERRIDE; | |
| 53 | |
| 54 // Overridden from OAuth2TokenService::Consumer: | |
| 55 virtual void OnGetTokenSuccess(const OAuth2TokenService::Request* request, | |
| 56 const std::string& access_token, | |
| 57 const base::Time& expiration_time) OVERRIDE; | |
| 58 virtual void OnGetTokenFailure(const OAuth2TokenService::Request* request, | |
| 59 const GoogleServiceAuthError& error) OVERRIDE; | |
| 60 | |
| 61 // Overridden from GaiaAuthConsumer: | |
| 62 virtual void OnClientLoginSuccess(const ClientLoginResult& result) OVERRIDE; | |
| 63 virtual void OnClientLoginFailure(const GoogleServiceAuthError& error) | |
| 64 OVERRIDE; | |
| 65 virtual void OnGetUserInfoSuccess(const UserInfoMap& data) OVERRIDE; | |
| 66 virtual void OnGetUserInfoFailure(const GoogleServiceAuthError& error) | |
| 67 OVERRIDE; | |
| 68 | |
| 69 const std::string account_id_; | |
| 70 ProfileOAuth2TokenService* token_service_; | |
| 71 GaiaAuthFetcher gaia_auth_fetcher_; | |
| 72 | |
| 73 Callback callback_; | |
| 74 | |
| 75 scoped_ptr<OAuth2TokenService::Request> oauth2_access_token_request_; | |
| 76 }; | |
| 77 | |
| 78 #endif // COMPONENTS_SIGNIN_CORE_BROWSER_ACCOUNT_SERVICE_FLAG_FETCHER_H_ | |
| OLD | NEW |