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

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: WIP 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 request->clear_command_results();
bartfab (slow) 2015/02/12 14:29:19 This is unnecessary. The command results will alwa
binjin 2015/02/16 22:46:23 Done.
318
319 for (const auto& command_result : command_results)
320 *request->add_command_results() = command_result;
321
322 request_jobs_.push_back(request_job.Pass());
323 request_jobs_.back()->Start(
324 base::Bind(&CloudPolicyClient::OnRemoteCommandsFetched,
325 base::Unretained(this), request_job.get(), callback));
326 }
327
302 void CloudPolicyClient::AddObserver(Observer* observer) { 328 void CloudPolicyClient::AddObserver(Observer* observer) {
303 observers_.AddObserver(observer); 329 observers_.AddObserver(observer);
304 } 330 }
305 331
306 void CloudPolicyClient::RemoveObserver(Observer* observer) { 332 void CloudPolicyClient::RemoveObserver(Observer* observer) {
307 observers_.RemoveObserver(observer); 333 observers_.RemoveObserver(observer);
308 } 334 }
309 335
310 void CloudPolicyClient::AddPolicyTypeToFetch( 336 void CloudPolicyClient::AddPolicyTypeToFetch(
311 const std::string& policy_type, 337 const std::string& policy_type,
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 const enterprise_management::DeviceManagementResponse& response) { 535 const enterprise_management::DeviceManagementResponse& response) {
510 status_ = status; 536 status_ = status;
511 if (status != DM_STATUS_SUCCESS) 537 if (status != DM_STATUS_SUCCESS)
512 NotifyClientError(); 538 NotifyClientError();
513 539
514 callback.Run(status == DM_STATUS_SUCCESS); 540 callback.Run(status == DM_STATUS_SUCCESS);
515 // Must call RemoveJob() last, because it frees |callback|. 541 // Must call RemoveJob() last, because it frees |callback|.
516 RemoveJob(job); 542 RemoveJob(job);
517 } 543 }
518 544
545 void CloudPolicyClient::OnRemoteCommandsFetched(
546 const DeviceManagementRequestJob* job,
547 const RemoteCommandCallback& callback,
548 DeviceManagementStatus status,
549 int net_error,
550 const enterprise_management::DeviceManagementResponse& response) {
551 std::vector<enterprise_management::RemoteCommand> commands;
552 if (status == DM_STATUS_SUCCESS && response.has_remote_command_response()) {
553 for (const auto& command : response.remote_command_response().commands())
554 commands.push_back(command);
555 } else {
556 NotifyClientError();
557 }
558 callback.Run(commands);
559 }
bartfab (slow) 2015/02/12 14:29:19 You forgot to RemoveJob(job).
binjin 2015/02/16 22:46:23 Done.
560
519 void CloudPolicyClient::NotifyPolicyFetched() { 561 void CloudPolicyClient::NotifyPolicyFetched() {
520 FOR_EACH_OBSERVER(Observer, observers_, OnPolicyFetched(this)); 562 FOR_EACH_OBSERVER(Observer, observers_, OnPolicyFetched(this));
521 } 563 }
522 564
523 void CloudPolicyClient::NotifyRegistrationStateChanged() { 565 void CloudPolicyClient::NotifyRegistrationStateChanged() {
524 FOR_EACH_OBSERVER(Observer, observers_, OnRegistrationStateChanged(this)); 566 FOR_EACH_OBSERVER(Observer, observers_, OnRegistrationStateChanged(this));
525 } 567 }
526 568
527 void CloudPolicyClient::NotifyRobotAuthCodesFetched() { 569 void CloudPolicyClient::NotifyRobotAuthCodesFetched() {
528 FOR_EACH_OBSERVER(Observer, observers_, OnRobotAuthCodesFetched(this)); 570 FOR_EACH_OBSERVER(Observer, observers_, OnRobotAuthCodesFetched(this));
529 } 571 }
530 572
531 void CloudPolicyClient::NotifyClientError() { 573 void CloudPolicyClient::NotifyClientError() {
532 FOR_EACH_OBSERVER(Observer, observers_, OnClientError(this)); 574 FOR_EACH_OBSERVER(Observer, observers_, OnClientError(this));
533 } 575 }
534 576
535 } // namespace policy 577 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698