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

Side by Side Diff: chrome/browser/policy/device_management_backend_impl.cc

Issue 6409040: New policy protobuf protocol. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Ready for review! Created 9 years, 10 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #include "chrome/browser/policy/device_management_backend_impl.h" 5 #include "chrome/browser/policy/device_management_backend_impl.h"
6 6
7 #include <utility> 7 #include <utility>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/stringprintf.h" 10 #include "base/stringprintf.h"
11 #include "net/base/escape.h" 11 #include "net/base/escape.h"
12 #include "net/url_request/url_request_status.h" 12 #include "net/url_request/url_request_status.h"
13 #include "chrome/browser/policy/device_management_service.h" 13 #include "chrome/browser/policy/device_management_service.h"
14 #include "chrome/common/chrome_version_info.h" 14 #include "chrome/common/chrome_version_info.h"
15 15
16 namespace policy { 16 namespace policy {
17 17
18 // Name constants for URL query parameters. 18 // Name constants for URL query parameters.
19 const char DeviceManagementBackendImpl::kParamRequest[] = "request"; 19 const char DeviceManagementBackendImpl::kParamRequest[] = "request";
20 const char DeviceManagementBackendImpl::kParamDeviceType[] = "devicetype"; 20 const char DeviceManagementBackendImpl::kParamDeviceType[] = "devicetype";
21 const char DeviceManagementBackendImpl::kParamAppType[] = "apptype"; 21 const char DeviceManagementBackendImpl::kParamAppType[] = "apptype";
22 const char DeviceManagementBackendImpl::kParamDeviceID[] = "deviceid"; 22 const char DeviceManagementBackendImpl::kParamDeviceID[] = "deviceid";
23 const char DeviceManagementBackendImpl::kParamAgent[] = "agent"; 23 const char DeviceManagementBackendImpl::kParamAgent[] = "agent";
24 24
25 // String constants for the device and app type we report to the server. 25 // String constants for the device and app type we report to the server.
26 const char DeviceManagementBackendImpl::kValueRequestRegister[] = "register"; 26 const char DeviceManagementBackendImpl::kValueRequestRegister[] = "register";
27 const char DeviceManagementBackendImpl::kValueRequestUnregister[] = 27 const char DeviceManagementBackendImpl::kValueRequestUnregister[] =
28 "unregister"; 28 "unregister";
29 const char DeviceManagementBackendImpl::kValueRequestPolicy[] = "policy"; 29 const char DeviceManagementBackendImpl::kValueRequestPolicy[] = "policy";
30 const char DeviceManagementBackendImpl::kValueRequestCloudPolicy[] =
31 "cloud_policy";
30 const char DeviceManagementBackendImpl::kValueDeviceType[] = "Chrome OS"; 32 const char DeviceManagementBackendImpl::kValueDeviceType[] = "Chrome OS";
31 const char DeviceManagementBackendImpl::kValueAppType[] = "Chrome"; 33 const char DeviceManagementBackendImpl::kValueAppType[] = "Chrome";
32 34
33 namespace { 35 namespace {
34 36
35 const char kValueAgent[] = "%s enterprise management client version %s (%s)"; 37 const char kValueAgent[] = "%s enterprise management client version %s (%s)";
36 38
37 const char kPostContentType[] = "application/protobuf"; 39 const char kPostContentType[] = "application/protobuf";
38 40
39 const char kServiceTokenAuthHeader[] = "Authorization: GoogleLogin auth="; 41 const char kServiceTokenAuthHeader[] = "Authorization: GoogleLogin auth=";
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 } 225 }
224 226
225 // Handles device registration jobs. 227 // Handles device registration jobs.
226 class DeviceManagementRegisterJob : public DeviceManagementJobBase { 228 class DeviceManagementRegisterJob : public DeviceManagementJobBase {
227 public: 229 public:
228 DeviceManagementRegisterJob( 230 DeviceManagementRegisterJob(
229 DeviceManagementBackendImpl* backend_impl, 231 DeviceManagementBackendImpl* backend_impl,
230 const std::string& auth_token, 232 const std::string& auth_token,
231 const std::string& device_id, 233 const std::string& device_id,
232 const em::DeviceRegisterRequest& request, 234 const em::DeviceRegisterRequest& request,
233 DeviceManagementBackend::DeviceRegisterResponseDelegate* delegate); 235 DeviceManagementBackend::DeviceRegisterResponseDelegate* delegate)
236 : DeviceManagementJobBase(
237 backend_impl,
238 DeviceManagementBackendImpl::kValueRequestRegister,
239 device_id),
240 delegate_(delegate) {
241 SetAuthToken(auth_token);
242 em::DeviceManagementRequest request_wrapper;
243 request_wrapper.mutable_register_request()->CopyFrom(request);
244 SetPayload(request_wrapper);
245 }
234 virtual ~DeviceManagementRegisterJob() {} 246 virtual ~DeviceManagementRegisterJob() {}
235 247
236 private: 248 private:
237 // DeviceManagementJobBase overrides. 249 // DeviceManagementJobBase overrides.
238 virtual void OnError(DeviceManagementBackend::ErrorCode error) { 250 virtual void OnError(DeviceManagementBackend::ErrorCode error) {
239 delegate_->OnError(error); 251 delegate_->OnError(error);
240 } 252 }
241 virtual void OnResponse(const em::DeviceManagementResponse& response) { 253 virtual void OnResponse(const em::DeviceManagementResponse& response) {
242 delegate_->HandleRegisterResponse(response.register_response()); 254 delegate_->HandleRegisterResponse(response.register_response());
243 } 255 }
244 256
245 DeviceManagementBackend::DeviceRegisterResponseDelegate* delegate_; 257 DeviceManagementBackend::DeviceRegisterResponseDelegate* delegate_;
246 258
247 DISALLOW_COPY_AND_ASSIGN(DeviceManagementRegisterJob); 259 DISALLOW_COPY_AND_ASSIGN(DeviceManagementRegisterJob);
248 }; 260 };
249 261
250 DeviceManagementRegisterJob::DeviceManagementRegisterJob(
251 DeviceManagementBackendImpl* backend_impl,
252 const std::string& auth_token,
253 const std::string& device_id,
254 const em::DeviceRegisterRequest& request,
255 DeviceManagementBackend::DeviceRegisterResponseDelegate* delegate)
256 : DeviceManagementJobBase(
257 backend_impl,
258 DeviceManagementBackendImpl::kValueRequestRegister,
259 device_id),
260 delegate_(delegate) {
261 SetAuthToken(auth_token);
262 em::DeviceManagementRequest request_wrapper;
263 request_wrapper.mutable_register_request()->CopyFrom(request);
264 SetPayload(request_wrapper);
265 }
266
267 // Handles device unregistration jobs. 262 // Handles device unregistration jobs.
268 class DeviceManagementUnregisterJob : public DeviceManagementJobBase { 263 class DeviceManagementUnregisterJob : public DeviceManagementJobBase {
269 public: 264 public:
270 DeviceManagementUnregisterJob( 265 DeviceManagementUnregisterJob(
271 DeviceManagementBackendImpl* backend_impl, 266 DeviceManagementBackendImpl* backend_impl,
272 const std::string& device_id, 267 const std::string& device_id,
273 const std::string& device_management_token, 268 const std::string& device_management_token,
274 const em::DeviceUnregisterRequest& request, 269 const em::DeviceUnregisterRequest& request,
275 DeviceManagementBackend::DeviceUnregisterResponseDelegate* delegate); 270 DeviceManagementBackend::DeviceUnregisterResponseDelegate* delegate)
271 : DeviceManagementJobBase(
272 backend_impl,
273 DeviceManagementBackendImpl::kValueRequestUnregister,
274 device_id),
275 delegate_(delegate) {
276 SetDeviceManagementToken(device_management_token);
277 em::DeviceManagementRequest request_wrapper;
278 request_wrapper.mutable_unregister_request()->CopyFrom(request);
279 SetPayload(request_wrapper);
280 }
276 virtual ~DeviceManagementUnregisterJob() {} 281 virtual ~DeviceManagementUnregisterJob() {}
277 282
278 private: 283 private:
279 // DeviceManagementJobBase overrides. 284 // DeviceManagementJobBase overrides.
280 virtual void OnError(DeviceManagementBackend::ErrorCode error) { 285 virtual void OnError(DeviceManagementBackend::ErrorCode error) {
281 delegate_->OnError(error); 286 delegate_->OnError(error);
282 } 287 }
283 virtual void OnResponse(const em::DeviceManagementResponse& response) { 288 virtual void OnResponse(const em::DeviceManagementResponse& response) {
284 delegate_->HandleUnregisterResponse(response.unregister_response()); 289 delegate_->HandleUnregisterResponse(response.unregister_response());
285 } 290 }
286 291
287 DeviceManagementBackend::DeviceUnregisterResponseDelegate* delegate_; 292 DeviceManagementBackend::DeviceUnregisterResponseDelegate* delegate_;
288 293
289 DISALLOW_COPY_AND_ASSIGN(DeviceManagementUnregisterJob); 294 DISALLOW_COPY_AND_ASSIGN(DeviceManagementUnregisterJob);
290 }; 295 };
291 296
292 DeviceManagementUnregisterJob::DeviceManagementUnregisterJob(
293 DeviceManagementBackendImpl* backend_impl,
294 const std::string& device_management_token,
295 const std::string& device_id,
296 const em::DeviceUnregisterRequest& request,
297 DeviceManagementBackend::DeviceUnregisterResponseDelegate* delegate)
298 : DeviceManagementJobBase(
299 backend_impl,
300 DeviceManagementBackendImpl::kValueRequestUnregister,
301 device_id),
302 delegate_(delegate) {
303 SetDeviceManagementToken(device_management_token);
304 em::DeviceManagementRequest request_wrapper;
305 request_wrapper.mutable_unregister_request()->CopyFrom(request);
306 SetPayload(request_wrapper);
307 }
308
309 // Handles policy request jobs. 297 // Handles policy request jobs.
310 class DeviceManagementPolicyJob : public DeviceManagementJobBase { 298 class DeviceManagementPolicyJob : public DeviceManagementJobBase {
311 public: 299 public:
312 DeviceManagementPolicyJob( 300 DeviceManagementPolicyJob(
313 DeviceManagementBackendImpl* backend_impl, 301 DeviceManagementBackendImpl* backend_impl,
314 const std::string& device_management_token, 302 const std::string& device_management_token,
315 const std::string& device_id, 303 const std::string& device_id,
316 const em::DevicePolicyRequest& request, 304 const em::DevicePolicyRequest& request,
317 DeviceManagementBackend::DevicePolicyResponseDelegate* delegate); 305 DeviceManagementBackend::DevicePolicyResponseDelegate* delegate)
306 : DeviceManagementJobBase(
307 backend_impl,
308 DeviceManagementBackendImpl::kValueRequestPolicy,
309 device_id),
310 delegate_(delegate) {
311 SetDeviceManagementToken(device_management_token);
312 em::DeviceManagementRequest request_wrapper;
313 request_wrapper.mutable_policy_request()->CopyFrom(request);
314 SetPayload(request_wrapper);
315 }
318 virtual ~DeviceManagementPolicyJob() {} 316 virtual ~DeviceManagementPolicyJob() {}
319 317
320 private: 318 private:
321 // DeviceManagementJobBase overrides. 319 // DeviceManagementJobBase overrides.
322 virtual void OnError(DeviceManagementBackend::ErrorCode error) { 320 virtual void OnError(DeviceManagementBackend::ErrorCode error) {
323 delegate_->OnError(error); 321 delegate_->OnError(error);
324 } 322 }
325 virtual void OnResponse(const em::DeviceManagementResponse& response) { 323 virtual void OnResponse(const em::DeviceManagementResponse& response) {
326 delegate_->HandlePolicyResponse(response.policy_response()); 324 delegate_->HandlePolicyResponse(response.policy_response());
327 } 325 }
328 326
329 DeviceManagementBackend::DevicePolicyResponseDelegate* delegate_; 327 DeviceManagementBackend::DevicePolicyResponseDelegate* delegate_;
330 328
331 DISALLOW_COPY_AND_ASSIGN(DeviceManagementPolicyJob); 329 DISALLOW_COPY_AND_ASSIGN(DeviceManagementPolicyJob);
332 }; 330 };
333 331
334 DeviceManagementPolicyJob::DeviceManagementPolicyJob( 332 // Handles cloud policy request jobs.
335 DeviceManagementBackendImpl* backend_impl, 333 class CloudPolicyJob : public DeviceManagementJobBase {
336 const std::string& device_management_token, 334 public:
337 const std::string& device_id, 335 CloudPolicyJob(
338 const em::DevicePolicyRequest& request, 336 DeviceManagementBackendImpl* backend_impl,
339 DeviceManagementBackend::DevicePolicyResponseDelegate* delegate) 337 const std::string& device_management_token,
340 : DeviceManagementJobBase( 338 const std::string& device_id,
339 const em::CloudPolicyRequest& request,
340 DeviceManagementBackend::DevicePolicyResponseDelegate* delegate)
341 : DeviceManagementJobBase(
341 backend_impl, 342 backend_impl,
342 DeviceManagementBackendImpl::kValueRequestPolicy, 343 DeviceManagementBackendImpl::kValueRequestCloudPolicy,
343 device_id), 344 device_id),
344 delegate_(delegate) { 345 delegate_(delegate) {
345 SetDeviceManagementToken(device_management_token); 346 SetDeviceManagementToken(device_management_token);
346 em::DeviceManagementRequest request_wrapper; 347 em::DeviceManagementRequest request_wrapper;
347 request_wrapper.mutable_policy_request()->CopyFrom(request); 348 request_wrapper.mutable_cloud_policy_request()->CopyFrom(request);
348 SetPayload(request_wrapper); 349 SetPayload(request_wrapper);
349 } 350 }
351 virtual ~CloudPolicyJob() {}
352
353 private:
354 // DeviceManagementJobBase overrides.
355 virtual void OnError(DeviceManagementBackend::ErrorCode error) {
356 delegate_->OnError(error);
357 }
358 virtual void OnResponse(const em::DeviceManagementResponse& response) {
359 delegate_->HandleCloudPolicyResponse(response.cloud_policy_response());
360 }
361
362 DeviceManagementBackend::DevicePolicyResponseDelegate* delegate_;
363
364 DISALLOW_COPY_AND_ASSIGN(CloudPolicyJob);
365 };
350 366
351 DeviceManagementBackendImpl::DeviceManagementBackendImpl( 367 DeviceManagementBackendImpl::DeviceManagementBackendImpl(
352 DeviceManagementService* service) 368 DeviceManagementService* service)
353 : service_(service) { 369 : service_(service) {
354 } 370 }
355 371
356 DeviceManagementBackendImpl::~DeviceManagementBackendImpl() { 372 DeviceManagementBackendImpl::~DeviceManagementBackendImpl() {
357 // Swap to a helper, so we don't interfere with the unregistration on delete. 373 // Swap to a helper, so we don't interfere with the unregistration on delete.
358 JobSet to_be_deleted; 374 JobSet to_be_deleted;
359 to_be_deleted.swap(pending_jobs_); 375 to_be_deleted.swap(pending_jobs_);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 418
403 void DeviceManagementBackendImpl::ProcessPolicyRequest( 419 void DeviceManagementBackendImpl::ProcessPolicyRequest(
404 const std::string& device_management_token, 420 const std::string& device_management_token,
405 const std::string& device_id, 421 const std::string& device_id,
406 const em::DevicePolicyRequest& request, 422 const em::DevicePolicyRequest& request,
407 DevicePolicyResponseDelegate* delegate) { 423 DevicePolicyResponseDelegate* delegate) {
408 AddJob(new DeviceManagementPolicyJob(this, device_management_token, device_id, 424 AddJob(new DeviceManagementPolicyJob(this, device_management_token, device_id,
409 request, delegate)); 425 request, delegate));
410 } 426 }
411 427
428 void DeviceManagementBackendImpl::ProcessCloudPolicyRequest(
429 const std::string& device_management_token,
430 const std::string& device_id,
431 const em::CloudPolicyRequest& request,
432 DevicePolicyResponseDelegate* delegate) {
433 AddJob(new CloudPolicyJob(this, device_management_token, device_id,
434 request, delegate));
435 }
436
412 } // namespace policy 437 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698