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

Side by Side Diff: chrome/browser/policy/cloud_policy_client.h

Issue 9109009: Introduce CloudPolicyClient (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments. Created 8 years, 8 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
(Empty)
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.
4
5 #ifndef CHROME_BROWSER_POLICY_CLOUD_POLICY_CLIENT_H_
6 #define CHROME_BROWSER_POLICY_CLOUD_POLICY_CLIENT_H_
7 #pragma once
8
9 #include <string>
10
11 #include "base/basictypes.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/observer_list.h"
14 #include "base/time.h"
15 #include "chrome/browser/policy/cloud_policy_constants.h"
16
17 namespace enterprise_management {
18 class DeviceManagementResponse;
19 class DeviceRegisterRequest;
20 class DeviceStatusReportRequest;
21 class PolicyFetchRequest;
22 class PolicyFetchResponse;
23 class SessionStatusReportRequest;
24 }
25
26 namespace policy {
27
28 class DeviceManagementRequestJob;
29 class DeviceManagementService;
30 class MockCloudPolicyClient;
31
32 // Implements the core logic required to talk to the device management service.
33 // Also keeps track of the current state of the association with the service,
34 // such as whether there is a valid registration (DMToken is present in that
35 // case) and whether and what errors occurred in the latest request.
36 //
37 // Note that CloudPolicyClient doesn't do any validation of policy responses
38 // such as signature and time stamp checks. These happen once the policy gets
39 // installed in the cloud policy cache.
40 class CloudPolicyClient {
41 public:
42 // Indicates whether to register for user or device policy.
43 enum PolicyScope {
44 POLICY_SCOPE_USER,
45 POLICY_SCOPE_DEVICE,
Joao da Silva 2012/04/16 23:45:00 Use the constants from policy_map.h?
Mattias Nissler (ping if slow) 2012/05/22 14:05:26 I'm on the fence, because PolicyMap isn't a depend
Joao da Silva 2012/05/22 20:59:30 That's cool.
46 };
47
48 // Container for public key version and validity flag.
49 class PublicKeyVersion {
50 public:
51 // Constructs and invalid public key version.
52 PublicKeyVersion();
53 // Create a valid public key version object.
54 explicit PublicKeyVersion(int version);
55
56 // Copy constructor and assignment operator so this can be passed by value.
57 explicit PublicKeyVersion(const PublicKeyVersion& other);
58 const PublicKeyVersion& operator=(const PublicKeyVersion& other);
59
60 bool valid() const { return valid_; }
61 int version() const { return version_; }
62
63 private:
64 bool valid_;
65 int version_;
66 };
67
68 // Observer interface for state and policy changes.
69 class Observer {
70 public:
71 virtual ~Observer();
72
73 // Called when a policy fetch completes.
74 virtual void OnPolicyFetched(CloudPolicyClient* client) = 0;
75
76 // Called upon registration state changes.
77 virtual void OnRegistrationStateChanged(CloudPolicyClient* client) = 0;
78
79 // Indicates there's been an error.
80 virtual void OnClientError(CloudPolicyClient* client) = 0;
81 };
82
83 // Delegate interface for supplying status information to upload to the server
84 // as part of the policy fetch request.
85 class StatusProvider {
86 public:
87 virtual ~StatusProvider();
88
89 // Retrieves status information to send with the next policy fetch.
90 // Implementations must return true if status information was filled in.
91 virtual bool GetDeviceStatus(
92 enterprise_management::DeviceStatusReportRequest* status) = 0;
93 virtual bool GetSessionStatus(
94 enterprise_management::SessionStatusReportRequest* status) = 0;
95
96 // Called after the status information has successfully been submitted to
97 // the server.
98 virtual void OnSubmittedSuccessfully() = 0;
99 };
100
101 // |provider| and |service| are weak pointers and it's the caller's
102 // responsibility to keep them valid for the lifetime of CloudPolicyClient.
103 CloudPolicyClient(const std::string& machine_id,
104 const std::string& machine_model,
105 UserAffiliation user_affiliation,
Joao da Silva 2012/04/16 23:45:00 This changes after enrollment. Will the owner of t
Mattias Nissler (ping if slow) 2012/05/22 14:05:26 The assumption is that we bring up the client once
106 PolicyScope scope,
107 StatusProvider* provider,
108 DeviceManagementService* service);
109 virtual ~CloudPolicyClient();
110
111 // Sets the DMToken, thereby establishing a registration with the server. A
112 // policy fetch is not automatically issued but can be requested by calling
113 // FetchPolicy().
114 virtual void SetupRegistration(const std::string& dm_token,
115 const std::string& client_id);
116
117 // Attempts to register with the device management service. Results in a
118 // registration change or error notification.
119 virtual void Register(const std::string& auth_token);
120
121 // Requests a policy fetch. The client being registered is a prerequisite to
122 // this operation and this call will CHECK if the client is not in registered
123 // state. FetchPolicy() triggers a policy fetch from the cloud. A policy
124 // change notification is reported to the observers and the new policy blob
125 // can be retrieved once the policy fetch operation completes. In case of
126 // multiple requests to fetch policy, new requests will cancel any pending
127 // requests and the latest request will eventually trigger notifications.
128 virtual void FetchPolicy();
129
130 // Sends an unregistration request to the server.
131 virtual void Unregister();
132
133 // Adds an observer to be called back upon policy and state changes.
134 void AddObserver(Observer* observer);
135
136 // Removes the specified observer.
137 void RemoveObserver(Observer* observer);
138
139 void set_submit_machine_id(bool submit_machine_id) {
140 submit_machine_id_ = submit_machine_id;
141 }
142
143 void set_last_fetch_timestamp(const base::Time& timestamp) {
144 last_fetch_timestamp_ = timestamp;
145 }
146
147 void set_public_key_version(const PublicKeyVersion& public_key_version) {
148 public_key_version_ = public_key_version;
149 }
150
151 // Whether the client is registered with the device management service.
152 bool is_registered() const { return !dm_token_.empty(); }
153
154 const enterprise_management::PolicyFetchResponse* policy() const {
155 return policy_.get();
156 }
157
158 DeviceManagementStatus status() const {
159 return status_;
160 }
161
162 protected:
163 // Sets the registration type suitable for the policy scope used.
164 void SetRegistrationType(
165 enterprise_management::DeviceRegisterRequest* request) const;
166
167 // Sets the appropriate policy type in the fetch request.
168 void SetPolicyType(enterprise_management::PolicyFetchRequest* request) const;
169
170 // Callback for registration requests.
171 void OnRegisterCompleted(
172 DeviceManagementStatus status,
173 const enterprise_management::DeviceManagementResponse& response);
174
175 // Callback for policy fetch requests.
176 void OnPolicyFetchCompleted(
177 DeviceManagementStatus status,
178 const enterprise_management::DeviceManagementResponse& response);
179
180 // Callback for unregistration requests.
181 void OnUnregisterCompleted(
182 DeviceManagementStatus status,
183 const enterprise_management::DeviceManagementResponse& response);
184
185 // Observer notification helpers.
186 void NotifyPolicyFetched();
187 void NotifyRegistrationStateChanged();
188 void NotifyClientError();
189
190 // Data necessary for constructing policy requests.
191 const std::string machine_id_;
192 const std::string machine_model_;
193 const UserAffiliation user_affiliation_;
194 const PolicyScope scope_;
195
196 std::string dm_token_;
197 std::string client_id_;
198 bool submit_machine_id_;
199 base::Time last_fetch_timestamp_;
200 PublicKeyVersion public_key_version_;
201
202 // Used for issuing requests to the cloud.
203 DeviceManagementService* service_;
204 scoped_ptr<DeviceManagementRequestJob> request_job_;
205
206 // Status upload data is produced by |status_provider_|.
207 StatusProvider* status_provider_;
208
209 // The policy blob returned by the last policy fetch operation.
210 scoped_ptr<enterprise_management::PolicyFetchResponse> policy_;
211 DeviceManagementStatus status_;
212
213 ObserverList<Observer, true> observers_;
214
215 DISALLOW_COPY_AND_ASSIGN(CloudPolicyClient);
216 };
217
218 } // namespace policy
219
220 #endif // CHROME_BROWSER_POLICY_CLOUD_POLICY_CLIENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698