Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / components / policy / core / common / cloud / user_info_fetcher.h
blob632e69227c4ff0c57424057c62af7da1cc5265a4
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_
8 #include <string>
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;
15 namespace base {
16 class DictionaryValue;
19 namespace net {
20 class URLFetcher;
21 class URLRequestContextGetter;
24 namespace policy {
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 {
29 public:
30 class POLICY_EXPORT Delegate {
31 public:
32 // Invoked when the UserInfo request has succeeded, passing the parsed
33 // response in |response|. Delegate may free the UserInfoFetcher in this
34 // callback.
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
40 // callback.
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;
54 private:
55 Delegate* delegate_;
56 net::URLRequestContextGetter* context_;
57 scoped_ptr<net::URLFetcher> url_fetcher_;
59 DISALLOW_COPY_AND_ASSIGN(UserInfoFetcher);
62 } // namespace policy
64 #endif // COMPONENTS_POLICY_CORE_COMMON_CLOUD_USER_INFO_FETCHER_H_