OLD | NEW |
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 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 10 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
(...skipping 16 matching lines...) Expand all Loading... |
27 namespace policy { | 27 namespace policy { |
28 | 28 |
29 // Name constants for URL query parameters. | 29 // Name constants for URL query parameters. |
30 const char DeviceManagementBackendImpl::kParamAgent[] = "agent"; | 30 const char DeviceManagementBackendImpl::kParamAgent[] = "agent"; |
31 const char DeviceManagementBackendImpl::kParamAppType[] = "apptype"; | 31 const char DeviceManagementBackendImpl::kParamAppType[] = "apptype"; |
32 const char DeviceManagementBackendImpl::kParamDeviceID[] = "deviceid"; | 32 const char DeviceManagementBackendImpl::kParamDeviceID[] = "deviceid"; |
33 const char DeviceManagementBackendImpl::kParamDeviceType[] = "devicetype"; | 33 const char DeviceManagementBackendImpl::kParamDeviceType[] = "devicetype"; |
34 const char DeviceManagementBackendImpl::kParamOAuthToken[] = "oauth_token"; | 34 const char DeviceManagementBackendImpl::kParamOAuthToken[] = "oauth_token"; |
35 const char DeviceManagementBackendImpl::kParamPlatform[] = "platform"; | 35 const char DeviceManagementBackendImpl::kParamPlatform[] = "platform"; |
36 const char DeviceManagementBackendImpl::kParamRequest[] = "request"; | 36 const char DeviceManagementBackendImpl::kParamRequest[] = "request"; |
| 37 const char DeviceManagementBackendImpl::kParamUserAffiliation[] = |
| 38 "user_affiliation"; |
37 | 39 |
38 // String constants for the device and app type we report to the server. | 40 // String constants for the device and app type we report to the server. |
39 const char DeviceManagementBackendImpl::kValueAppType[] = "Chrome"; | 41 const char DeviceManagementBackendImpl::kValueAppType[] = "Chrome"; |
40 const char DeviceManagementBackendImpl::kValueDeviceType[] = "2"; | 42 const char DeviceManagementBackendImpl::kValueDeviceType[] = "2"; |
41 const char DeviceManagementBackendImpl::kValueRequestPolicy[] = "policy"; | 43 const char DeviceManagementBackendImpl::kValueRequestPolicy[] = "policy"; |
42 const char DeviceManagementBackendImpl::kValueRequestRegister[] = "register"; | 44 const char DeviceManagementBackendImpl::kValueRequestRegister[] = "register"; |
43 const char DeviceManagementBackendImpl::kValueRequestUnregister[] = | 45 const char DeviceManagementBackendImpl::kValueRequestUnregister[] = |
44 "unregister"; | 46 "unregister"; |
| 47 const char DeviceManagementBackendImpl::kValueUserAffiliationManaged[] = |
| 48 "managed"; |
| 49 const char DeviceManagementBackendImpl::kValueUserAffiliationNone[] = "none"; |
45 | 50 |
46 namespace { | 51 namespace { |
47 | 52 |
48 const char kValueAgent[] = "%s %s(%s)"; | 53 const char kValueAgent[] = "%s %s(%s)"; |
49 const char kValuePlatform[] = "%s|%s|%s"; | 54 const char kValuePlatform[] = "%s|%s|%s"; |
50 | 55 |
51 const char kPostContentType[] = "application/protobuf"; | 56 const char kPostContentType[] = "application/protobuf"; |
52 | 57 |
53 const char kServiceTokenAuthHeader[] = "Authorization: GoogleLogin auth="; | 58 const char kServiceTokenAuthHeader[] = "Authorization: GoogleLogin auth="; |
54 const char kDMTokenAuthHeader[] = "Authorization: GoogleDMToken token="; | 59 const char kDMTokenAuthHeader[] = "Authorization: GoogleDMToken token="; |
55 | 60 |
56 // HTTP Error Codes of the DM Server with their concrete meinings in the context | 61 // HTTP Error Codes of the DM Server with their concrete meinings in the context |
57 // of the DM Server communication. | 62 // of the DM Server communication. |
58 const int kSuccess = 200; | 63 const int kSuccess = 200; |
59 const int kInvalidArgument = 400; | 64 const int kInvalidArgument = 400; |
60 const int kInvalidAuthCookieOrDMToken = 401; | 65 const int kInvalidAuthCookieOrDMToken = 401; |
61 const int kDeviceManagementNotAllowed = 403; | 66 const int kDeviceManagementNotAllowed = 403; |
62 const int kInvalidURL = 404; // This error is not coming from the GFE. | 67 const int kInvalidURL = 404; // This error is not coming from the GFE. |
63 const int kDeviceNotFound = 410; | 68 const int kDeviceNotFound = 410; |
64 const int kPendingApproval = 412; | 69 const int kPendingApproval = 412; |
65 const int kInternalServerError = 500; | 70 const int kInternalServerError = 500; |
66 const int kServiceUnavailable = 503; | 71 const int kServiceUnavailable = 503; |
67 const int kPolicyNotFound = 902; // This error is not sent as HTTP status code. | 72 const int kPolicyNotFound = 902; // This error is not sent as HTTP status code. |
68 | 73 |
69 // TODO(pastarmovj): Legacy error codes are here for comaptibility only. They | 74 // TODO(pastarmovj): Legacy error codes are here for comaptibility only. They |
70 // should be removed once the DM Server has been updated. | 75 // should be removed once the DM Server has been updated. |
71 const int kPendingApprovalLegacy = 491; | 76 const int kPendingApprovalLegacy = 491; |
72 const int kDeviceNotFoundLegacy = 901; | 77 const int kDeviceNotFoundLegacy = 901; |
73 | 78 |
74 | |
75 #if defined(OS_CHROMEOS) | 79 #if defined(OS_CHROMEOS) |
76 // Machine info keys. | 80 // Machine info keys. |
77 const char kMachineInfoHWClass[] = "hardware_class"; | 81 const char kMachineInfoHWClass[] = "hardware_class"; |
78 const char kMachineInfoBoard[] = "CHROMEOS_RELEASE_BOARD"; | 82 const char kMachineInfoBoard[] = "CHROMEOS_RELEASE_BOARD"; |
79 #endif | 83 #endif |
80 | 84 |
81 } // namespace | 85 } // namespace |
82 | 86 |
83 // Helper class for URL query parameter encoding/decoding. | 87 // Helper class for URL query parameter encoding/decoding. |
84 class URLQueryParameters { | 88 class URLQueryParameters { |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 DISALLOW_COPY_AND_ASSIGN(DeviceManagementUnregisterJob); | 381 DISALLOW_COPY_AND_ASSIGN(DeviceManagementUnregisterJob); |
378 }; | 382 }; |
379 | 383 |
380 // Handles policy request jobs. | 384 // Handles policy request jobs. |
381 class DeviceManagementPolicyJob : public DeviceManagementJobBase { | 385 class DeviceManagementPolicyJob : public DeviceManagementJobBase { |
382 public: | 386 public: |
383 DeviceManagementPolicyJob( | 387 DeviceManagementPolicyJob( |
384 DeviceManagementBackendImpl* backend_impl, | 388 DeviceManagementBackendImpl* backend_impl, |
385 const std::string& device_management_token, | 389 const std::string& device_management_token, |
386 const std::string& device_id, | 390 const std::string& device_id, |
| 391 const std::string& user_affiliation, |
387 const em::DevicePolicyRequest& request, | 392 const em::DevicePolicyRequest& request, |
388 DeviceManagementBackend::DevicePolicyResponseDelegate* delegate) | 393 DeviceManagementBackend::DevicePolicyResponseDelegate* delegate) |
389 : DeviceManagementJobBase( | 394 : DeviceManagementJobBase( |
390 backend_impl, | 395 backend_impl, |
391 DeviceManagementBackendImpl::kValueRequestPolicy, | 396 DeviceManagementBackendImpl::kValueRequestPolicy, |
392 device_id), | 397 device_id), |
393 delegate_(delegate) { | 398 delegate_(delegate) { |
394 SetDeviceManagementToken(device_management_token); | 399 SetDeviceManagementToken(device_management_token); |
| 400 SetQueryParam(DeviceManagementBackendImpl::kParamUserAffiliation, |
| 401 user_affiliation); |
395 em::DeviceManagementRequest request_wrapper; | 402 em::DeviceManagementRequest request_wrapper; |
396 request_wrapper.mutable_policy_request()->CopyFrom(request); | 403 request_wrapper.mutable_policy_request()->CopyFrom(request); |
397 SetPayload(request_wrapper); | 404 SetPayload(request_wrapper); |
398 } | 405 } |
399 virtual ~DeviceManagementPolicyJob() {} | 406 virtual ~DeviceManagementPolicyJob() {} |
400 | 407 |
401 private: | 408 private: |
402 // DeviceManagementJobBase overrides. | 409 // DeviceManagementJobBase overrides. |
403 virtual void OnError(DeviceManagementBackend::ErrorCode error) { | 410 virtual void OnError(DeviceManagementBackend::ErrorCode error) { |
404 MetricPolicy sample; | 411 MetricPolicy sample; |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
531 const std::string& device_id, | 538 const std::string& device_id, |
532 const em::DeviceUnregisterRequest& request, | 539 const em::DeviceUnregisterRequest& request, |
533 DeviceUnregisterResponseDelegate* delegate) { | 540 DeviceUnregisterResponseDelegate* delegate) { |
534 AddJob(new DeviceManagementUnregisterJob(this, device_management_token, | 541 AddJob(new DeviceManagementUnregisterJob(this, device_management_token, |
535 device_id, request, delegate)); | 542 device_id, request, delegate)); |
536 } | 543 } |
537 | 544 |
538 void DeviceManagementBackendImpl::ProcessPolicyRequest( | 545 void DeviceManagementBackendImpl::ProcessPolicyRequest( |
539 const std::string& device_management_token, | 546 const std::string& device_management_token, |
540 const std::string& device_id, | 547 const std::string& device_id, |
| 548 CloudPolicyDataStore::UserAffiliation affiliation, |
541 const em::DevicePolicyRequest& request, | 549 const em::DevicePolicyRequest& request, |
542 DevicePolicyResponseDelegate* delegate) { | 550 DevicePolicyResponseDelegate* delegate) { |
543 UMA_HISTOGRAM_ENUMERATION(kMetricPolicy, kMetricPolicyFetchRequested, | 551 UMA_HISTOGRAM_ENUMERATION(kMetricPolicy, kMetricPolicyFetchRequested, |
544 kMetricPolicySize); | 552 kMetricPolicySize); |
545 AddJob(new DeviceManagementPolicyJob(this, device_management_token, device_id, | 553 AddJob(new DeviceManagementPolicyJob(this, device_management_token, device_id, |
| 554 UserAffiliationToString(affiliation), |
546 request, delegate)); | 555 request, delegate)); |
547 } | 556 } |
548 | 557 |
| 558 // static |
| 559 const char* DeviceManagementBackendImpl::UserAffiliationToString( |
| 560 CloudPolicyDataStore::UserAffiliation affiliation) { |
| 561 switch (affiliation) { |
| 562 case CloudPolicyDataStore::USER_AFFILIATION_MANAGED: |
| 563 return kValueUserAffiliationManaged; |
| 564 case CloudPolicyDataStore::USER_AFFILIATION_NONE: |
| 565 return kValueUserAffiliationNone; |
| 566 } |
| 567 NOTREACHED(); |
| 568 return kValueUserAffiliationNone; |
| 569 } |
| 570 |
549 } // namespace policy | 571 } // namespace policy |
OLD | NEW |