| 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 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 const char DeviceManagementBackendImpl::kParamDeviceType[] = "devicetype"; | 30 const char DeviceManagementBackendImpl::kParamDeviceType[] = "devicetype"; |
| 31 const char DeviceManagementBackendImpl::kParamOAuthToken[] = "oauth_token"; | 31 const char DeviceManagementBackendImpl::kParamOAuthToken[] = "oauth_token"; |
| 32 const char DeviceManagementBackendImpl::kParamPlatform[] = "platform"; | 32 const char DeviceManagementBackendImpl::kParamPlatform[] = "platform"; |
| 33 const char DeviceManagementBackendImpl::kParamRequest[] = "request"; | 33 const char DeviceManagementBackendImpl::kParamRequest[] = "request"; |
| 34 const char DeviceManagementBackendImpl::kParamUserAffiliation[] = | 34 const char DeviceManagementBackendImpl::kParamUserAffiliation[] = |
| 35 "user_affiliation"; | 35 "user_affiliation"; |
| 36 | 36 |
| 37 // String constants for the device and app type we report to the server. | 37 // String constants for the device and app type we report to the server. |
| 38 const char DeviceManagementBackendImpl::kValueAppType[] = "Chrome"; | 38 const char DeviceManagementBackendImpl::kValueAppType[] = "Chrome"; |
| 39 const char DeviceManagementBackendImpl::kValueDeviceType[] = "2"; | 39 const char DeviceManagementBackendImpl::kValueDeviceType[] = "2"; |
| 40 const char DeviceManagementBackendImpl::kValueRequestAutoEnrollment[] = |
| 41 "enterprise_check"; |
| 40 const char DeviceManagementBackendImpl::kValueRequestPolicy[] = "policy"; | 42 const char DeviceManagementBackendImpl::kValueRequestPolicy[] = "policy"; |
| 41 const char DeviceManagementBackendImpl::kValueRequestRegister[] = "register"; | 43 const char DeviceManagementBackendImpl::kValueRequestRegister[] = "register"; |
| 42 const char DeviceManagementBackendImpl::kValueRequestUnregister[] = | 44 const char DeviceManagementBackendImpl::kValueRequestUnregister[] = |
| 43 "unregister"; | 45 "unregister"; |
| 44 const char DeviceManagementBackendImpl::kValueUserAffiliationManaged[] = | 46 const char DeviceManagementBackendImpl::kValueUserAffiliationManaged[] = |
| 45 "managed"; | 47 "managed"; |
| 46 const char DeviceManagementBackendImpl::kValueUserAffiliationNone[] = "none"; | 48 const char DeviceManagementBackendImpl::kValueUserAffiliationNone[] = "none"; |
| 47 | 49 |
| 48 namespace { | 50 namespace { |
| 49 | 51 |
| (...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 UMA_HISTOGRAM_ENUMERATION(kMetricPolicy, kMetricPolicyFetchResponseReceived, | 452 UMA_HISTOGRAM_ENUMERATION(kMetricPolicy, kMetricPolicyFetchResponseReceived, |
| 451 kMetricPolicySize); | 453 kMetricPolicySize); |
| 452 delegate_->HandlePolicyResponse(response.policy_response()); | 454 delegate_->HandlePolicyResponse(response.policy_response()); |
| 453 } | 455 } |
| 454 | 456 |
| 455 DeviceManagementBackend::DevicePolicyResponseDelegate* delegate_; | 457 DeviceManagementBackend::DevicePolicyResponseDelegate* delegate_; |
| 456 | 458 |
| 457 DISALLOW_COPY_AND_ASSIGN(DeviceManagementPolicyJob); | 459 DISALLOW_COPY_AND_ASSIGN(DeviceManagementPolicyJob); |
| 458 }; | 460 }; |
| 459 | 461 |
| 462 // Handles auto enrollment request jobs. These are used to determine if a new |
| 463 // ChromiumOS device should automatically enter the enterprise enrollment screen |
| 464 // during the OOBE flow. |
| 465 class DeviceManagementAutoEnrollmentJob : public DeviceManagementJobBase { |
| 466 public: |
| 467 DeviceManagementAutoEnrollmentJob( |
| 468 DeviceManagementBackendImpl* backend_impl, |
| 469 const std::string& device_id, |
| 470 const em::DeviceAutoEnrollmentRequest& request, |
| 471 DeviceManagementBackend::DeviceAutoEnrollmentResponseDelegate* delegate) |
| 472 : DeviceManagementJobBase( |
| 473 backend_impl, |
| 474 DeviceManagementBackendImpl::kValueRequestAutoEnrollment, |
| 475 device_id), |
| 476 delegate_(delegate) { |
| 477 em::DeviceManagementRequest request_wrapper; |
| 478 request_wrapper.mutable_auto_enrollment_request()->CopyFrom(request); |
| 479 SetPayload(request_wrapper); |
| 480 } |
| 481 virtual ~DeviceManagementAutoEnrollmentJob() {} |
| 482 |
| 483 private: |
| 484 // DeviceManagementJobBase overrides. |
| 485 virtual void OnError(DeviceManagementBackend::ErrorCode error) OVERRIDE { |
| 486 delegate_->OnError(error); |
| 487 } |
| 488 virtual void OnResponse( |
| 489 const em::DeviceManagementResponse& response) OVERRIDE { |
| 490 delegate_->HandleAutoEnrollmentResponse( |
| 491 response.auto_enrollment_response()); |
| 492 } |
| 493 |
| 494 DeviceManagementBackend::DeviceAutoEnrollmentResponseDelegate* delegate_; |
| 495 |
| 496 DISALLOW_COPY_AND_ASSIGN(DeviceManagementAutoEnrollmentJob); |
| 497 }; |
| 498 |
| 460 DeviceManagementBackendImpl::DeviceManagementBackendImpl( | 499 DeviceManagementBackendImpl::DeviceManagementBackendImpl( |
| 461 DeviceManagementService* service) | 500 DeviceManagementService* service) |
| 462 : service_(service) { | 501 : service_(service) { |
| 463 } | 502 } |
| 464 | 503 |
| 465 DeviceManagementBackendImpl::~DeviceManagementBackendImpl() { | 504 DeviceManagementBackendImpl::~DeviceManagementBackendImpl() { |
| 466 for (JobSet::iterator job(pending_jobs_.begin()); | 505 for (JobSet::iterator job(pending_jobs_.begin()); |
| 467 job != pending_jobs_.end(); | 506 job != pending_jobs_.end(); |
| 468 ++job) { | 507 ++job) { |
| 469 service_->RemoveJob(*job); | 508 service_->RemoveJob(*job); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 564 CloudPolicyDataStore::UserAffiliation affiliation, | 603 CloudPolicyDataStore::UserAffiliation affiliation, |
| 565 const em::DevicePolicyRequest& request, | 604 const em::DevicePolicyRequest& request, |
| 566 DevicePolicyResponseDelegate* delegate) { | 605 DevicePolicyResponseDelegate* delegate) { |
| 567 UMA_HISTOGRAM_ENUMERATION(kMetricPolicy, kMetricPolicyFetchRequested, | 606 UMA_HISTOGRAM_ENUMERATION(kMetricPolicy, kMetricPolicyFetchRequested, |
| 568 kMetricPolicySize); | 607 kMetricPolicySize); |
| 569 AddJob(new DeviceManagementPolicyJob(this, device_management_token, device_id, | 608 AddJob(new DeviceManagementPolicyJob(this, device_management_token, device_id, |
| 570 UserAffiliationToString(affiliation), | 609 UserAffiliationToString(affiliation), |
| 571 request, delegate)); | 610 request, delegate)); |
| 572 } | 611 } |
| 573 | 612 |
| 613 void DeviceManagementBackendImpl::ProcessAutoEnrollmentRequest( |
| 614 const std::string& device_id, |
| 615 const em::DeviceAutoEnrollmentRequest& request, |
| 616 DeviceAutoEnrollmentResponseDelegate* delegate) { |
| 617 AddJob(new DeviceManagementAutoEnrollmentJob(this, device_id, request, |
| 618 delegate)); |
| 619 } |
| 620 |
| 574 // static | 621 // static |
| 575 const char* DeviceManagementBackendImpl::UserAffiliationToString( | 622 const char* DeviceManagementBackendImpl::UserAffiliationToString( |
| 576 CloudPolicyDataStore::UserAffiliation affiliation) { | 623 CloudPolicyDataStore::UserAffiliation affiliation) { |
| 577 switch (affiliation) { | 624 switch (affiliation) { |
| 578 case CloudPolicyDataStore::USER_AFFILIATION_MANAGED: | 625 case CloudPolicyDataStore::USER_AFFILIATION_MANAGED: |
| 579 return kValueUserAffiliationManaged; | 626 return kValueUserAffiliationManaged; |
| 580 case CloudPolicyDataStore::USER_AFFILIATION_NONE: | 627 case CloudPolicyDataStore::USER_AFFILIATION_NONE: |
| 581 return kValueUserAffiliationNone; | 628 return kValueUserAffiliationNone; |
| 582 } | 629 } |
| 583 NOTREACHED(); | 630 NOTREACHED(); |
| 584 return kValueUserAffiliationNone; | 631 return kValueUserAffiliationNone; |
| 585 } | 632 } |
| 586 | 633 |
| 587 } // namespace policy | 634 } // namespace policy |
| OLD | NEW |