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

Unified Diff: components/policy/core/common/cloud/cloud_policy_client.cc

Issue 879233003: Initial RemoteCommandService (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@remote-commands
Patch Set: minor fixes Created 5 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: components/policy/core/common/cloud/cloud_policy_client.cc
diff --git a/components/policy/core/common/cloud/cloud_policy_client.cc b/components/policy/core/common/cloud/cloud_policy_client.cc
index 6f7fbf931c2f28f4de5b44f83d147bf8cd7d8337..7e5fa73e8ddb969b2cb251093f54e2186f9e93d9 100644
--- a/components/policy/core/common/cloud/cloud_policy_client.cc
+++ b/components/policy/core/common/cloud/cloud_policy_client.cc
@@ -261,11 +261,10 @@ void CloudPolicyClient::UploadCertificate(
request->mutable_cert_upload_request()->set_device_certificate(
certificate_data);
- DeviceManagementRequestJob::Callback job_callback = base::Bind(
- &CloudPolicyClient::OnCertificateUploadCompleted,
- base::Unretained(this),
- request_job.get(),
- callback);
+ const DeviceManagementRequestJob::Callback job_callback =
+ base::Bind(&CloudPolicyClient::OnCertificateUploadCompleted,
+ base::Unretained(this), request_job.get(), callback);
bartfab (slow) 2015/02/28 00:01:22 Nit: #include "base/bind_helpers.h"
binjin 2015/02/28 02:18:04 Done.
+
request_jobs_.push_back(request_job.Pass());
request_jobs_.back()->Start(job_callback);
}
@@ -289,11 +288,36 @@ void CloudPolicyClient::UploadDeviceStatus(
if (session_status)
*request->mutable_session_status_report_request() = *session_status;
- DeviceManagementRequestJob::Callback job_callback = base::Bind(
- &CloudPolicyClient::OnStatusUploadCompleted,
- base::Unretained(this),
- request_job.get(),
- callback);
+ const DeviceManagementRequestJob::Callback job_callback =
+ base::Bind(&CloudPolicyClient::OnStatusUploadCompleted,
+ base::Unretained(this), request_job.get(), callback);
+
+ request_jobs_.push_back(request_job.Pass());
+ request_jobs_.back()->Start(job_callback);
+}
+
+void CloudPolicyClient::FetchRemoteCommands(
+ RemoteCommandJob::UniqueIDType last_command_id,
+ const std::vector<em::RemoteCommandResult>& command_results,
+ const RemoteCommandCallback& callback) {
+ CHECK(is_registered());
+ scoped_ptr<DeviceManagementRequestJob> request_job(service_->CreateJob(
+ DeviceManagementRequestJob::TYPE_REMOTE_COMMANDS, GetRequestContext()));
+
+ request_job->SetDMToken(dm_token_);
+ request_job->SetClientID(client_id_);
+
+ em::DeviceRemoteCommandRequest* request =
bartfab (slow) 2015/02/28 00:01:22 Nit: const.
binjin 2015/02/28 02:18:04 I'm not sure since it's pointer mutable protobuf.
bartfab (slow) 2015/03/10 16:09:20 Thanks. const pointer is what I meant.
binjin 2015/03/12 11:03:15 Acknowledged.
+ request_job->GetRequest()->mutable_remote_command_request();
+
+ request->set_last_command_unique_id(last_command_id);
+
+ for (const auto& command_result : command_results)
+ *request->add_command_results() = command_result;
+
+ const DeviceManagementRequestJob::Callback job_callback = base::Bind(
bartfab (slow) 2015/02/28 00:01:22 Why the nested base::Bind()?
binjin 2015/02/28 02:18:04 Done.
+ base::Bind(&CloudPolicyClient::OnRemoteCommandsFetched,
+ base::Unretained(this), request_job.get(), callback));
request_jobs_.push_back(request_job.Pass());
request_jobs_.back()->Start(job_callback);
@@ -516,6 +540,24 @@ void CloudPolicyClient::OnStatusUploadCompleted(
RemoveJob(job);
}
+void CloudPolicyClient::OnRemoteCommandsFetched(
+ const DeviceManagementRequestJob* job,
+ const RemoteCommandCallback& callback,
+ DeviceManagementStatus status,
+ int net_error,
+ const enterprise_management::DeviceManagementResponse& response) {
+ std::vector<enterprise_management::RemoteCommand> commands;
+ if (status == DM_STATUS_SUCCESS && response.has_remote_command_response()) {
+ for (const auto& command : response.remote_command_response().commands())
+ commands.push_back(command);
+ } else {
+ NotifyClientError();
bartfab (slow) 2015/02/28 00:01:22 NotifyClientError() will tell all consumers that s
binjin 2015/02/28 02:18:04 Done.
+ }
+ callback.Run(commands);
+ // Must call RemoveJob() last, because it frees |callback|.
+ RemoveJob(job);
+}
+
void CloudPolicyClient::NotifyPolicyFetched() {
FOR_EACH_OBSERVER(Observer, observers_, OnPolicyFetched(this));
}

Powered by Google App Engine
This is Rietveld 408576698