Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 254 scoped_ptr<DeviceManagementRequestJob> request_job( | 254 scoped_ptr<DeviceManagementRequestJob> request_job( |
| 255 service_->CreateJob(DeviceManagementRequestJob::TYPE_UPLOAD_CERTIFICATE, | 255 service_->CreateJob(DeviceManagementRequestJob::TYPE_UPLOAD_CERTIFICATE, |
| 256 GetRequestContext())); | 256 GetRequestContext())); |
| 257 request_job->SetDMToken(dm_token_); | 257 request_job->SetDMToken(dm_token_); |
| 258 request_job->SetClientID(client_id_); | 258 request_job->SetClientID(client_id_); |
| 259 | 259 |
| 260 em::DeviceManagementRequest* request = request_job->GetRequest(); | 260 em::DeviceManagementRequest* request = request_job->GetRequest(); |
| 261 request->mutable_cert_upload_request()->set_device_certificate( | 261 request->mutable_cert_upload_request()->set_device_certificate( |
| 262 certificate_data); | 262 certificate_data); |
| 263 | 263 |
| 264 DeviceManagementRequestJob::Callback job_callback = base::Bind( | 264 const DeviceManagementRequestJob::Callback job_callback = |
| 265 &CloudPolicyClient::OnCertificateUploadCompleted, | 265 base::Bind(&CloudPolicyClient::OnCertificateUploadCompleted, |
| 266 base::Unretained(this), | 266 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.
| |
| 267 request_job.get(), | 267 |
| 268 callback); | |
| 269 request_jobs_.push_back(request_job.Pass()); | 268 request_jobs_.push_back(request_job.Pass()); |
| 270 request_jobs_.back()->Start(job_callback); | 269 request_jobs_.back()->Start(job_callback); |
| 271 } | 270 } |
| 272 | 271 |
| 273 void CloudPolicyClient::UploadDeviceStatus( | 272 void CloudPolicyClient::UploadDeviceStatus( |
| 274 const em::DeviceStatusReportRequest* device_status, | 273 const em::DeviceStatusReportRequest* device_status, |
| 275 const em::SessionStatusReportRequest* session_status, | 274 const em::SessionStatusReportRequest* session_status, |
| 276 const CloudPolicyClient::StatusCallback& callback) { | 275 const CloudPolicyClient::StatusCallback& callback) { |
| 277 CHECK(is_registered()); | 276 CHECK(is_registered()); |
| 278 // Should pass in at least one type of status. | 277 // Should pass in at least one type of status. |
| 279 DCHECK(device_status || session_status); | 278 DCHECK(device_status || session_status); |
| 280 scoped_ptr<DeviceManagementRequestJob> request_job( | 279 scoped_ptr<DeviceManagementRequestJob> request_job( |
| 281 service_->CreateJob(DeviceManagementRequestJob::TYPE_UPLOAD_STATUS, | 280 service_->CreateJob(DeviceManagementRequestJob::TYPE_UPLOAD_STATUS, |
| 282 GetRequestContext())); | 281 GetRequestContext())); |
| 283 request_job->SetDMToken(dm_token_); | 282 request_job->SetDMToken(dm_token_); |
| 284 request_job->SetClientID(client_id_); | 283 request_job->SetClientID(client_id_); |
| 285 | 284 |
| 286 em::DeviceManagementRequest* request = request_job->GetRequest(); | 285 em::DeviceManagementRequest* request = request_job->GetRequest(); |
| 287 if (device_status) | 286 if (device_status) |
| 288 *request->mutable_device_status_report_request() = *device_status; | 287 *request->mutable_device_status_report_request() = *device_status; |
| 289 if (session_status) | 288 if (session_status) |
| 290 *request->mutable_session_status_report_request() = *session_status; | 289 *request->mutable_session_status_report_request() = *session_status; |
| 291 | 290 |
| 292 DeviceManagementRequestJob::Callback job_callback = base::Bind( | 291 const DeviceManagementRequestJob::Callback job_callback = |
| 293 &CloudPolicyClient::OnStatusUploadCompleted, | 292 base::Bind(&CloudPolicyClient::OnStatusUploadCompleted, |
| 294 base::Unretained(this), | 293 base::Unretained(this), request_job.get(), callback); |
| 295 request_job.get(), | |
| 296 callback); | |
| 297 | 294 |
| 298 request_jobs_.push_back(request_job.Pass()); | 295 request_jobs_.push_back(request_job.Pass()); |
| 299 request_jobs_.back()->Start(job_callback); | 296 request_jobs_.back()->Start(job_callback); |
| 297 } | |
| 298 | |
| 299 void CloudPolicyClient::FetchRemoteCommands( | |
| 300 RemoteCommandJob::UniqueIDType last_command_id, | |
| 301 const std::vector<em::RemoteCommandResult>& command_results, | |
| 302 const RemoteCommandCallback& callback) { | |
| 303 CHECK(is_registered()); | |
| 304 scoped_ptr<DeviceManagementRequestJob> request_job(service_->CreateJob( | |
| 305 DeviceManagementRequestJob::TYPE_REMOTE_COMMANDS, GetRequestContext())); | |
| 306 | |
| 307 request_job->SetDMToken(dm_token_); | |
| 308 request_job->SetClientID(client_id_); | |
| 309 | |
| 310 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.
| |
| 311 request_job->GetRequest()->mutable_remote_command_request(); | |
| 312 | |
| 313 request->set_last_command_unique_id(last_command_id); | |
| 314 | |
| 315 for (const auto& command_result : command_results) | |
| 316 *request->add_command_results() = command_result; | |
| 317 | |
| 318 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.
| |
| 319 base::Bind(&CloudPolicyClient::OnRemoteCommandsFetched, | |
| 320 base::Unretained(this), request_job.get(), callback)); | |
| 321 | |
| 322 request_jobs_.push_back(request_job.Pass()); | |
| 323 request_jobs_.back()->Start(job_callback); | |
| 300 } | 324 } |
| 301 | 325 |
| 302 void CloudPolicyClient::AddObserver(Observer* observer) { | 326 void CloudPolicyClient::AddObserver(Observer* observer) { |
| 303 observers_.AddObserver(observer); | 327 observers_.AddObserver(observer); |
| 304 } | 328 } |
| 305 | 329 |
| 306 void CloudPolicyClient::RemoveObserver(Observer* observer) { | 330 void CloudPolicyClient::RemoveObserver(Observer* observer) { |
| 307 observers_.RemoveObserver(observer); | 331 observers_.RemoveObserver(observer); |
| 308 } | 332 } |
| 309 | 333 |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 509 const enterprise_management::DeviceManagementResponse& response) { | 533 const enterprise_management::DeviceManagementResponse& response) { |
| 510 status_ = status; | 534 status_ = status; |
| 511 if (status != DM_STATUS_SUCCESS) | 535 if (status != DM_STATUS_SUCCESS) |
| 512 NotifyClientError(); | 536 NotifyClientError(); |
| 513 | 537 |
| 514 callback.Run(status == DM_STATUS_SUCCESS); | 538 callback.Run(status == DM_STATUS_SUCCESS); |
| 515 // Must call RemoveJob() last, because it frees |callback|. | 539 // Must call RemoveJob() last, because it frees |callback|. |
| 516 RemoveJob(job); | 540 RemoveJob(job); |
| 517 } | 541 } |
| 518 | 542 |
| 543 void CloudPolicyClient::OnRemoteCommandsFetched( | |
| 544 const DeviceManagementRequestJob* job, | |
| 545 const RemoteCommandCallback& callback, | |
| 546 DeviceManagementStatus status, | |
| 547 int net_error, | |
| 548 const enterprise_management::DeviceManagementResponse& response) { | |
| 549 std::vector<enterprise_management::RemoteCommand> commands; | |
| 550 if (status == DM_STATUS_SUCCESS && response.has_remote_command_response()) { | |
| 551 for (const auto& command : response.remote_command_response().commands()) | |
| 552 commands.push_back(command); | |
| 553 } else { | |
| 554 NotifyClientError(); | |
|
bartfab (slow)
2015/02/28 00:01:22
NotifyClientError() will tell all consumers that s
binjin
2015/02/28 02:18:04
Done.
| |
| 555 } | |
| 556 callback.Run(commands); | |
| 557 // Must call RemoveJob() last, because it frees |callback|. | |
| 558 RemoveJob(job); | |
| 559 } | |
| 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 |
| OLD | NEW |