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.
5 #ifndef COMPONENTS_SIGNIN_CORE_BROWSER_ACCOUNT_SERVICE_FLAG_FETCHER_H_
6 #define COMPONENTS_SIGNIN_CORE_BROWSER_ACCOUNT_SERVICE_FLAG_FETCHER_H_
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"
17 class ProfileOAuth2TokenService
;
20 class URLRequestContextGetter
;
23 // Downloads an account's list of Gaia service flags.
24 // On construction, the download starts immediately and calls the given callback
25 // when either the download is successful or an error is detected. It is valid
26 // to destruct the object before the callback is called; this will cancel the
28 class AccountServiceFlagFetcher
: public GaiaAuthConsumer
,
29 public OAuth2TokenService::Observer
,
30 public OAuth2TokenService::Consumer
{
34 TOKEN_ERROR
, // Failed to get OAuth2 token.
35 SERVICE_ERROR
, // Service returned an error or malformed reply.
38 // If the flag download is successful, this will return the list of service
39 // flags that are set for the given account.
40 typedef base::Callback
<void(ResultCode
/* result */,
41 const std::vector
<std::string
>& /* flags */)>
44 // Immediately starts fetching the flags.
45 AccountServiceFlagFetcher(const std::string
& account_id
,
46 ProfileOAuth2TokenService
* token_service
,
47 net::URLRequestContextGetter
* request_context
,
48 const ResultCallback
& callback
);
50 // Destructing the object before the callback is called cancels the request.
51 ~AccountServiceFlagFetcher() override
;
55 void StartFetchingOAuth2AccessToken();
57 // Overridden from OAuth2TokenService::Observer:
58 void OnRefreshTokenAvailable(const std::string
& account_id
) override
;
59 void OnRefreshTokensLoaded() override
;
61 // Overridden from OAuth2TokenService::Consumer:
62 void OnGetTokenSuccess(const OAuth2TokenService::Request
* request
,
63 const std::string
& access_token
,
64 const base::Time
& expiration_time
) override
;
65 void OnGetTokenFailure(const OAuth2TokenService::Request
* request
,
66 const GoogleServiceAuthError
& error
) override
;
68 // Overridden from GaiaAuthConsumer:
69 void OnClientLoginSuccess(const ClientLoginResult
& result
) override
;
70 void OnClientLoginFailure(const GoogleServiceAuthError
& error
) override
;
71 void OnGetUserInfoSuccess(const UserInfoMap
& data
) override
;
72 void OnGetUserInfoFailure(const GoogleServiceAuthError
& error
) override
;
74 const std::string account_id_
;
75 ProfileOAuth2TokenService
* token_service_
;
76 GaiaAuthFetcher gaia_auth_fetcher_
;
78 ResultCallback callback_
;
80 scoped_ptr
<OAuth2TokenService::Request
> oauth2_access_token_request_
;
82 DISALLOW_COPY_AND_ASSIGN(AccountServiceFlagFetcher
);
85 #endif // COMPONENTS_SIGNIN_CORE_BROWSER_ACCOUNT_SERVICE_FLAG_FETCHER_H_