Chromium Code Reviews| Index: components/signin/core/browser/account_service_flag_fetcher.h |
| diff --git a/components/signin/core/browser/account_service_flag_fetcher.h b/components/signin/core/browser/account_service_flag_fetcher.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..44310909c1c607fb6b13e0a5ad3ef19d1fa08930 |
| --- /dev/null |
| +++ b/components/signin/core/browser/account_service_flag_fetcher.h |
| @@ -0,0 +1,78 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef COMPONENTS_SIGNIN_CORE_BROWSER_ACCOUNT_SERVICE_FLAG_FETCHER_H_ |
| +#define COMPONENTS_SIGNIN_CORE_BROWSER_ACCOUNT_SERVICE_FLAG_FETCHER_H_ |
| + |
| +#include <string> |
| +#include <vector> |
| + |
| +#include "base/callback.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "google_apis/gaia/gaia_auth_consumer.h" |
| +#include "google_apis/gaia/gaia_auth_fetcher.h" |
| +#include "google_apis/gaia/oauth2_token_service.h" |
| + |
| +class ProfileOAuth2TokenService; |
| + |
| +namespace net { |
| +class URLRequestContextGetter; |
| +} |
| + |
| +// 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.
|
| +class AccountServiceFlagFetcher : public GaiaAuthConsumer, |
| + public OAuth2TokenService::Observer, |
| + public OAuth2TokenService::Consumer { |
| + public: |
| + enum ResultCode { |
| + SUCCESS, |
| + TOKEN_ERROR, // Failed to get OAuth2 token. |
| + SERVICE_ERROR, // Service returned an error or malformed reply. |
| + }; |
| + // 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.
|
| + // flags that are set for the given account. |
| + typedef base::Callback<void(ResultCode /* result */, |
| + const std::vector<std::string>& /* flags */)> |
| + 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
|
| + |
| + // Immediately starts fetching the flags. |
| + AccountServiceFlagFetcher(const std::string& account_id, |
| + ProfileOAuth2TokenService* token_service, |
| + net::URLRequestContextGetter* request_context, |
| + const Callback& callback); |
| + // 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.
|
| + virtual ~AccountServiceFlagFetcher(); |
| + |
| + private: |
| + void Start(); |
| + void StartFetchingOAuth2AccessToken(); |
| + |
| + // Overridden from OAuth2TokenService::Observer: |
| + virtual void OnRefreshTokenAvailable(const std::string& account_id) OVERRIDE; |
| + |
| + // Overridden from OAuth2TokenService::Consumer: |
| + virtual void OnGetTokenSuccess(const OAuth2TokenService::Request* request, |
| + const std::string& access_token, |
| + const base::Time& expiration_time) OVERRIDE; |
| + virtual void OnGetTokenFailure(const OAuth2TokenService::Request* request, |
| + const GoogleServiceAuthError& error) OVERRIDE; |
| + |
| + // Overridden from GaiaAuthConsumer: |
| + virtual void OnClientLoginSuccess(const ClientLoginResult& result) OVERRIDE; |
| + virtual void OnClientLoginFailure(const GoogleServiceAuthError& error) |
| + OVERRIDE; |
| + virtual void OnGetUserInfoSuccess(const UserInfoMap& data) OVERRIDE; |
| + virtual void OnGetUserInfoFailure(const GoogleServiceAuthError& error) |
| + OVERRIDE; |
| + |
| + const std::string account_id_; |
| + ProfileOAuth2TokenService* token_service_; |
| + GaiaAuthFetcher gaia_auth_fetcher_; |
| + |
| + Callback callback_; |
| + |
| + scoped_ptr<OAuth2TokenService::Request> oauth2_access_token_request_; |
| +}; |
| + |
| +#endif // COMPONENTS_SIGNIN_CORE_BROWSER_ACCOUNT_SERVICE_FLAG_FETCHER_H_ |