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 class DeviceManagementAutoEnrollmentJob : public DeviceManagementJobBase { | |
pastarmovj
2011/12/01 09:30:04
A short comment for the class will be good althoug
Joao da Silva
2011/12/01 09:42:07
Done.
| |
463 public: | |
464 DeviceManagementAutoEnrollmentJob( | |
465 DeviceManagementBackendImpl* backend_impl, | |
466 const std::string& device_id, | |
467 const em::DeviceAutoEnrollmentRequest& request, | |
468 DeviceManagementBackend::DeviceAutoEnrollmentResponseDelegate* delegate) | |
469 : DeviceManagementJobBase( | |
470 backend_impl, | |
471 DeviceManagementBackendImpl::kValueRequestAutoEnrollment, | |
472 device_id), | |
473 delegate_(delegate) { | |
474 em::DeviceManagementRequest request_wrapper; | |
475 request_wrapper.mutable_auto_enrollment_request()->CopyFrom(request); | |
476 SetPayload(request_wrapper); | |
477 } | |
478 virtual ~DeviceManagementAutoEnrollmentJob() {} | |
479 | |
480 private: | |
481 // DeviceManagementJobBase overrides. | |
482 virtual void OnError(DeviceManagementBackend::ErrorCode error) OVERRIDE { | |
pastarmovj
2011/12/01 09:30:04
Don't you want to put some UMA metrics here as wel
Joao da Silva
2011/12/01 09:42:07
Yes, we want metrics on how auto-enrollment behave
pastarmovj
2011/12/01 09:49:03
Good.
| |
483 delegate_->OnError(error); | |
484 } | |
485 virtual void OnResponse( | |
486 const em::DeviceManagementResponse& response) OVERRIDE { | |
487 delegate_->HandleAutoEnrollmentResponse( | |
488 response.auto_enrollment_response()); | |
489 } | |
490 | |
491 DeviceManagementBackend::DeviceAutoEnrollmentResponseDelegate* delegate_; | |
492 | |
493 DISALLOW_COPY_AND_ASSIGN(DeviceManagementAutoEnrollmentJob); | |
494 }; | |
495 | |
460 DeviceManagementBackendImpl::DeviceManagementBackendImpl( | 496 DeviceManagementBackendImpl::DeviceManagementBackendImpl( |
461 DeviceManagementService* service) | 497 DeviceManagementService* service) |
462 : service_(service) { | 498 : service_(service) { |
463 } | 499 } |
464 | 500 |
465 DeviceManagementBackendImpl::~DeviceManagementBackendImpl() { | 501 DeviceManagementBackendImpl::~DeviceManagementBackendImpl() { |
466 for (JobSet::iterator job(pending_jobs_.begin()); | 502 for (JobSet::iterator job(pending_jobs_.begin()); |
467 job != pending_jobs_.end(); | 503 job != pending_jobs_.end(); |
468 ++job) { | 504 ++job) { |
469 service_->RemoveJob(*job); | 505 service_->RemoveJob(*job); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
564 CloudPolicyDataStore::UserAffiliation affiliation, | 600 CloudPolicyDataStore::UserAffiliation affiliation, |
565 const em::DevicePolicyRequest& request, | 601 const em::DevicePolicyRequest& request, |
566 DevicePolicyResponseDelegate* delegate) { | 602 DevicePolicyResponseDelegate* delegate) { |
567 UMA_HISTOGRAM_ENUMERATION(kMetricPolicy, kMetricPolicyFetchRequested, | 603 UMA_HISTOGRAM_ENUMERATION(kMetricPolicy, kMetricPolicyFetchRequested, |
568 kMetricPolicySize); | 604 kMetricPolicySize); |
569 AddJob(new DeviceManagementPolicyJob(this, device_management_token, device_id, | 605 AddJob(new DeviceManagementPolicyJob(this, device_management_token, device_id, |
570 UserAffiliationToString(affiliation), | 606 UserAffiliationToString(affiliation), |
571 request, delegate)); | 607 request, delegate)); |
572 } | 608 } |
573 | 609 |
610 void DeviceManagementBackendImpl::ProcessAutoEnrollmentRequest( | |
611 const std::string& device_id, | |
612 const em::DeviceAutoEnrollmentRequest& request, | |
613 DeviceAutoEnrollmentResponseDelegate* delegate) { | |
614 AddJob(new DeviceManagementAutoEnrollmentJob(this, device_id, request, | |
615 delegate)); | |
616 } | |
617 | |
574 // static | 618 // static |
575 const char* DeviceManagementBackendImpl::UserAffiliationToString( | 619 const char* DeviceManagementBackendImpl::UserAffiliationToString( |
576 CloudPolicyDataStore::UserAffiliation affiliation) { | 620 CloudPolicyDataStore::UserAffiliation affiliation) { |
577 switch (affiliation) { | 621 switch (affiliation) { |
578 case CloudPolicyDataStore::USER_AFFILIATION_MANAGED: | 622 case CloudPolicyDataStore::USER_AFFILIATION_MANAGED: |
579 return kValueUserAffiliationManaged; | 623 return kValueUserAffiliationManaged; |
580 case CloudPolicyDataStore::USER_AFFILIATION_NONE: | 624 case CloudPolicyDataStore::USER_AFFILIATION_NONE: |
581 return kValueUserAffiliationNone; | 625 return kValueUserAffiliationNone; |
582 } | 626 } |
583 NOTREACHED(); | 627 NOTREACHED(); |
584 return kValueUserAffiliationNone; | 628 return kValueUserAffiliationNone; |
585 } | 629 } |
586 | 630 |
587 } // namespace policy | 631 } // namespace policy |
OLD | NEW |