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) | |
11 #include <sys/utsname.h> | |
12 #endif | |
13 | |
14 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
15 #include "base/stringprintf.h" | 11 #include "base/stringprintf.h" |
16 #include "base/sys_info.h" | 12 #include "base/sys_info.h" |
17 #include "chrome/browser/policy/device_management_service.h" | 13 #include "chrome/browser/policy/device_management_service.h" |
18 #include "chrome/browser/policy/enterprise_metrics.h" | 14 #include "chrome/browser/policy/enterprise_metrics.h" |
19 #include "chrome/common/chrome_version_info.h" | 15 #include "chrome/common/chrome_version_info.h" |
20 #include "net/base/escape.h" | 16 #include "net/base/escape.h" |
21 #include "net/url_request/url_request_status.h" | 17 #include "net/url_request/url_request_status.h" |
22 | 18 |
23 #if defined(OS_CHROMEOS) | 19 #if defined(OS_CHROMEOS) |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 // should be removed once the DM Server has been updated. | 73 // should be removed once the DM Server has been updated. |
78 const int kPendingApprovalLegacy = 491; | 74 const int kPendingApprovalLegacy = 491; |
79 const int kDeviceNotFoundLegacy = 901; | 75 const int kDeviceNotFoundLegacy = 901; |
80 | 76 |
81 #if defined(OS_CHROMEOS) | 77 #if defined(OS_CHROMEOS) |
82 // Machine info keys. | 78 // Machine info keys. |
83 const char kMachineInfoHWClass[] = "hardware_class"; | 79 const char kMachineInfoHWClass[] = "hardware_class"; |
84 const char kMachineInfoBoard[] = "CHROMEOS_RELEASE_BOARD"; | 80 const char kMachineInfoBoard[] = "CHROMEOS_RELEASE_BOARD"; |
85 #endif | 81 #endif |
86 | 82 |
87 } // namespace | |
88 | |
89 // Helper class for URL query parameter encoding/decoding. | 83 // Helper class for URL query parameter encoding/decoding. |
90 class URLQueryParameters { | 84 class URLQueryParameters { |
91 public: | 85 public: |
92 URLQueryParameters() {} | 86 URLQueryParameters() {} |
93 | 87 |
94 // Add a query parameter. | 88 // Add a query parameter. |
95 void Put(const std::string& name, const std::string& value); | 89 void Put(const std::string& name, const std::string& value); |
96 | 90 |
97 // Produce the query string, taking care of properly encoding and assembling | 91 // Produce the query string, taking care of properly encoding and assembling |
98 // the names and values. | 92 // the names and values. |
(...skipping 18 matching lines...) Expand all Loading... |
117 ++entry) { | 111 ++entry) { |
118 if (entry != params_.begin()) | 112 if (entry != params_.begin()) |
119 result += '&'; | 113 result += '&'; |
120 result += EscapeQueryParamValue(entry->first, true); | 114 result += EscapeQueryParamValue(entry->first, true); |
121 result += '='; | 115 result += '='; |
122 result += EscapeQueryParamValue(entry->second, true); | 116 result += EscapeQueryParamValue(entry->second, true); |
123 } | 117 } |
124 return result; | 118 return result; |
125 } | 119 } |
126 | 120 |
| 121 } // namespace |
| 122 |
127 // A base class containing the common code for the jobs created by the backend | 123 // A base class containing the common code for the jobs created by the backend |
128 // implementation. Subclasses provide custom code for handling actual register, | 124 // implementation. Subclasses provide custom code for handling actual register, |
129 // unregister, and policy jobs. | 125 // unregister, and policy jobs. |
130 class DeviceManagementJobBase | 126 class DeviceManagementJobBase |
131 : public DeviceManagementService::DeviceManagementJob { | 127 : public DeviceManagementService::DeviceManagementJob { |
132 public: | 128 public: |
133 virtual ~DeviceManagementJobBase() {} | 129 virtual ~DeviceManagementJobBase() {} |
134 | 130 |
135 // DeviceManagementJob overrides: | 131 // DeviceManagementJob overrides: |
136 virtual void HandleResponse(const net::URLRequestStatus& status, | 132 virtual void HandleResponse(const net::URLRequestStatus& status, |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 else if (!gaia_auth_token.empty()) | 311 else if (!gaia_auth_token.empty()) |
316 SetGaiaAuthToken(gaia_auth_token); | 312 SetGaiaAuthToken(gaia_auth_token); |
317 em::DeviceManagementRequest request_wrapper; | 313 em::DeviceManagementRequest request_wrapper; |
318 request_wrapper.mutable_register_request()->CopyFrom(request); | 314 request_wrapper.mutable_register_request()->CopyFrom(request); |
319 SetPayload(request_wrapper); | 315 SetPayload(request_wrapper); |
320 } | 316 } |
321 virtual ~DeviceManagementRegisterJob() {} | 317 virtual ~DeviceManagementRegisterJob() {} |
322 | 318 |
323 private: | 319 private: |
324 // DeviceManagementJobBase overrides. | 320 // DeviceManagementJobBase overrides. |
325 virtual void OnError(DeviceManagementBackend::ErrorCode error) { | 321 virtual void OnError(DeviceManagementBackend::ErrorCode error) OVERRIDE { |
326 MetricToken sample; | 322 MetricToken sample; |
327 switch (error) { | 323 switch (error) { |
328 case DeviceManagementBackend::kErrorRequestInvalid: | 324 case DeviceManagementBackend::kErrorRequestInvalid: |
329 case DeviceManagementBackend::kErrorRequestFailed: | 325 case DeviceManagementBackend::kErrorRequestFailed: |
330 sample = kMetricTokenFetchRequestFailed; | 326 sample = kMetricTokenFetchRequestFailed; |
331 break; | 327 break; |
332 case DeviceManagementBackend::kErrorServiceDeviceNotFound: | 328 case DeviceManagementBackend::kErrorServiceDeviceNotFound: |
333 sample = kMetricTokenFetchDeviceNotFound; | 329 sample = kMetricTokenFetchDeviceNotFound; |
334 break; | 330 break; |
335 case DeviceManagementBackend::kErrorServiceManagementNotSupported: | 331 case DeviceManagementBackend::kErrorServiceManagementNotSupported: |
336 sample = kMetricTokenFetchManagementNotSupported; | 332 sample = kMetricTokenFetchManagementNotSupported; |
337 break; | 333 break; |
338 case DeviceManagementBackend::kErrorResponseDecoding: | 334 case DeviceManagementBackend::kErrorResponseDecoding: |
339 sample = kMetricTokenFetchBadResponse; | 335 sample = kMetricTokenFetchBadResponse; |
340 break; | 336 break; |
341 case DeviceManagementBackend::kErrorServiceInvalidSerialNumber: | 337 case DeviceManagementBackend::kErrorServiceInvalidSerialNumber: |
342 sample = kMetricTokenFetchInvalidSerialNumber; | 338 sample = kMetricTokenFetchInvalidSerialNumber; |
343 break; | 339 break; |
344 case DeviceManagementBackend::kErrorServiceDeviceIdConflict: | 340 case DeviceManagementBackend::kErrorServiceDeviceIdConflict: |
345 sample = kMetricTokenFetchDeviceIdConflict; | 341 sample = kMetricTokenFetchDeviceIdConflict; |
346 break; | 342 break; |
347 default: | 343 default: |
348 sample = kMetricTokenFetchServerFailed; | 344 sample = kMetricTokenFetchServerFailed; |
349 break; | 345 break; |
350 } | 346 } |
351 UMA_HISTOGRAM_ENUMERATION(kMetricToken, sample, kMetricTokenSize); | 347 UMA_HISTOGRAM_ENUMERATION(kMetricToken, sample, kMetricTokenSize); |
352 delegate_->OnError(error); | 348 delegate_->OnError(error); |
353 } | 349 } |
354 virtual void OnResponse(const em::DeviceManagementResponse& response) { | 350 virtual void OnResponse( |
| 351 const em::DeviceManagementResponse& response) OVERRIDE { |
355 UMA_HISTOGRAM_ENUMERATION(kMetricToken, kMetricTokenFetchResponseReceived, | 352 UMA_HISTOGRAM_ENUMERATION(kMetricToken, kMetricTokenFetchResponseReceived, |
356 kMetricTokenSize); | 353 kMetricTokenSize); |
357 delegate_->HandleRegisterResponse(response.register_response()); | 354 delegate_->HandleRegisterResponse(response.register_response()); |
358 } | 355 } |
359 | 356 |
360 DeviceManagementBackend::DeviceRegisterResponseDelegate* delegate_; | 357 DeviceManagementBackend::DeviceRegisterResponseDelegate* delegate_; |
361 | 358 |
362 DISALLOW_COPY_AND_ASSIGN(DeviceManagementRegisterJob); | 359 DISALLOW_COPY_AND_ASSIGN(DeviceManagementRegisterJob); |
363 }; | 360 }; |
364 | 361 |
(...skipping 13 matching lines...) Expand all Loading... |
378 delegate_(delegate) { | 375 delegate_(delegate) { |
379 SetDeviceManagementToken(device_management_token); | 376 SetDeviceManagementToken(device_management_token); |
380 em::DeviceManagementRequest request_wrapper; | 377 em::DeviceManagementRequest request_wrapper; |
381 request_wrapper.mutable_unregister_request()->CopyFrom(request); | 378 request_wrapper.mutable_unregister_request()->CopyFrom(request); |
382 SetPayload(request_wrapper); | 379 SetPayload(request_wrapper); |
383 } | 380 } |
384 virtual ~DeviceManagementUnregisterJob() {} | 381 virtual ~DeviceManagementUnregisterJob() {} |
385 | 382 |
386 private: | 383 private: |
387 // DeviceManagementJobBase overrides. | 384 // DeviceManagementJobBase overrides. |
388 virtual void OnError(DeviceManagementBackend::ErrorCode error) { | 385 virtual void OnError(DeviceManagementBackend::ErrorCode error) OVERRIDE { |
389 delegate_->OnError(error); | 386 delegate_->OnError(error); |
390 } | 387 } |
391 virtual void OnResponse(const em::DeviceManagementResponse& response) { | 388 virtual void OnResponse( |
| 389 const em::DeviceManagementResponse& response) OVERRIDE { |
392 delegate_->HandleUnregisterResponse(response.unregister_response()); | 390 delegate_->HandleUnregisterResponse(response.unregister_response()); |
393 } | 391 } |
394 | 392 |
395 DeviceManagementBackend::DeviceUnregisterResponseDelegate* delegate_; | 393 DeviceManagementBackend::DeviceUnregisterResponseDelegate* delegate_; |
396 | 394 |
397 DISALLOW_COPY_AND_ASSIGN(DeviceManagementUnregisterJob); | 395 DISALLOW_COPY_AND_ASSIGN(DeviceManagementUnregisterJob); |
398 }; | 396 }; |
399 | 397 |
400 // Handles policy request jobs. | 398 // Handles policy request jobs. |
401 class DeviceManagementPolicyJob : public DeviceManagementJobBase { | 399 class DeviceManagementPolicyJob : public DeviceManagementJobBase { |
(...skipping 14 matching lines...) Expand all Loading... |
416 SetQueryParam(DeviceManagementBackendImpl::kParamUserAffiliation, | 414 SetQueryParam(DeviceManagementBackendImpl::kParamUserAffiliation, |
417 user_affiliation); | 415 user_affiliation); |
418 em::DeviceManagementRequest request_wrapper; | 416 em::DeviceManagementRequest request_wrapper; |
419 request_wrapper.mutable_policy_request()->CopyFrom(request); | 417 request_wrapper.mutable_policy_request()->CopyFrom(request); |
420 SetPayload(request_wrapper); | 418 SetPayload(request_wrapper); |
421 } | 419 } |
422 virtual ~DeviceManagementPolicyJob() {} | 420 virtual ~DeviceManagementPolicyJob() {} |
423 | 421 |
424 private: | 422 private: |
425 // DeviceManagementJobBase overrides. | 423 // DeviceManagementJobBase overrides. |
426 virtual void OnError(DeviceManagementBackend::ErrorCode error) { | 424 virtual void OnError(DeviceManagementBackend::ErrorCode error) OVERRIDE { |
427 MetricPolicy sample; | 425 MetricPolicy sample; |
428 switch (error) { | 426 switch (error) { |
429 case DeviceManagementBackend::kErrorRequestInvalid: | 427 case DeviceManagementBackend::kErrorRequestInvalid: |
430 case DeviceManagementBackend::kErrorRequestFailed: | 428 case DeviceManagementBackend::kErrorRequestFailed: |
431 sample = kMetricPolicyFetchRequestFailed; | 429 sample = kMetricPolicyFetchRequestFailed; |
432 break; | 430 break; |
433 case DeviceManagementBackend::kErrorServicePolicyNotFound: | 431 case DeviceManagementBackend::kErrorServicePolicyNotFound: |
434 sample = kMetricPolicyFetchNotFound; | 432 sample = kMetricPolicyFetchNotFound; |
435 break; | 433 break; |
436 case DeviceManagementBackend::kErrorServiceManagementTokenInvalid: | 434 case DeviceManagementBackend::kErrorServiceManagementTokenInvalid: |
437 sample = kMetricPolicyFetchInvalidToken; | 435 sample = kMetricPolicyFetchInvalidToken; |
438 break; | 436 break; |
439 case DeviceManagementBackend::kErrorResponseDecoding: | 437 case DeviceManagementBackend::kErrorResponseDecoding: |
440 sample = kMetricPolicyFetchBadResponse; | 438 sample = kMetricPolicyFetchBadResponse; |
441 break; | 439 break; |
442 default: | 440 default: |
443 sample = kMetricPolicyFetchServerFailed; | 441 sample = kMetricPolicyFetchServerFailed; |
444 break; | 442 break; |
445 } | 443 } |
446 UMA_HISTOGRAM_ENUMERATION(kMetricPolicy, sample, kMetricPolicySize); | 444 UMA_HISTOGRAM_ENUMERATION(kMetricPolicy, sample, kMetricPolicySize); |
447 delegate_->OnError(error); | 445 delegate_->OnError(error); |
448 } | 446 } |
449 virtual void OnResponse(const em::DeviceManagementResponse& response) { | 447 virtual void OnResponse( |
| 448 const em::DeviceManagementResponse& response) OVERRIDE { |
450 UMA_HISTOGRAM_ENUMERATION(kMetricPolicy, kMetricPolicyFetchResponseReceived, | 449 UMA_HISTOGRAM_ENUMERATION(kMetricPolicy, kMetricPolicyFetchResponseReceived, |
451 kMetricPolicySize); | 450 kMetricPolicySize); |
452 delegate_->HandlePolicyResponse(response.policy_response()); | 451 delegate_->HandlePolicyResponse(response.policy_response()); |
453 } | 452 } |
454 | 453 |
455 DeviceManagementBackend::DevicePolicyResponseDelegate* delegate_; | 454 DeviceManagementBackend::DevicePolicyResponseDelegate* delegate_; |
456 | 455 |
457 DISALLOW_COPY_AND_ASSIGN(DeviceManagementPolicyJob); | 456 DISALLOW_COPY_AND_ASSIGN(DeviceManagementPolicyJob); |
458 }; | 457 }; |
459 | 458 |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
578 case CloudPolicyDataStore::USER_AFFILIATION_MANAGED: | 577 case CloudPolicyDataStore::USER_AFFILIATION_MANAGED: |
579 return kValueUserAffiliationManaged; | 578 return kValueUserAffiliationManaged; |
580 case CloudPolicyDataStore::USER_AFFILIATION_NONE: | 579 case CloudPolicyDataStore::USER_AFFILIATION_NONE: |
581 return kValueUserAffiliationNone; | 580 return kValueUserAffiliationNone; |
582 } | 581 } |
583 NOTREACHED(); | 582 NOTREACHED(); |
584 return kValueUserAffiliationNone; | 583 return kValueUserAffiliationNone; |
585 } | 584 } |
586 | 585 |
587 } // namespace policy | 586 } // namespace policy |
OLD | NEW |