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

Side by Side Diff: chrome/browser/policy/cloud/cloud_policy_client_registration_helper.h

Issue 109743002: Move policy code into components/policy. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: moar fixes Created 7 years 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
(Empty)
1 // Copyright 2013 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.
4
5 #ifndef CHROME_BROWSER_POLICY_CLOUD_CLOUD_POLICY_CLIENT_REGISTRATION_HELPER_H_
6 #define CHROME_BROWSER_POLICY_CLOUD_CLOUD_POLICY_CLIENT_REGISTRATION_HELPER_H_
7
8 #include <string>
9
10 #include "base/basictypes.h"
11 #include "base/callback.h"
12 #include "base/compiler_specific.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "chrome/browser/policy/cloud/cloud_policy_client.h"
15 #include "chrome/browser/policy/cloud/user_info_fetcher.h"
16 #include "chrome/browser/policy/proto/cloud/device_management_backend.pb.h"
17
18 class OAuth2TokenService;
19
20 namespace net {
21 class URLRequestContextGetter;
22 }
23
24 namespace policy {
25
26 // Helper class that registers a CloudPolicyClient. It fetches an OAuth2 token
27 // for the DM service if needed, and checks with Gaia if the account has policy
28 // management enabled.
29 class CloudPolicyClientRegistrationHelper : public UserInfoFetcher::Delegate,
30 public CloudPolicyClient::Observer {
31 public:
32 // |context| and |client| are not owned and must outlive this object.
33 // If |should_force_load_policy| then the cloud policy registration is
34 // performed even if Gaia indicates that this account doesn't have management
35 // enabled.
36 CloudPolicyClientRegistrationHelper(
37 CloudPolicyClient* client,
38 bool should_force_load_policy,
39 enterprise_management::DeviceRegisterRequest::Type registration_type);
40 virtual ~CloudPolicyClientRegistrationHelper();
41
42 // Starts the client registration process. This version uses the
43 // supplied OAuth2TokenService to mint the new token for the userinfo
44 // and DM services, using the |account_id|.
45 // |callback| is invoked when the registration is complete.
46 void StartRegistration(
47 OAuth2TokenService* token_service,
48 const std::string& account_id,
49 const base::Closure& callback);
50
51 #if !defined(OS_ANDROID)
52 // Starts the client registration process. The |login_refresh_token| is used
53 // to mint a new token for the userinfo and DM services.
54 // |callback| is invoked when the registration is complete.
55 void StartRegistrationWithLoginToken(const std::string& login_refresh_token,
56 const base::Closure& callback);
57 #endif
58
59 private:
60 class TokenServiceHelper;
61 #if !defined(OS_ANDROID)
62 class LoginTokenHelper;
63 #endif
64
65 void OnTokenFetched(const std::string& oauth_access_token);
66
67 // UserInfoFetcher::Delegate implementation:
68 virtual void OnGetUserInfoSuccess(
69 const base::DictionaryValue* response) OVERRIDE;
70 virtual void OnGetUserInfoFailure(
71 const GoogleServiceAuthError& error) OVERRIDE;
72
73 // CloudPolicyClient::Observer implementation:
74 virtual void OnPolicyFetched(CloudPolicyClient* client) OVERRIDE;
75 virtual void OnRegistrationStateChanged(CloudPolicyClient* client) OVERRIDE;
76 virtual void OnClientError(CloudPolicyClient* client) OVERRIDE;
77
78 // Invoked when the registration request has been completed.
79 void RequestCompleted();
80
81 // Internal helper class that uses OAuth2TokenService to fetch an OAuth
82 // access token. On desktop, this is only used after the user has signed in -
83 // desktop platforms use LoginTokenHelper for policy fetches performed before
84 // signin is complete.
85 scoped_ptr<TokenServiceHelper> token_service_helper_;
86
87 #if !defined(OS_ANDROID)
88 // Special desktop-only helper to fetch an OAuth access token prior to
89 // the completion of signin. Not used on Android since all token fetching
90 // is done via OAuth2TokenService.
91 scoped_ptr<LoginTokenHelper> login_token_helper_;
92 #endif
93
94 // Helper class for fetching information from GAIA about the currently
95 // signed-in user.
96 scoped_ptr<UserInfoFetcher> user_info_fetcher_;
97
98 // Access token used to register the CloudPolicyClient and also access
99 // GAIA to get information about the signed in user.
100 std::string oauth_access_token_;
101
102 net::URLRequestContextGetter* context_;
103 CloudPolicyClient* client_;
104 bool should_force_load_policy_;
105 enterprise_management::DeviceRegisterRequest::Type registration_type_;
106 base::Closure callback_;
107
108 DISALLOW_COPY_AND_ASSIGN(CloudPolicyClientRegistrationHelper);
109 };
110
111 } // namespace policy
112
113 #endif // CHROME_BROWSER_POLICY_CLOUD_CLOUD_POLICY_CLIENT_REGISTRATION_HELPER_H _
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698