| 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/bind_helpers.h" |
| 9 #include "base/guid.h" | 9 #include "base/guid.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 request->set_location(location); | 370 request->set_location(location); |
| 371 | 371 |
| 372 const DeviceManagementRequestJob::Callback job_callback = | 372 const DeviceManagementRequestJob::Callback job_callback = |
| 373 base::Bind(&CloudPolicyClient::OnDeviceAttributeUpdated, | 373 base::Bind(&CloudPolicyClient::OnDeviceAttributeUpdated, |
| 374 base::Unretained(this), request_job.get(), callback); | 374 base::Unretained(this), request_job.get(), callback); |
| 375 | 375 |
| 376 request_jobs_.push_back(request_job.Pass()); | 376 request_jobs_.push_back(request_job.Pass()); |
| 377 request_jobs_.back()->Start(job_callback); | 377 request_jobs_.back()->Start(job_callback); |
| 378 } | 378 } |
| 379 | 379 |
| 380 void CloudPolicyClient::UpdateGcmId( |
| 381 const std::string& gcm_id, |
| 382 const CloudPolicyClient::StatusCallback& callback) { |
| 383 CHECK(is_registered()); |
| 384 |
| 385 scoped_ptr<DeviceManagementRequestJob> request_job(service_->CreateJob( |
| 386 DeviceManagementRequestJob::TYPE_GCM_ID_UPDATE, GetRequestContext())); |
| 387 |
| 388 request_job->SetDMToken(dm_token_); |
| 389 request_job->SetClientID(client_id_); |
| 390 |
| 391 em::GcmIdUpdateRequest* const request = |
| 392 request_job->GetRequest()->mutable_gcm_id_update_request(); |
| 393 |
| 394 request->set_gcm_id(gcm_id); |
| 395 |
| 396 const DeviceManagementRequestJob::Callback job_callback = |
| 397 base::Bind(&CloudPolicyClient::OnGcmIdUpdated, base::Unretained(this), |
| 398 request_job.get(), callback); |
| 399 |
| 400 request_jobs_.push_back(request_job.Pass()); |
| 401 request_jobs_.back()->Start(job_callback); |
| 402 } |
| 403 |
| 380 void CloudPolicyClient::AddObserver(Observer* observer) { | 404 void CloudPolicyClient::AddObserver(Observer* observer) { |
| 381 observers_.AddObserver(observer); | 405 observers_.AddObserver(observer); |
| 382 } | 406 } |
| 383 | 407 |
| 384 void CloudPolicyClient::RemoveObserver(Observer* observer) { | 408 void CloudPolicyClient::RemoveObserver(Observer* observer) { |
| 385 observers_.RemoveObserver(observer); | 409 observers_.RemoveObserver(observer); |
| 386 } | 410 } |
| 387 | 411 |
| 388 void CloudPolicyClient::AddPolicyTypeToFetch( | 412 void CloudPolicyClient::AddPolicyTypeToFetch( |
| 389 const std::string& policy_type, | 413 const std::string& policy_type, |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 658 commands.push_back(command); | 682 commands.push_back(command); |
| 659 } else { | 683 } else { |
| 660 status = DM_STATUS_RESPONSE_DECODING_ERROR; | 684 status = DM_STATUS_RESPONSE_DECODING_ERROR; |
| 661 } | 685 } |
| 662 } | 686 } |
| 663 callback.Run(status, commands); | 687 callback.Run(status, commands); |
| 664 // Must call RemoveJob() last, because it frees |callback|. | 688 // Must call RemoveJob() last, because it frees |callback|. |
| 665 RemoveJob(job); | 689 RemoveJob(job); |
| 666 } | 690 } |
| 667 | 691 |
| 692 void CloudPolicyClient::OnGcmIdUpdated( |
| 693 const DeviceManagementRequestJob* job, |
| 694 const StatusCallback& callback, |
| 695 DeviceManagementStatus status, |
| 696 int net_error, |
| 697 const enterprise_management::DeviceManagementResponse& response) { |
| 698 status_ = status; |
| 699 if (status != DM_STATUS_SUCCESS) |
| 700 NotifyClientError(); |
| 701 |
| 702 callback.Run(status == DM_STATUS_SUCCESS); |
| 703 RemoveJob(job); |
| 704 } |
| 705 |
| 668 void CloudPolicyClient::NotifyPolicyFetched() { | 706 void CloudPolicyClient::NotifyPolicyFetched() { |
| 669 FOR_EACH_OBSERVER(Observer, observers_, OnPolicyFetched(this)); | 707 FOR_EACH_OBSERVER(Observer, observers_, OnPolicyFetched(this)); |
| 670 } | 708 } |
| 671 | 709 |
| 672 void CloudPolicyClient::NotifyRegistrationStateChanged() { | 710 void CloudPolicyClient::NotifyRegistrationStateChanged() { |
| 673 FOR_EACH_OBSERVER(Observer, observers_, OnRegistrationStateChanged(this)); | 711 FOR_EACH_OBSERVER(Observer, observers_, OnRegistrationStateChanged(this)); |
| 674 } | 712 } |
| 675 | 713 |
| 676 void CloudPolicyClient::NotifyRobotAuthCodesFetched() { | 714 void CloudPolicyClient::NotifyRobotAuthCodesFetched() { |
| 677 FOR_EACH_OBSERVER(Observer, observers_, OnRobotAuthCodesFetched(this)); | 715 FOR_EACH_OBSERVER(Observer, observers_, OnRobotAuthCodesFetched(this)); |
| 678 } | 716 } |
| 679 | 717 |
| 680 void CloudPolicyClient::NotifyClientError() { | 718 void CloudPolicyClient::NotifyClientError() { |
| 681 FOR_EACH_OBSERVER(Observer, observers_, OnClientError(this)); | 719 FOR_EACH_OBSERVER(Observer, observers_, OnClientError(this)); |
| 682 } | 720 } |
| 683 | 721 |
| 684 } // namespace policy | 722 } // namespace policy |
| OLD | NEW |