Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(681)

Side by Side Diff: components/policy/core/common/cloud/user_info_fetcher.h

Issue 265563002: Revert of Use new people.get api instead of oauth2/v1/userinfo. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef COMPONENTS_POLICY_CORE_COMMON_CLOUD_USER_INFO_FETCHER_H_ 5 #ifndef COMPONENTS_POLICY_CORE_COMMON_CLOUD_USER_INFO_FETCHER_H_
6 #define COMPONENTS_POLICY_CORE_COMMON_CLOUD_USER_INFO_FETCHER_H_ 6 #define COMPONENTS_POLICY_CORE_COMMON_CLOUD_USER_INFO_FETCHER_H_
7 7
8 #include <string> 8 #include <string>
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "components/policy/policy_export.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" 11 #include "net/url_request/url_fetcher_delegate.h"
13 12
14 class GoogleServiceAuthError; 13 class GoogleServiceAuthError;
15 14
16 namespace base { 15 namespace base {
17 class DictionaryValue; 16 class DictionaryValue;
18 } 17 }
19 18
20 namespace net { 19 namespace net {
21 class URLFetcher; 20 class URLFetcher;
22 class URLRequestContextGetter; 21 class URLRequestContextGetter;
23 } 22 }
24 23
25 namespace policy { 24 namespace policy {
26 25
27 // Class that makes a UserInfo request, parses the response, and notifies 26 // Class that makes a UserInfo request, parses the response, and notifies
28 // a provided Delegate when the request is complete. 27 // a provided Delegate when the request is complete.
29 class POLICY_EXPORT UserInfoFetcher { 28 class POLICY_EXPORT UserInfoFetcher : public net::URLFetcherDelegate {
30 public: 29 public:
31 class POLICY_EXPORT Delegate { 30 class POLICY_EXPORT Delegate {
32 public: 31 public:
33 // Invoked when the UserInfo request has succeeded, passing the parsed 32 // Invoked when the UserInfo request has succeeded, passing the parsed
34 // response in |response|. Delegate may free the UserInfoFetcher in this 33 // response in |response|. Delegate may free the UserInfoFetcher in this
35 // callback. 34 // callback.
36 virtual void OnGetUserInfoSuccess( 35 virtual void OnGetUserInfoSuccess(
37 const base::DictionaryValue* response) = 0; 36 const base::DictionaryValue* response) = 0;
38 37
39 // Invoked when the UserInfo request has failed, passing the associated 38 // Invoked when the UserInfo request has failed, passing the associated
40 // error in |error|. Delegate may free the UserInfoFetcher in this 39 // error in |error|. Delegate may free the UserInfoFetcher in this
41 // callback. 40 // callback.
42 virtual void OnGetUserInfoFailure(const GoogleServiceAuthError& error) = 0; 41 virtual void OnGetUserInfoFailure(const GoogleServiceAuthError& error) = 0;
43 }; 42 };
44 43
45 // Create a new UserInfoFetcher. |context| can be NULL for unit tests. 44 // Create a new UserInfoFetcher. |context| can be NULL for unit tests.
46 UserInfoFetcher(Delegate* delegate, net::URLRequestContextGetter* context); 45 UserInfoFetcher(Delegate* delegate, net::URLRequestContextGetter* context);
47 virtual ~UserInfoFetcher(); 46 virtual ~UserInfoFetcher();
48 47
49 // Starts the UserInfo request, using the passed OAuth2 |access_token|. 48 // Starts the UserInfo request, using the passed OAuth2 |access_token|.
50 void Start(const std::string& access_token); 49 void Start(const std::string& access_token);
51 50
51 // net::URLFetcherDelegate implementation.
52 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
53
52 private: 54 private:
53 class GaiaDelegate : public gaia::GaiaOAuthClient::Delegate { 55 Delegate* delegate_;
54 public: 56 net::URLRequestContextGetter* context_;
55 explicit GaiaDelegate(UserInfoFetcher::Delegate* delegate); 57 scoped_ptr<net::URLFetcher> url_fetcher_;
56
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;
63
64 UserInfoFetcher::Delegate* delegate_;
65
66 DISALLOW_COPY_AND_ASSIGN(GaiaDelegate);
67 };
68
69 GaiaDelegate delegate_;
70 gaia::GaiaOAuthClient gaia_client_;
71 58
72 DISALLOW_COPY_AND_ASSIGN(UserInfoFetcher); 59 DISALLOW_COPY_AND_ASSIGN(UserInfoFetcher);
73 }; 60 };
74 61
75 } // namespace policy 62 } // namespace policy
76 63
77 #endif // COMPONENTS_POLICY_CORE_COMMON_CLOUD_USER_INFO_FETCHER_H_ 64 #endif // COMPONENTS_POLICY_CORE_COMMON_CLOUD_USER_INFO_FETCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698