Ignore title parameter for navigator.registerProtocolHandler
[chromium-blink-merge.git] / components / policy / core / common / cloud / user_info_fetcher.h
blob0f4c25f533daa17808e3a237945ca1e26ee2b42e
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 "google_apis/gaia/gaia_oauth_client.h"
12 #include "net/url_request/url_fetcher_delegate.h"
14 class GoogleServiceAuthError;
16 namespace base {
17 class DictionaryValue;
20 namespace net {
21 class URLFetcher;
22 class URLRequestContextGetter;
25 namespace policy {
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 {
30 public:
31 class POLICY_EXPORT Delegate {
32 public:
33 // Invoked when the UserInfo request has succeeded, passing the parsed
34 // response in |response|. Delegate may free the UserInfoFetcher in this
35 // callback.
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
41 // callback.
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);
52 private:
53 class GaiaDelegate : public gaia::GaiaOAuthClient::Delegate {
54 public:
55 explicit GaiaDelegate(UserInfoFetcher::Delegate* delegate);
57 private:
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);
75 } // namespace policy
77 #endif // COMPONENTS_POLICY_CORE_COMMON_CLOUD_USER_INFO_FETCHER_H_