OLD | NEW |
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_CLOUD_POLICY_CLIENT_H_ | 5 #ifndef COMPONENTS_POLICY_CORE_COMMON_CLOUD_CLOUD_POLICY_CLIENT_H_ |
6 #define COMPONENTS_POLICY_CORE_COMMON_CLOUD_CLOUD_POLICY_CLIENT_H_ | 6 #define COMPONENTS_POLICY_CORE_COMMON_CLOUD_CLOUD_POLICY_CLIENT_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 | 63 |
64 // Called when a request for device robot OAuth2 authorization tokens | 64 // Called when a request for device robot OAuth2 authorization tokens |
65 // returns successfully. Only occurs during enrollment. Optional | 65 // returns successfully. Only occurs during enrollment. Optional |
66 // (default implementation is a noop). | 66 // (default implementation is a noop). |
67 virtual void OnRobotAuthCodesFetched(CloudPolicyClient* client); | 67 virtual void OnRobotAuthCodesFetched(CloudPolicyClient* client); |
68 | 68 |
69 // Indicates there's been an error in a previously-issued request. | 69 // Indicates there's been an error in a previously-issued request. |
70 virtual void OnClientError(CloudPolicyClient* client) = 0; | 70 virtual void OnClientError(CloudPolicyClient* client) = 0; |
71 }; | 71 }; |
72 | 72 |
73 // Delegate interface for supplying status information to upload to the server | |
74 // as part of the policy fetch request. | |
75 class POLICY_EXPORT StatusProvider { | |
76 public: | |
77 virtual ~StatusProvider(); | |
78 | |
79 // Retrieves status information to send with the next policy fetch. | |
80 // Implementations must return true if status information was filled in. | |
81 virtual bool GetDeviceStatus( | |
82 enterprise_management::DeviceStatusReportRequest* status) = 0; | |
83 virtual bool GetSessionStatus( | |
84 enterprise_management::SessionStatusReportRequest* status) = 0; | |
85 | |
86 // Called after the status information has successfully been submitted to | |
87 // the server. | |
88 virtual void OnSubmittedSuccessfully() = 0; | |
89 }; | |
90 | |
91 // |provider| and |service| are weak pointers and it's the caller's | 73 // |provider| and |service| are weak pointers and it's the caller's |
92 // responsibility to keep them valid for the lifetime of CloudPolicyClient. | 74 // responsibility to keep them valid for the lifetime of CloudPolicyClient. |
93 // |verification_key_hash| contains an identifier telling the DMServer which | 75 // |verification_key_hash| contains an identifier telling the DMServer which |
94 // verification key to use. | 76 // verification key to use. |
95 CloudPolicyClient( | 77 CloudPolicyClient( |
96 const std::string& machine_id, | 78 const std::string& machine_id, |
97 const std::string& machine_model, | 79 const std::string& machine_model, |
98 const std::string& verification_key_hash, | 80 const std::string& verification_key_hash, |
99 UserAffiliation user_affiliation, | 81 UserAffiliation user_affiliation, |
100 DeviceManagementService* service, | 82 DeviceManagementService* service, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 // Sends an unregistration request to the server. | 121 // Sends an unregistration request to the server. |
140 virtual void Unregister(); | 122 virtual void Unregister(); |
141 | 123 |
142 // Upload a device certificate to the server. Like FetchPolicy, this method | 124 // Upload a device certificate to the server. Like FetchPolicy, this method |
143 // requires that the client is in a registered state. |certificate_data| must | 125 // requires that the client is in a registered state. |certificate_data| must |
144 // hold the X.509 certificate data to be sent to the server. The |callback| | 126 // hold the X.509 certificate data to be sent to the server. The |callback| |
145 // will be called when the operation completes. | 127 // will be called when the operation completes. |
146 virtual void UploadCertificate(const std::string& certificate_data, | 128 virtual void UploadCertificate(const std::string& certificate_data, |
147 const StatusCallback& callback); | 129 const StatusCallback& callback); |
148 | 130 |
| 131 // Uploads device/session status to the server. As above, the client must be |
| 132 // in a registered state. If non-null, |device_status| and |session_status| |
| 133 // will be included in the upload status request. The |callback| will be |
| 134 // called when the operation completes. |
| 135 virtual void UploadDeviceStatus( |
| 136 const enterprise_management::DeviceStatusReportRequest* device_status, |
| 137 const enterprise_management::SessionStatusReportRequest* session_status, |
| 138 const StatusCallback& callback); |
| 139 |
149 // Adds an observer to be called back upon policy and state changes. | 140 // Adds an observer to be called back upon policy and state changes. |
150 void AddObserver(Observer* observer); | 141 void AddObserver(Observer* observer); |
151 | 142 |
152 // Removes the specified observer. | 143 // Removes the specified observer. |
153 void RemoveObserver(Observer* observer); | 144 void RemoveObserver(Observer* observer); |
154 | 145 |
155 // Sets the status provider for this client, or NULL if no provider. | |
156 // ClouldPolicyClient takes ownership of the passed |provider|. | |
157 void SetStatusProvider(scoped_ptr<StatusProvider> provider); | |
158 | |
159 // Returns true if this object has a StatusProvider configured. | |
160 bool HasStatusProviderForTest(); | |
161 | |
162 void set_submit_machine_id(bool submit_machine_id) { | 146 void set_submit_machine_id(bool submit_machine_id) { |
163 submit_machine_id_ = submit_machine_id; | 147 submit_machine_id_ = submit_machine_id; |
164 } | 148 } |
165 | 149 |
166 void set_last_policy_timestamp(const base::Time& timestamp) { | 150 void set_last_policy_timestamp(const base::Time& timestamp) { |
167 last_policy_timestamp_ = timestamp; | 151 last_policy_timestamp_ = timestamp; |
168 } | 152 } |
169 | 153 |
170 void set_public_key_version(int public_key_version) { | 154 void set_public_key_version(int public_key_version) { |
171 public_key_version_ = public_key_version; | 155 public_key_version_ = public_key_version; |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 int net_error, | 247 int net_error, |
264 const enterprise_management::DeviceManagementResponse& response); | 248 const enterprise_management::DeviceManagementResponse& response); |
265 | 249 |
266 // Callback for certificate upload requests. | 250 // Callback for certificate upload requests. |
267 void OnCertificateUploadCompleted( | 251 void OnCertificateUploadCompleted( |
268 const StatusCallback& callback, | 252 const StatusCallback& callback, |
269 DeviceManagementStatus status, | 253 DeviceManagementStatus status, |
270 int net_error, | 254 int net_error, |
271 const enterprise_management::DeviceManagementResponse& response); | 255 const enterprise_management::DeviceManagementResponse& response); |
272 | 256 |
| 257 // Callback for status upload requests. |
| 258 void OnStatusUploadCompleted( |
| 259 const StatusCallback& callback, |
| 260 DeviceManagementStatus status, |
| 261 int net_error, |
| 262 const enterprise_management::DeviceManagementResponse& response); |
| 263 |
273 // Observer notification helpers. | 264 // Observer notification helpers. |
274 void NotifyPolicyFetched(); | 265 void NotifyPolicyFetched(); |
275 void NotifyRegistrationStateChanged(); | 266 void NotifyRegistrationStateChanged(); |
276 void NotifyRobotAuthCodesFetched(); | 267 void NotifyRobotAuthCodesFetched(); |
277 void NotifyClientError(); | 268 void NotifyClientError(); |
278 | 269 |
279 // Data necessary for constructing policy requests. | 270 // Data necessary for constructing policy requests. |
280 const std::string machine_id_; | 271 const std::string machine_id_; |
281 const std::string machine_model_; | 272 const std::string machine_model_; |
282 const std::string verification_key_hash_; | 273 const std::string verification_key_hash_; |
(...skipping 14 matching lines...) Expand all Loading... |
297 int64 invalidation_version_; | 288 int64 invalidation_version_; |
298 std::string invalidation_payload_; | 289 std::string invalidation_payload_; |
299 | 290 |
300 // The invalidation version used for the most recent fetch operation. | 291 // The invalidation version used for the most recent fetch operation. |
301 int64 fetched_invalidation_version_; | 292 int64 fetched_invalidation_version_; |
302 | 293 |
303 // Used for issuing requests to the cloud. | 294 // Used for issuing requests to the cloud. |
304 DeviceManagementService* service_; | 295 DeviceManagementService* service_; |
305 scoped_ptr<DeviceManagementRequestJob> request_job_; | 296 scoped_ptr<DeviceManagementRequestJob> request_job_; |
306 | 297 |
307 // Status upload data is produced by |status_provider_|. | |
308 scoped_ptr<StatusProvider> status_provider_; | |
309 | |
310 // The policy responses returned by the last policy fetch operation. | 298 // The policy responses returned by the last policy fetch operation. |
311 ResponseMap responses_; | 299 ResponseMap responses_; |
312 DeviceManagementStatus status_; | 300 DeviceManagementStatus status_; |
313 | 301 |
314 ObserverList<Observer, true> observers_; | 302 ObserverList<Observer, true> observers_; |
315 scoped_refptr<net::URLRequestContextGetter> request_context_; | 303 scoped_refptr<net::URLRequestContextGetter> request_context_; |
316 | 304 |
317 private: | 305 private: |
318 DISALLOW_COPY_AND_ASSIGN(CloudPolicyClient); | 306 DISALLOW_COPY_AND_ASSIGN(CloudPolicyClient); |
319 }; | 307 }; |
320 | 308 |
321 } // namespace policy | 309 } // namespace policy |
322 | 310 |
323 #endif // COMPONENTS_POLICY_CORE_COMMON_CLOUD_CLOUD_POLICY_CLIENT_H_ | 311 #endif // COMPONENTS_POLICY_CORE_COMMON_CLOUD_CLOUD_POLICY_CLIENT_H_ |
OLD | NEW |