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

Side by Side 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: comments grammar fixes; fix win compile 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "components/policy/core/common/cloud/cloud_policy_client.h" 5 #include "components/policy/core/common/cloud/cloud_policy_client.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/guid.h" 8 #include "base/guid.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 DeviceManagementRequestJob::Callback job_callback = base::Bind( 292 DeviceManagementRequestJob::Callback job_callback = base::Bind(
293 &CloudPolicyClient::OnStatusUploadCompleted, 293 &CloudPolicyClient::OnStatusUploadCompleted,
294 base::Unretained(this), 294 base::Unretained(this),
295 request_job.get(), 295 request_job.get(),
296 callback); 296 callback);
297 297
298 request_jobs_.push_back(request_job.Pass()); 298 request_jobs_.push_back(request_job.Pass());
299 request_jobs_.back()->Start(job_callback); 299 request_jobs_.back()->Start(job_callback);
300 } 300 }
301 301
302 void CloudPolicyClient::FetchRemoteCommands(
303 RemoteCommandJob::UniqueIDType last_command_id,
304 const std::vector<em::RemoteCommandResult>& command_results,
305 const RemoteCommandCallback& callback) {
306 CHECK(is_registered());
307 scoped_ptr<DeviceManagementRequestJob> request_job(service_->CreateJob(
308 DeviceManagementRequestJob::TYPE_REMOTE_COMMANDS, GetRequestContext()));
309
310 request_job->SetDMToken(dm_token_);
311 request_job->SetClientID(client_id_);
312
313 em::DeviceRemoteCommandRequest* request =
314 request_job->GetRequest()->mutable_remote_command_request();
315
316 request->set_last_command_unique_id(last_command_id);
317
318 for (const auto& command_result : command_results)
319 *request->add_command_results() = command_result;
320
321 DeviceManagementRequestJob::Callback job_callback = base::Bind(
bartfab (slow) 2015/02/17 18:13:52 Nit: const.
binjin 2015/02/18 15:37:50 Done.
322 base::Bind(&CloudPolicyClient::OnRemoteCommandsFetched,
323 base::Unretained(this), request_job.get(), callback));
324
325 request_jobs_.push_back(request_job.Pass());
326 request_jobs_.back()->Start(job_callback);
327 }
328
302 void CloudPolicyClient::AddObserver(Observer* observer) { 329 void CloudPolicyClient::AddObserver(Observer* observer) {
303 observers_.AddObserver(observer); 330 observers_.AddObserver(observer);
304 } 331 }
305 332
306 void CloudPolicyClient::RemoveObserver(Observer* observer) { 333 void CloudPolicyClient::RemoveObserver(Observer* observer) {
307 observers_.RemoveObserver(observer); 334 observers_.RemoveObserver(observer);
308 } 335 }
309 336
310 void CloudPolicyClient::AddPolicyTypeToFetch( 337 void CloudPolicyClient::AddPolicyTypeToFetch(
311 const std::string& policy_type, 338 const std::string& policy_type,
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 const enterprise_management::DeviceManagementResponse& response) { 536 const enterprise_management::DeviceManagementResponse& response) {
510 status_ = status; 537 status_ = status;
511 if (status != DM_STATUS_SUCCESS) 538 if (status != DM_STATUS_SUCCESS)
512 NotifyClientError(); 539 NotifyClientError();
513 540
514 callback.Run(status == DM_STATUS_SUCCESS); 541 callback.Run(status == DM_STATUS_SUCCESS);
515 // Must call RemoveJob() last, because it frees |callback|. 542 // Must call RemoveJob() last, because it frees |callback|.
516 RemoveJob(job); 543 RemoveJob(job);
517 } 544 }
518 545
546 void CloudPolicyClient::OnRemoteCommandsFetched(
547 const DeviceManagementRequestJob* job,
548 const RemoteCommandCallback& callback,
549 DeviceManagementStatus status,
550 int net_error,
551 const enterprise_management::DeviceManagementResponse& response) {
552 std::vector<enterprise_management::RemoteCommand> commands;
553 if (status == DM_STATUS_SUCCESS && response.has_remote_command_response()) {
554 for (const auto& command : response.remote_command_response().commands())
555 commands.push_back(command);
556 } else {
557 NotifyClientError();
558 }
559 callback.Run(commands);
560 // Must call RemoveJob() last, because it frees |callback|.
561 RemoveJob(job);
562 }
563
519 void CloudPolicyClient::NotifyPolicyFetched() { 564 void CloudPolicyClient::NotifyPolicyFetched() {
520 FOR_EACH_OBSERVER(Observer, observers_, OnPolicyFetched(this)); 565 FOR_EACH_OBSERVER(Observer, observers_, OnPolicyFetched(this));
521 } 566 }
522 567
523 void CloudPolicyClient::NotifyRegistrationStateChanged() { 568 void CloudPolicyClient::NotifyRegistrationStateChanged() {
524 FOR_EACH_OBSERVER(Observer, observers_, OnRegistrationStateChanged(this)); 569 FOR_EACH_OBSERVER(Observer, observers_, OnRegistrationStateChanged(this));
525 } 570 }
526 571
527 void CloudPolicyClient::NotifyRobotAuthCodesFetched() { 572 void CloudPolicyClient::NotifyRobotAuthCodesFetched() {
528 FOR_EACH_OBSERVER(Observer, observers_, OnRobotAuthCodesFetched(this)); 573 FOR_EACH_OBSERVER(Observer, observers_, OnRobotAuthCodesFetched(this));
529 } 574 }
530 575
531 void CloudPolicyClient::NotifyClientError() { 576 void CloudPolicyClient::NotifyClientError() {
532 FOR_EACH_OBSERVER(Observer, observers_, OnClientError(this)); 577 FOR_EACH_OBSERVER(Observer, observers_, OnClientError(this));
533 } 578 }
534 579
535 } // namespace policy 580 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698