| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 public_key_version_(-1), | 62 public_key_version_(-1), |
| 63 public_key_version_valid_(false), | 63 public_key_version_valid_(false), |
| 64 invalidation_version_(0), | 64 invalidation_version_(0), |
| 65 fetched_invalidation_version_(0), | 65 fetched_invalidation_version_(0), |
| 66 service_(service), // Can be null for unit tests. | 66 service_(service), // Can be null for unit tests. |
| 67 status_(DM_STATUS_SUCCESS), | 67 status_(DM_STATUS_SUCCESS), |
| 68 request_context_(request_context) { | 68 request_context_(request_context) { |
| 69 } | 69 } |
| 70 | 70 |
| 71 CloudPolicyClient::~CloudPolicyClient() { | 71 CloudPolicyClient::~CloudPolicyClient() { |
| 72 STLDeleteValues(&responses_); | 72 base::STLDeleteValues(&responses_); |
| 73 } | 73 } |
| 74 | 74 |
| 75 void CloudPolicyClient::SetupRegistration(const std::string& dm_token, | 75 void CloudPolicyClient::SetupRegistration(const std::string& dm_token, |
| 76 const std::string& client_id) { | 76 const std::string& client_id) { |
| 77 DCHECK(!dm_token.empty()); | 77 DCHECK(!dm_token.empty()); |
| 78 DCHECK(!client_id.empty()); | 78 DCHECK(!client_id.empty()); |
| 79 DCHECK(!is_registered()); | 79 DCHECK(!is_registered()); |
| 80 | 80 |
| 81 dm_token_ = dm_token; | 81 dm_token_ = dm_token; |
| 82 client_id_ = client_id; | 82 client_id_ = client_id; |
| 83 request_jobs_.clear(); | 83 request_jobs_.clear(); |
| 84 policy_fetch_request_job_.reset(); | 84 policy_fetch_request_job_.reset(); |
| 85 STLDeleteValues(&responses_); | 85 base::STLDeleteValues(&responses_); |
| 86 | 86 |
| 87 NotifyRegistrationStateChanged(); | 87 NotifyRegistrationStateChanged(); |
| 88 } | 88 } |
| 89 | 89 |
| 90 void CloudPolicyClient::Register(em::DeviceRegisterRequest::Type type, | 90 void CloudPolicyClient::Register(em::DeviceRegisterRequest::Type type, |
| 91 em::DeviceRegisterRequest::Flavor flavor, | 91 em::DeviceRegisterRequest::Flavor flavor, |
| 92 const std::string& auth_token, | 92 const std::string& auth_token, |
| 93 const std::string& client_id, | 93 const std::string& client_id, |
| 94 const std::string& requisition, | 94 const std::string& requisition, |
| 95 const std::string& current_state_key) { | 95 const std::string& current_state_key) { |
| (...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 513 response.policy_response().response_size() == 0) { | 513 response.policy_response().response_size() == 0) { |
| 514 LOG(WARNING) << "Empty policy response."; | 514 LOG(WARNING) << "Empty policy response."; |
| 515 status = DM_STATUS_RESPONSE_DECODING_ERROR; | 515 status = DM_STATUS_RESPONSE_DECODING_ERROR; |
| 516 } | 516 } |
| 517 } | 517 } |
| 518 | 518 |
| 519 status_ = status; | 519 status_ = status; |
| 520 if (status == DM_STATUS_SUCCESS) { | 520 if (status == DM_STATUS_SUCCESS) { |
| 521 const em::DevicePolicyResponse& policy_response = | 521 const em::DevicePolicyResponse& policy_response = |
| 522 response.policy_response(); | 522 response.policy_response(); |
| 523 STLDeleteValues(&responses_); | 523 base::STLDeleteValues(&responses_); |
| 524 for (int i = 0; i < policy_response.response_size(); ++i) { | 524 for (int i = 0; i < policy_response.response_size(); ++i) { |
| 525 const em::PolicyFetchResponse& response = policy_response.response(i); | 525 const em::PolicyFetchResponse& response = policy_response.response(i); |
| 526 em::PolicyData policy_data; | 526 em::PolicyData policy_data; |
| 527 if (!policy_data.ParseFromString(response.policy_data()) || | 527 if (!policy_data.ParseFromString(response.policy_data()) || |
| 528 !policy_data.IsInitialized() || | 528 !policy_data.IsInitialized() || |
| 529 !policy_data.has_policy_type()) { | 529 !policy_data.has_policy_type()) { |
| 530 LOG(WARNING) << "Invalid PolicyData received, ignoring"; | 530 LOG(WARNING) << "Invalid PolicyData received, ignoring"; |
| 531 continue; | 531 continue; |
| 532 } | 532 } |
| 533 const std::string& type = policy_data.policy_type(); | 533 const std::string& type = policy_data.policy_type(); |
| 534 std::string entity_id; | 534 std::string entity_id; |
| 535 if (policy_data.has_settings_entity_id()) | 535 if (policy_data.has_settings_entity_id()) |
| 536 entity_id = policy_data.settings_entity_id(); | 536 entity_id = policy_data.settings_entity_id(); |
| 537 std::pair<std::string, std::string> key(type, entity_id); | 537 std::pair<std::string, std::string> key(type, entity_id); |
| 538 if (ContainsKey(responses_, key)) { | 538 if (base::ContainsKey(responses_, key)) { |
| 539 LOG(WARNING) << "Duplicate PolicyFetchResponse for type: " | 539 LOG(WARNING) << "Duplicate PolicyFetchResponse for type: " |
| 540 << type << ", entity: " << entity_id << ", ignoring"; | 540 << type << ", entity: " << entity_id << ", ignoring"; |
| 541 continue; | 541 continue; |
| 542 } | 542 } |
| 543 responses_[key] = new em::PolicyFetchResponse(response); | 543 responses_[key] = new em::PolicyFetchResponse(response); |
| 544 } | 544 } |
| 545 state_keys_to_upload_.clear(); | 545 state_keys_to_upload_.clear(); |
| 546 NotifyPolicyFetched(); | 546 NotifyPolicyFetched(); |
| 547 } else { | 547 } else { |
| 548 NotifyClientError(); | 548 NotifyClientError(); |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 717 | 717 |
| 718 void CloudPolicyClient::NotifyRobotAuthCodesFetched() { | 718 void CloudPolicyClient::NotifyRobotAuthCodesFetched() { |
| 719 FOR_EACH_OBSERVER(Observer, observers_, OnRobotAuthCodesFetched(this)); | 719 FOR_EACH_OBSERVER(Observer, observers_, OnRobotAuthCodesFetched(this)); |
| 720 } | 720 } |
| 721 | 721 |
| 722 void CloudPolicyClient::NotifyClientError() { | 722 void CloudPolicyClient::NotifyClientError() { |
| 723 FOR_EACH_OBSERVER(Observer, observers_, OnClientError(this)); | 723 FOR_EACH_OBSERVER(Observer, observers_, OnClientError(this)); |
| 724 } | 724 } |
| 725 | 725 |
| 726 } // namespace policy | 726 } // namespace policy |
| OLD | NEW |