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 "net/url_request/url_fetcher_delegate.h"
13 class GoogleServiceAuthError
;
16 class DictionaryValue
;
21 class URLRequestContextGetter
;
26 // Class that makes a UserInfo request, parses the response, and notifies
27 // a provided Delegate when the request is complete.
28 class POLICY_EXPORT UserInfoFetcher
: public net::URLFetcherDelegate
{
30 class POLICY_EXPORT Delegate
{
32 // Invoked when the UserInfo request has succeeded, passing the parsed
33 // response in |response|. Delegate may free the UserInfoFetcher in this
35 virtual void OnGetUserInfoSuccess(
36 const base::DictionaryValue
* response
) = 0;
38 // Invoked when the UserInfo request has failed, passing the associated
39 // error in |error|. Delegate may free the UserInfoFetcher in this
41 virtual void OnGetUserInfoFailure(const GoogleServiceAuthError
& error
) = 0;
44 // Create a new UserInfoFetcher. |context| can be NULL for unit tests.
45 UserInfoFetcher(Delegate
* delegate
, net::URLRequestContextGetter
* context
);
46 ~UserInfoFetcher() override
;
48 // Starts the UserInfo request, using the passed OAuth2 |access_token|.
49 void Start(const std::string
& access_token
);
51 // net::URLFetcherDelegate implementation.
52 void OnURLFetchComplete(const net::URLFetcher
* source
) override
;
56 net::URLRequestContextGetter
* context_
;
57 scoped_ptr
<net::URLFetcher
> url_fetcher_
;
59 DISALLOW_COPY_AND_ASSIGN(UserInfoFetcher
);
64 #endif // COMPONENTS_POLICY_CORE_COMMON_CLOUD_USER_INFO_FETCHER_H_