| 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/bind_helpers.h" | 
| 8 #include "base/guid.h" | 9 #include "base/guid.h" | 
| 9 #include "base/logging.h" | 10 #include "base/logging.h" | 
| 10 #include "base/stl_util.h" | 11 #include "base/stl_util.h" | 
| 11 #include "components/policy/core/common/cloud/device_management_service.h" | 12 #include "components/policy/core/common/cloud/device_management_service.h" | 
| 12 #include "google_apis/gaia/gaia_constants.h" | 13 #include "google_apis/gaia/gaia_constants.h" | 
| 13 #include "google_apis/gaia/gaia_urls.h" | 14 #include "google_apis/gaia/gaia_urls.h" | 
| 14 #include "net/url_request/url_request_context_getter.h" | 15 #include "net/url_request/url_request_context_getter.h" | 
| 15 | 16 | 
| 16 namespace em = enterprise_management; | 17 namespace em = enterprise_management; | 
| 17 | 18 | 
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 254   scoped_ptr<DeviceManagementRequestJob> request_job( | 255   scoped_ptr<DeviceManagementRequestJob> request_job( | 
| 255       service_->CreateJob(DeviceManagementRequestJob::TYPE_UPLOAD_CERTIFICATE, | 256       service_->CreateJob(DeviceManagementRequestJob::TYPE_UPLOAD_CERTIFICATE, | 
| 256                           GetRequestContext())); | 257                           GetRequestContext())); | 
| 257   request_job->SetDMToken(dm_token_); | 258   request_job->SetDMToken(dm_token_); | 
| 258   request_job->SetClientID(client_id_); | 259   request_job->SetClientID(client_id_); | 
| 259 | 260 | 
| 260   em::DeviceManagementRequest* request = request_job->GetRequest(); | 261   em::DeviceManagementRequest* request = request_job->GetRequest(); | 
| 261   request->mutable_cert_upload_request()->set_device_certificate( | 262   request->mutable_cert_upload_request()->set_device_certificate( | 
| 262       certificate_data); | 263       certificate_data); | 
| 263 | 264 | 
| 264   DeviceManagementRequestJob::Callback job_callback = base::Bind( | 265   const DeviceManagementRequestJob::Callback job_callback = | 
| 265       &CloudPolicyClient::OnCertificateUploadCompleted, | 266       base::Bind(&CloudPolicyClient::OnCertificateUploadCompleted, | 
| 266       base::Unretained(this), | 267                  base::Unretained(this), request_job.get(), callback); | 
| 267       request_job.get(), | 268 | 
| 268       callback); |  | 
| 269   request_jobs_.push_back(request_job.Pass()); | 269   request_jobs_.push_back(request_job.Pass()); | 
| 270   request_jobs_.back()->Start(job_callback); | 270   request_jobs_.back()->Start(job_callback); | 
| 271 } | 271 } | 
| 272 | 272 | 
| 273 void CloudPolicyClient::UploadDeviceStatus( | 273 void CloudPolicyClient::UploadDeviceStatus( | 
| 274     const em::DeviceStatusReportRequest* device_status, | 274     const em::DeviceStatusReportRequest* device_status, | 
| 275     const em::SessionStatusReportRequest* session_status, | 275     const em::SessionStatusReportRequest* session_status, | 
| 276     const CloudPolicyClient::StatusCallback& callback) { | 276     const CloudPolicyClient::StatusCallback& callback) { | 
| 277   CHECK(is_registered()); | 277   CHECK(is_registered()); | 
| 278   // Should pass in at least one type of status. | 278   // Should pass in at least one type of status. | 
| 279   DCHECK(device_status || session_status); | 279   DCHECK(device_status || session_status); | 
| 280   scoped_ptr<DeviceManagementRequestJob> request_job( | 280   scoped_ptr<DeviceManagementRequestJob> request_job( | 
| 281       service_->CreateJob(DeviceManagementRequestJob::TYPE_UPLOAD_STATUS, | 281       service_->CreateJob(DeviceManagementRequestJob::TYPE_UPLOAD_STATUS, | 
| 282                           GetRequestContext())); | 282                           GetRequestContext())); | 
| 283   request_job->SetDMToken(dm_token_); | 283   request_job->SetDMToken(dm_token_); | 
| 284   request_job->SetClientID(client_id_); | 284   request_job->SetClientID(client_id_); | 
| 285 | 285 | 
| 286   em::DeviceManagementRequest* request = request_job->GetRequest(); | 286   em::DeviceManagementRequest* request = request_job->GetRequest(); | 
| 287   if (device_status) | 287   if (device_status) | 
| 288     *request->mutable_device_status_report_request() = *device_status; | 288     *request->mutable_device_status_report_request() = *device_status; | 
| 289   if (session_status) | 289   if (session_status) | 
| 290     *request->mutable_session_status_report_request() = *session_status; | 290     *request->mutable_session_status_report_request() = *session_status; | 
| 291 | 291 | 
| 292   DeviceManagementRequestJob::Callback job_callback = base::Bind( | 292   const DeviceManagementRequestJob::Callback job_callback = | 
| 293       &CloudPolicyClient::OnStatusUploadCompleted, | 293       base::Bind(&CloudPolicyClient::OnStatusUploadCompleted, | 
| 294       base::Unretained(this), | 294                  base::Unretained(this), request_job.get(), callback); | 
| 295       request_job.get(), |  | 
| 296       callback); |  | 
| 297 | 295 | 
| 298   request_jobs_.push_back(request_job.Pass()); | 296   request_jobs_.push_back(request_job.Pass()); | 
| 299   request_jobs_.back()->Start(job_callback); | 297   request_jobs_.back()->Start(job_callback); | 
|  | 298 } | 
|  | 299 | 
|  | 300 void CloudPolicyClient::FetchRemoteCommands( | 
|  | 301     scoped_ptr<RemoteCommandJob::UniqueIDType> last_command_id, | 
|  | 302     const std::vector<em::RemoteCommandResult>& command_results, | 
|  | 303     const RemoteCommandCallback& callback) { | 
|  | 304   CHECK(is_registered()); | 
|  | 305   scoped_ptr<DeviceManagementRequestJob> request_job(service_->CreateJob( | 
|  | 306       DeviceManagementRequestJob::TYPE_REMOTE_COMMANDS, GetRequestContext())); | 
|  | 307 | 
|  | 308   request_job->SetDMToken(dm_token_); | 
|  | 309   request_job->SetClientID(client_id_); | 
|  | 310 | 
|  | 311   em::DeviceRemoteCommandRequest* const request = | 
|  | 312       request_job->GetRequest()->mutable_remote_command_request(); | 
|  | 313 | 
|  | 314   if (last_command_id) | 
|  | 315     request->set_last_command_unique_id(*last_command_id); | 
|  | 316 | 
|  | 317   for (const auto& command_result : command_results) | 
|  | 318     *request->add_command_results() = command_result; | 
|  | 319 | 
|  | 320   const DeviceManagementRequestJob::Callback job_callback = | 
|  | 321       base::Bind(&CloudPolicyClient::OnRemoteCommandsFetched, | 
|  | 322                  base::Unretained(this), request_job.get(), callback); | 
|  | 323 | 
|  | 324   request_jobs_.push_back(request_job.Pass()); | 
|  | 325   request_jobs_.back()->Start(job_callback); | 
| 300 } | 326 } | 
| 301 | 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 | 
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 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) { | 
|  | 553     if (response.has_remote_command_response()) { | 
|  | 554       for (const auto& command : response.remote_command_response().commands()) | 
|  | 555         commands.push_back(command); | 
|  | 556     } else { | 
|  | 557       status = DM_STATUS_RESPONSE_DECODING_ERROR; | 
|  | 558     } | 
|  | 559   } | 
|  | 560   callback.Run(status, commands); | 
|  | 561   // Must call RemoveJob() last, because it frees |callback|. | 
|  | 562   RemoveJob(job); | 
|  | 563 } | 
|  | 564 | 
| 519 void CloudPolicyClient::NotifyPolicyFetched() { | 565 void CloudPolicyClient::NotifyPolicyFetched() { | 
| 520   FOR_EACH_OBSERVER(Observer, observers_, OnPolicyFetched(this)); | 566   FOR_EACH_OBSERVER(Observer, observers_, OnPolicyFetched(this)); | 
| 521 } | 567 } | 
| 522 | 568 | 
| 523 void CloudPolicyClient::NotifyRegistrationStateChanged() { | 569 void CloudPolicyClient::NotifyRegistrationStateChanged() { | 
| 524   FOR_EACH_OBSERVER(Observer, observers_, OnRegistrationStateChanged(this)); | 570   FOR_EACH_OBSERVER(Observer, observers_, OnRegistrationStateChanged(this)); | 
| 525 } | 571 } | 
| 526 | 572 | 
| 527 void CloudPolicyClient::NotifyRobotAuthCodesFetched() { | 573 void CloudPolicyClient::NotifyRobotAuthCodesFetched() { | 
| 528   FOR_EACH_OBSERVER(Observer, observers_, OnRobotAuthCodesFetched(this)); | 574   FOR_EACH_OBSERVER(Observer, observers_, OnRobotAuthCodesFetched(this)); | 
| 529 } | 575 } | 
| 530 | 576 | 
| 531 void CloudPolicyClient::NotifyClientError() { | 577 void CloudPolicyClient::NotifyClientError() { | 
| 532   FOR_EACH_OBSERVER(Observer, observers_, OnClientError(this)); | 578   FOR_EACH_OBSERVER(Observer, observers_, OnClientError(this)); | 
| 533 } | 579 } | 
| 534 | 580 | 
| 535 }  // namespace policy | 581 }  // namespace policy | 
| OLD | NEW | 
|---|