summaryrefslogtreecommitdiffstats
path: root/chrome/browser/policy/device_management_backend_impl.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/policy/device_management_backend_impl.cc')
-rw-r--r--chrome/browser/policy/device_management_backend_impl.cc134
1 files changed, 81 insertions, 53 deletions
diff --git a/chrome/browser/policy/device_management_backend_impl.cc b/chrome/browser/policy/device_management_backend_impl.cc
index ed75f3f..b01cbf8 100644
--- a/chrome/browser/policy/device_management_backend_impl.cc
+++ b/chrome/browser/policy/device_management_backend_impl.cc
@@ -27,6 +27,8 @@ const char DeviceManagementBackendImpl::kValueRequestRegister[] = "register";
const char DeviceManagementBackendImpl::kValueRequestUnregister[] =
"unregister";
const char DeviceManagementBackendImpl::kValueRequestPolicy[] = "policy";
+const char DeviceManagementBackendImpl::kValueRequestCloudPolicy[] =
+ "cloud_policy";
const char DeviceManagementBackendImpl::kValueDeviceType[] = "Chrome OS";
const char DeviceManagementBackendImpl::kValueAppType[] = "Chrome";
@@ -170,7 +172,10 @@ void DeviceManagementJobBase::HandleResponse(
}
if (response_code != 200) {
- OnError(DeviceManagementBackend::kErrorHttpStatus);
+ if (response_code == 400)
+ OnError(DeviceManagementBackend::kErrorRequestInvalid);
+ else
+ OnError(DeviceManagementBackend::kErrorHttpStatus);
return;
}
@@ -230,7 +235,17 @@ class DeviceManagementRegisterJob : public DeviceManagementJobBase {
const std::string& auth_token,
const std::string& device_id,
const em::DeviceRegisterRequest& request,
- DeviceManagementBackend::DeviceRegisterResponseDelegate* delegate);
+ DeviceManagementBackend::DeviceRegisterResponseDelegate* delegate)
+ : DeviceManagementJobBase(
+ backend_impl,
+ DeviceManagementBackendImpl::kValueRequestRegister,
+ device_id),
+ delegate_(delegate) {
+ SetAuthToken(auth_token);
+ em::DeviceManagementRequest request_wrapper;
+ request_wrapper.mutable_register_request()->CopyFrom(request);
+ SetPayload(request_wrapper);
+ }
virtual ~DeviceManagementRegisterJob() {}
private:
@@ -247,32 +262,25 @@ class DeviceManagementRegisterJob : public DeviceManagementJobBase {
DISALLOW_COPY_AND_ASSIGN(DeviceManagementRegisterJob);
};
-DeviceManagementRegisterJob::DeviceManagementRegisterJob(
- DeviceManagementBackendImpl* backend_impl,
- const std::string& auth_token,
- const std::string& device_id,
- const em::DeviceRegisterRequest& request,
- DeviceManagementBackend::DeviceRegisterResponseDelegate* delegate)
- : DeviceManagementJobBase(
- backend_impl,
- DeviceManagementBackendImpl::kValueRequestRegister,
- device_id),
- delegate_(delegate) {
- SetAuthToken(auth_token);
- em::DeviceManagementRequest request_wrapper;
- request_wrapper.mutable_register_request()->CopyFrom(request);
- SetPayload(request_wrapper);
-}
-
// Handles device unregistration jobs.
class DeviceManagementUnregisterJob : public DeviceManagementJobBase {
public:
DeviceManagementUnregisterJob(
DeviceManagementBackendImpl* backend_impl,
- const std::string& device_id,
const std::string& device_management_token,
+ const std::string& device_id,
const em::DeviceUnregisterRequest& request,
- DeviceManagementBackend::DeviceUnregisterResponseDelegate* delegate);
+ DeviceManagementBackend::DeviceUnregisterResponseDelegate* delegate)
+ : DeviceManagementJobBase(
+ backend_impl,
+ DeviceManagementBackendImpl::kValueRequestUnregister,
+ device_id),
+ delegate_(delegate) {
+ SetDeviceManagementToken(device_management_token);
+ em::DeviceManagementRequest request_wrapper;
+ request_wrapper.mutable_unregister_request()->CopyFrom(request);
+ SetPayload(request_wrapper);
+ }
virtual ~DeviceManagementUnregisterJob() {}
private:
@@ -289,23 +297,6 @@ class DeviceManagementUnregisterJob : public DeviceManagementJobBase {
DISALLOW_COPY_AND_ASSIGN(DeviceManagementUnregisterJob);
};
-DeviceManagementUnregisterJob::DeviceManagementUnregisterJob(
- DeviceManagementBackendImpl* backend_impl,
- const std::string& device_management_token,
- const std::string& device_id,
- const em::DeviceUnregisterRequest& request,
- DeviceManagementBackend::DeviceUnregisterResponseDelegate* delegate)
- : DeviceManagementJobBase(
- backend_impl,
- DeviceManagementBackendImpl::kValueRequestUnregister,
- device_id),
- delegate_(delegate) {
- SetDeviceManagementToken(device_management_token);
- em::DeviceManagementRequest request_wrapper;
- request_wrapper.mutable_unregister_request()->CopyFrom(request);
- SetPayload(request_wrapper);
-}
-
// Handles policy request jobs.
class DeviceManagementPolicyJob : public DeviceManagementJobBase {
public:
@@ -314,7 +305,17 @@ class DeviceManagementPolicyJob : public DeviceManagementJobBase {
const std::string& device_management_token,
const std::string& device_id,
const em::DevicePolicyRequest& request,
- DeviceManagementBackend::DevicePolicyResponseDelegate* delegate);
+ DeviceManagementBackend::DevicePolicyResponseDelegate* delegate)
+ : DeviceManagementJobBase(
+ backend_impl,
+ DeviceManagementBackendImpl::kValueRequestPolicy,
+ device_id),
+ delegate_(delegate) {
+ SetDeviceManagementToken(device_management_token);
+ em::DeviceManagementRequest request_wrapper;
+ request_wrapper.mutable_policy_request()->CopyFrom(request);
+ SetPayload(request_wrapper);
+ }
virtual ~DeviceManagementPolicyJob() {}
private:
@@ -331,22 +332,40 @@ class DeviceManagementPolicyJob : public DeviceManagementJobBase {
DISALLOW_COPY_AND_ASSIGN(DeviceManagementPolicyJob);
};
-DeviceManagementPolicyJob::DeviceManagementPolicyJob(
- DeviceManagementBackendImpl* backend_impl,
- const std::string& device_management_token,
- const std::string& device_id,
- const em::DevicePolicyRequest& request,
- DeviceManagementBackend::DevicePolicyResponseDelegate* delegate)
- : DeviceManagementJobBase(
+// Handles cloud policy request jobs.
+class CloudPolicyJob : public DeviceManagementJobBase {
+ public:
+ CloudPolicyJob(
+ DeviceManagementBackendImpl* backend_impl,
+ const std::string& device_management_token,
+ const std::string& device_id,
+ const em::CloudPolicyRequest& request,
+ DeviceManagementBackend::DevicePolicyResponseDelegate* delegate)
+ : DeviceManagementJobBase(
backend_impl,
- DeviceManagementBackendImpl::kValueRequestPolicy,
+ DeviceManagementBackendImpl::kValueRequestCloudPolicy,
device_id),
- delegate_(delegate) {
- SetDeviceManagementToken(device_management_token);
- em::DeviceManagementRequest request_wrapper;
- request_wrapper.mutable_policy_request()->CopyFrom(request);
- SetPayload(request_wrapper);
-}
+ delegate_(delegate) {
+ SetDeviceManagementToken(device_management_token);
+ em::DeviceManagementRequest request_wrapper;
+ request_wrapper.mutable_cloud_policy_request()->CopyFrom(request);
+ SetPayload(request_wrapper);
+ }
+ virtual ~CloudPolicyJob() {}
+
+ private:
+ // DeviceManagementJobBase overrides.
+ virtual void OnError(DeviceManagementBackend::ErrorCode error) {
+ delegate_->OnError(error);
+ }
+ virtual void OnResponse(const em::DeviceManagementResponse& response) {
+ delegate_->HandleCloudPolicyResponse(response.cloud_policy_response());
+ }
+
+ DeviceManagementBackend::DevicePolicyResponseDelegate* delegate_;
+
+ DISALLOW_COPY_AND_ASSIGN(CloudPolicyJob);
+};
DeviceManagementBackendImpl::DeviceManagementBackendImpl(
DeviceManagementService* service)
@@ -409,4 +428,13 @@ void DeviceManagementBackendImpl::ProcessPolicyRequest(
request, delegate));
}
+void DeviceManagementBackendImpl::ProcessCloudPolicyRequest(
+ const std::string& device_management_token,
+ const std::string& device_id,
+ const em::CloudPolicyRequest& request,
+ DevicePolicyResponseDelegate* delegate) {
+ AddJob(new CloudPolicyJob(this, device_management_token, device_id,
+ request, delegate));
+}
+
} // namespace policy