Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(433)

Unified Diff: chrome/browser/policy/device_management_backend_impl.cc

Issue 6409040: New policy protobuf protocol. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/policy/device_management_backend_impl.cc
diff --git a/chrome/browser/policy/device_management_backend_impl.cc b/chrome/browser/policy/device_management_backend_impl.cc
index ed75f3f8603e156905c6eddab155c70ea64a19ce..b01cbf8193d9ae03e87e48e5b4e55f35230ac676 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
« no previous file with comments | « chrome/browser/policy/device_management_backend_impl.h ('k') | chrome/browser/policy/device_management_backend_mock.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698