| 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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 // Sets the client ID or generate a new one. A new one is intentionally | 122 // Sets the client ID or generate a new one. A new one is intentionally |
| 123 // generated on each new registration request in order to preserve privacy. | 123 // generated on each new registration request in order to preserve privacy. |
| 124 // Reusing IDs would mean the server could track clients by their registration | 124 // Reusing IDs would mean the server could track clients by their registration |
| 125 // attempts. | 125 // attempts. |
| 126 void CloudPolicyClient::SetClientId(const std::string& client_id) { | 126 void CloudPolicyClient::SetClientId(const std::string& client_id) { |
| 127 client_id_ = client_id.empty() ? base::GenerateGUID() : client_id; | 127 client_id_ = client_id.empty() ? base::GenerateGUID() : client_id; |
| 128 } | 128 } |
| 129 | 129 |
| 130 void CloudPolicyClient::Register(em::DeviceRegisterRequest::Type type, | 130 void CloudPolicyClient::Register(em::DeviceRegisterRequest::Type type, |
| 131 em::DeviceRegisterRequest::Flavor flavor, | 131 em::DeviceRegisterRequest::Flavor flavor, |
| 132 em::LicenseType license_type, |
| 132 const std::string& auth_token, | 133 const std::string& auth_token, |
| 133 const std::string& client_id, | 134 const std::string& client_id, |
| 134 const std::string& requisition, | 135 const std::string& requisition, |
| 135 const std::string& current_state_key) { | 136 const std::string& current_state_key) { |
| 136 DCHECK(service_); | 137 DCHECK(service_); |
| 137 DCHECK(!auth_token.empty()); | 138 DCHECK(!auth_token.empty()); |
| 138 DCHECK(!is_registered()); | 139 DCHECK(!is_registered()); |
| 139 | 140 |
| 140 SetClientId(client_id); | 141 SetClientId(client_id); |
| 141 | 142 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 152 request->set_type(type); | 153 request->set_type(type); |
| 153 if (!machine_id_.empty()) | 154 if (!machine_id_.empty()) |
| 154 request->set_machine_id(machine_id_); | 155 request->set_machine_id(machine_id_); |
| 155 if (!machine_model_.empty()) | 156 if (!machine_model_.empty()) |
| 156 request->set_machine_model(machine_model_); | 157 request->set_machine_model(machine_model_); |
| 157 if (!requisition.empty()) | 158 if (!requisition.empty()) |
| 158 request->set_requisition(requisition); | 159 request->set_requisition(requisition); |
| 159 if (!current_state_key.empty()) | 160 if (!current_state_key.empty()) |
| 160 request->set_server_backed_state_key(current_state_key); | 161 request->set_server_backed_state_key(current_state_key); |
| 161 request->set_flavor(flavor); | 162 request->set_flavor(flavor); |
| 163 if (license_type != em::LicenseType::UNDEFINED) |
| 164 request->set_license_type(license_type); |
| 162 | 165 |
| 163 policy_fetch_request_job_->SetRetryCallback( | 166 policy_fetch_request_job_->SetRetryCallback( |
| 164 base::Bind(&CloudPolicyClient::OnRetryRegister, | 167 base::Bind(&CloudPolicyClient::OnRetryRegister, |
| 165 weak_ptr_factory_.GetWeakPtr())); | 168 weak_ptr_factory_.GetWeakPtr())); |
| 166 | 169 |
| 167 policy_fetch_request_job_->Start( | 170 policy_fetch_request_job_->Start( |
| 168 base::Bind(&CloudPolicyClient::OnRegisterCompleted, | 171 base::Bind(&CloudPolicyClient::OnRegisterCompleted, |
| 169 weak_ptr_factory_.GetWeakPtr())); | 172 weak_ptr_factory_.GetWeakPtr())); |
| 170 } | 173 } |
| 171 | 174 |
| 172 void CloudPolicyClient::RegisterWithCertificate( | 175 void CloudPolicyClient::RegisterWithCertificate( |
| 173 em::DeviceRegisterRequest::Type type, | 176 em::DeviceRegisterRequest::Type type, |
| 174 em::DeviceRegisterRequest::Flavor flavor, | 177 em::DeviceRegisterRequest::Flavor flavor, |
| 178 em::LicenseType license_type, |
| 175 const std::string& pem_certificate_chain, | 179 const std::string& pem_certificate_chain, |
| 176 const std::string& client_id, | 180 const std::string& client_id, |
| 177 const std::string& requisition, | 181 const std::string& requisition, |
| 178 const std::string& current_state_key) { | 182 const std::string& current_state_key) { |
| 179 DCHECK(signing_service_); | 183 DCHECK(signing_service_); |
| 180 DCHECK(service_); | 184 DCHECK(service_); |
| 181 DCHECK(!is_registered()); | 185 DCHECK(!is_registered()); |
| 182 | 186 |
| 183 SetClientId(client_id); | 187 SetClientId(client_id); |
| 184 | 188 |
| 185 em::CertificateBasedDeviceRegistrationData data; | 189 em::CertificateBasedDeviceRegistrationData data; |
| 186 data.set_certificate_type(em::CertificateBasedDeviceRegistrationData:: | 190 data.set_certificate_type(em::CertificateBasedDeviceRegistrationData:: |
| 187 ENTERPRISE_ENROLLMENT_CERTIFICATE); | 191 ENTERPRISE_ENROLLMENT_CERTIFICATE); |
| 188 data.set_device_certificate(pem_certificate_chain); | 192 data.set_device_certificate(pem_certificate_chain); |
| 189 | 193 |
| 190 em::DeviceRegisterRequest* request = data.mutable_device_register_request(); | 194 em::DeviceRegisterRequest* request = data.mutable_device_register_request(); |
| 191 if (!client_id.empty()) | 195 if (!client_id.empty()) |
| 192 request->set_reregister(true); | 196 request->set_reregister(true); |
| 193 request->set_type(type); | 197 request->set_type(type); |
| 194 if (!machine_id_.empty()) | 198 if (!machine_id_.empty()) |
| 195 request->set_machine_id(machine_id_); | 199 request->set_machine_id(machine_id_); |
| 196 if (!machine_model_.empty()) | 200 if (!machine_model_.empty()) |
| 197 request->set_machine_model(machine_model_); | 201 request->set_machine_model(machine_model_); |
| 198 if (!requisition.empty()) | 202 if (!requisition.empty()) |
| 199 request->set_requisition(requisition); | 203 request->set_requisition(requisition); |
| 200 if (!current_state_key.empty()) | 204 if (!current_state_key.empty()) |
| 201 request->set_server_backed_state_key(current_state_key); | 205 request->set_server_backed_state_key(current_state_key); |
| 202 request->set_flavor(flavor); | 206 request->set_flavor(flavor); |
| 207 if (license_type != em::LicenseType::UNDEFINED) |
| 208 request->set_license_type(license_type); |
| 203 | 209 |
| 204 signing_service_->SignData(data.SerializeAsString(), | 210 signing_service_->SignData(data.SerializeAsString(), |
| 205 base::Bind(&CloudPolicyClient::OnRegisterWithCertificateRequestSigned, | 211 base::Bind(&CloudPolicyClient::OnRegisterWithCertificateRequestSigned, |
| 206 weak_ptr_factory_.GetWeakPtr())); | 212 weak_ptr_factory_.GetWeakPtr())); |
| 207 } | 213 } |
| 208 | 214 |
| 209 void CloudPolicyClient::OnRegisterWithCertificateRequestSigned(bool success, | 215 void CloudPolicyClient::OnRegisterWithCertificateRequestSigned(bool success, |
| 210 em::SignedData signed_data) { | 216 em::SignedData signed_data) { |
| 211 if (!success) { | 217 if (!success) { |
| 212 const em::DeviceManagementResponse response; | 218 const em::DeviceManagementResponse response; |
| (...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 870 for (auto& observer : observers_) | 876 for (auto& observer : observers_) |
| 871 observer.OnRobotAuthCodesFetched(this); | 877 observer.OnRobotAuthCodesFetched(this); |
| 872 } | 878 } |
| 873 | 879 |
| 874 void CloudPolicyClient::NotifyClientError() { | 880 void CloudPolicyClient::NotifyClientError() { |
| 875 for (auto& observer : observers_) | 881 for (auto& observer : observers_) |
| 876 observer.OnClientError(this); | 882 observer.OnClientError(this); |
| 877 } | 883 } |
| 878 | 884 |
| 879 } // namespace policy | 885 } // namespace policy |
| OLD | NEW |