1 // Copyright (c) 2012 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_POLICY_CORE_COMMON_CLOUD_USER_INFO_FETCHER_H_
6 #define COMPONENTS_POLICY_CORE_COMMON_CLOUD_USER_INFO_FETCHER_H_
9 #include "base/memory/scoped_ptr.h"
10 #include "components/policy/policy_export.h"
11 #include "google_apis/gaia/gaia_oauth_client.h"
12 #include "net/url_request/url_fetcher_delegate.h"
14 class GoogleServiceAuthError
;
17 class DictionaryValue
;
22 class URLRequestContextGetter
;
27 // Class that makes a UserInfo request, parses the response, and notifies
28 // a provided Delegate when the request is complete.
29 class POLICY_EXPORT UserInfoFetcher
{
31 class POLICY_EXPORT Delegate
{
33 // Invoked when the UserInfo request has succeeded, passing the parsed
34 // response in |response|. Delegate may free the UserInfoFetcher in this
36 virtual void OnGetUserInfoSuccess(
37 const base::DictionaryValue
* response
) = 0;
39 // Invoked when the UserInfo request has failed, passing the associated
40 // error in |error|. Delegate may free the UserInfoFetcher in this
42 virtual void OnGetUserInfoFailure(const GoogleServiceAuthError
& error
) = 0;
45 // Create a new UserInfoFetcher. |context| can be NULL for unit tests.
46 UserInfoFetcher(Delegate
* delegate
, net::URLRequestContextGetter
* context
);
47 virtual ~UserInfoFetcher();
49 // Starts the UserInfo request, using the passed OAuth2 |access_token|.
50 void Start(const std::string
& access_token
);
53 class GaiaDelegate
: public gaia::GaiaOAuthClient::Delegate
{
55 explicit GaiaDelegate(UserInfoFetcher::Delegate
* delegate
);
58 // gaia::GaiaOAuthClient::Delegate implementation.
59 virtual void OnGetUserInfoResponse(
60 scoped_ptr
<base::DictionaryValue
> user_info
) OVERRIDE
;
61 virtual void OnOAuthError() OVERRIDE
;
62 virtual void OnNetworkError(int response_code
) OVERRIDE
;
64 UserInfoFetcher::Delegate
* delegate_
;
66 DISALLOW_COPY_AND_ASSIGN(GaiaDelegate
);
69 GaiaDelegate delegate_
;
70 gaia::GaiaOAuthClient gaia_client_
;
72 DISALLOW_COPY_AND_ASSIGN(UserInfoFetcher
);
77 #endif // COMPONENTS_POLICY_CORE_COMMON_CLOUD_USER_INFO_FETCHER_H_