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

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

Issue 6537020: Update policy backend and testserver for the newest policy protocol (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 5 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[] = 30 const char DeviceManagementBackendImpl::kValueDeviceType[] = "2";
31 "cloud_policy";
32 const char DeviceManagementBackendImpl::kValueDeviceType[] = "Chrome OS";
33 const char DeviceManagementBackendImpl::kValueAppType[] = "Chrome"; 31 const char DeviceManagementBackendImpl::kValueAppType[] = "Chrome";
34 32
33 const char DeviceManagementBackendImpl::kValueMachineModel[] = "Chrome OS";
34
35 namespace { 35 namespace {
36 36
37 const char kValueAgent[] = "%s enterprise management client version %s (%s)"; 37 const char kValueAgent[] = "%s enterprise management client %s (%s)";
38 38
39 const char kPostContentType[] = "application/protobuf"; 39 const char kPostContentType[] = "application/protobuf";
40 40
41 const char kServiceTokenAuthHeader[] = "Authorization: GoogleLogin auth="; 41 const char kServiceTokenAuthHeader[] = "Authorization: GoogleLogin auth=";
42 const char kDMTokenAuthHeader[] = "Authorization: GoogleDMToken token="; 42 const char kDMTokenAuthHeader[] = "Authorization: GoogleDMToken token=";
43 43
44 } // namespace 44 } // namespace
45 45
46 // Helper class for URL query parameter encoding/decoding. 46 // Helper class for URL query parameter encoding/decoding.
47 class URLQueryParameters { 47 class URLQueryParameters {
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 const em::DeviceRegisterRequest& request, 237 const em::DeviceRegisterRequest& request,
238 DeviceManagementBackend::DeviceRegisterResponseDelegate* delegate) 238 DeviceManagementBackend::DeviceRegisterResponseDelegate* delegate)
239 : DeviceManagementJobBase( 239 : DeviceManagementJobBase(
240 backend_impl, 240 backend_impl,
241 DeviceManagementBackendImpl::kValueRequestRegister, 241 DeviceManagementBackendImpl::kValueRequestRegister,
242 device_id), 242 device_id),
243 delegate_(delegate) { 243 delegate_(delegate) {
244 SetAuthToken(auth_token); 244 SetAuthToken(auth_token);
245 em::DeviceManagementRequest request_wrapper; 245 em::DeviceManagementRequest request_wrapper;
246 request_wrapper.mutable_register_request()->CopyFrom(request); 246 request_wrapper.mutable_register_request()->CopyFrom(request);
247 request_wrapper.mutable_register_request()->set_machine_model(
248 DeviceManagementBackendImpl::kValueMachineModel);
247 SetPayload(request_wrapper); 249 SetPayload(request_wrapper);
248 } 250 }
249 virtual ~DeviceManagementRegisterJob() {} 251 virtual ~DeviceManagementRegisterJob() {}
250 252
251 private: 253 private:
252 // DeviceManagementJobBase overrides. 254 // DeviceManagementJobBase overrides.
253 virtual void OnError(DeviceManagementBackend::ErrorCode error) { 255 virtual void OnError(DeviceManagementBackend::ErrorCode error) {
254 delegate_->OnError(error); 256 delegate_->OnError(error);
255 } 257 }
256 virtual void OnResponse(const em::DeviceManagementResponse& response) { 258 virtual void OnResponse(const em::DeviceManagementResponse& response) {
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 } 327 }
326 virtual void OnResponse(const em::DeviceManagementResponse& response) { 328 virtual void OnResponse(const em::DeviceManagementResponse& response) {
327 delegate_->HandlePolicyResponse(response.policy_response()); 329 delegate_->HandlePolicyResponse(response.policy_response());
328 } 330 }
329 331
330 DeviceManagementBackend::DevicePolicyResponseDelegate* delegate_; 332 DeviceManagementBackend::DevicePolicyResponseDelegate* delegate_;
331 333
332 DISALLOW_COPY_AND_ASSIGN(DeviceManagementPolicyJob); 334 DISALLOW_COPY_AND_ASSIGN(DeviceManagementPolicyJob);
333 }; 335 };
334 336
335 // Handles cloud policy request jobs.
336 class CloudPolicyJob : public DeviceManagementJobBase {
337 public:
338 CloudPolicyJob(
339 DeviceManagementBackendImpl* backend_impl,
340 const std::string& device_management_token,
341 const std::string& device_id,
342 const em::CloudPolicyRequest& request,
343 DeviceManagementBackend::DevicePolicyResponseDelegate* delegate)
344 : DeviceManagementJobBase(
345 backend_impl,
346 DeviceManagementBackendImpl::kValueRequestCloudPolicy,
347 device_id),
348 delegate_(delegate) {
349 SetDeviceManagementToken(device_management_token);
350 em::DeviceManagementRequest request_wrapper;
351 request_wrapper.mutable_cloud_policy_request()->CopyFrom(request);
352 SetPayload(request_wrapper);
353 }
354 virtual ~CloudPolicyJob() {}
355
356 private:
357 // DeviceManagementJobBase overrides.
358 virtual void OnError(DeviceManagementBackend::ErrorCode error) {
359 delegate_->OnError(error);
360 }
361 virtual void OnResponse(const em::DeviceManagementResponse& response) {
362 delegate_->HandleCloudPolicyResponse(response.cloud_policy_response());
363 }
364
365 DeviceManagementBackend::DevicePolicyResponseDelegate* delegate_;
366
367 DISALLOW_COPY_AND_ASSIGN(CloudPolicyJob);
368 };
369
370 DeviceManagementBackendImpl::DeviceManagementBackendImpl( 337 DeviceManagementBackendImpl::DeviceManagementBackendImpl(
371 DeviceManagementService* service) 338 DeviceManagementService* service)
372 : service_(service) { 339 : service_(service) {
373 } 340 }
374 341
375 DeviceManagementBackendImpl::~DeviceManagementBackendImpl() { 342 DeviceManagementBackendImpl::~DeviceManagementBackendImpl() {
376 // Swap to a helper, so we don't interfere with the unregistration on delete. 343 // Swap to a helper, so we don't interfere with the unregistration on delete.
377 JobSet to_be_deleted; 344 JobSet to_be_deleted;
378 to_be_deleted.swap(pending_jobs_); 345 to_be_deleted.swap(pending_jobs_);
379 for (JobSet::iterator job(to_be_deleted.begin()); 346 for (JobSet::iterator job(to_be_deleted.begin());
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 388
422 void DeviceManagementBackendImpl::ProcessPolicyRequest( 389 void DeviceManagementBackendImpl::ProcessPolicyRequest(
423 const std::string& device_management_token, 390 const std::string& device_management_token,
424 const std::string& device_id, 391 const std::string& device_id,
425 const em::DevicePolicyRequest& request, 392 const em::DevicePolicyRequest& request,
426 DevicePolicyResponseDelegate* delegate) { 393 DevicePolicyResponseDelegate* delegate) {
427 AddJob(new DeviceManagementPolicyJob(this, device_management_token, device_id, 394 AddJob(new DeviceManagementPolicyJob(this, device_management_token, device_id,
428 request, delegate)); 395 request, delegate));
429 } 396 }
430 397
431 void DeviceManagementBackendImpl::ProcessCloudPolicyRequest(
432 const std::string& device_management_token,
433 const std::string& device_id,
434 const em::CloudPolicyRequest& request,
435 DevicePolicyResponseDelegate* delegate) {
436 AddJob(new CloudPolicyJob(this, device_management_token, device_id,
437 request, delegate));
438 }
439
440 } // namespace policy 398 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698