| 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 "chrome/browser/policy/cloud_policy_client.h" | 5 #include "chrome/browser/policy/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 "chrome/browser/policy/device_management_service.h" | 10 #include "chrome/browser/policy/device_management_service.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 | 32 |
| 33 } // namespace | 33 } // namespace |
| 34 | 34 |
| 35 CloudPolicyClient::Observer::~Observer() {} | 35 CloudPolicyClient::Observer::~Observer() {} |
| 36 | 36 |
| 37 CloudPolicyClient::StatusProvider::~StatusProvider() {} | 37 CloudPolicyClient::StatusProvider::~StatusProvider() {} |
| 38 | 38 |
| 39 CloudPolicyClient::CloudPolicyClient(const std::string& machine_id, | 39 CloudPolicyClient::CloudPolicyClient(const std::string& machine_id, |
| 40 const std::string& machine_model, | 40 const std::string& machine_model, |
| 41 UserAffiliation user_affiliation, | 41 UserAffiliation user_affiliation, |
| 42 PolicyScope scope, | 42 PolicyType type, |
| 43 StatusProvider* status_provider, | 43 StatusProvider* status_provider, |
| 44 DeviceManagementService* service) | 44 DeviceManagementService* service) |
| 45 : machine_id_(machine_id), | 45 : machine_id_(machine_id), |
| 46 machine_model_(machine_model), | 46 machine_model_(machine_model), |
| 47 user_affiliation_(user_affiliation), | 47 user_affiliation_(user_affiliation), |
| 48 scope_(scope), | 48 type_(type), |
| 49 device_mode_(DEVICE_MODE_NOT_SET), | 49 device_mode_(DEVICE_MODE_NOT_SET), |
| 50 submit_machine_id_(false), | 50 submit_machine_id_(false), |
| 51 public_key_version_(-1), | 51 public_key_version_(-1), |
| 52 public_key_version_valid_(false), | 52 public_key_version_valid_(false), |
| 53 service_(service), // Can be NULL for unit tests. | 53 service_(service), // Can be NULL for unit tests. |
| 54 status_provider_(status_provider), // Can be NULL for unit tests. | 54 status_provider_(status_provider), // Can be NULL for unit tests. |
| 55 status_(DM_STATUS_SUCCESS) { | 55 status_(DM_STATUS_SUCCESS) { |
| 56 } | 56 } |
| 57 | 57 |
| 58 CloudPolicyClient::~CloudPolicyClient() {} | 58 CloudPolicyClient::~CloudPolicyClient() {} |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 policy_request->set_signature_type(em::PolicyFetchRequest::SHA1_RSA); | 115 policy_request->set_signature_type(em::PolicyFetchRequest::SHA1_RSA); |
| 116 SetPolicyType(policy_request); | 116 SetPolicyType(policy_request); |
| 117 if (!last_policy_timestamp_.is_null()) { | 117 if (!last_policy_timestamp_.is_null()) { |
| 118 base::TimeDelta timestamp(last_policy_timestamp_ - base::Time::UnixEpoch()); | 118 base::TimeDelta timestamp(last_policy_timestamp_ - base::Time::UnixEpoch()); |
| 119 policy_request->set_timestamp(timestamp.InMilliseconds()); | 119 policy_request->set_timestamp(timestamp.InMilliseconds()); |
| 120 } | 120 } |
| 121 if (submit_machine_id_ && !machine_id_.empty()) | 121 if (submit_machine_id_ && !machine_id_.empty()) |
| 122 policy_request->set_machine_id(machine_id_); | 122 policy_request->set_machine_id(machine_id_); |
| 123 if (public_key_version_valid_) | 123 if (public_key_version_valid_) |
| 124 policy_request->set_public_key_version(public_key_version_); | 124 policy_request->set_public_key_version(public_key_version_); |
| 125 if (!entity_id_.empty()) |
| 126 policy_request->set_settings_entity_id(entity_id_); |
| 125 | 127 |
| 126 // Add status data. | 128 // Add status data. |
| 127 if (status_provider_) { | 129 if (status_provider_) { |
| 128 if (!status_provider_->GetDeviceStatus( | 130 if (!status_provider_->GetDeviceStatus( |
| 129 request->mutable_device_status_report_request())) { | 131 request->mutable_device_status_report_request())) { |
| 130 request->clear_device_status_report_request(); | 132 request->clear_device_status_report_request(); |
| 131 } | 133 } |
| 132 if (!status_provider_->GetSessionStatus( | 134 if (!status_provider_->GetSessionStatus( |
| 133 request->mutable_session_status_report_request())) { | 135 request->mutable_session_status_report_request())) { |
| 134 request->clear_session_status_report_request(); | 136 request->clear_session_status_report_request(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 154 void CloudPolicyClient::AddObserver(Observer* observer) { | 156 void CloudPolicyClient::AddObserver(Observer* observer) { |
| 155 observers_.AddObserver(observer); | 157 observers_.AddObserver(observer); |
| 156 } | 158 } |
| 157 | 159 |
| 158 void CloudPolicyClient::RemoveObserver(Observer* observer) { | 160 void CloudPolicyClient::RemoveObserver(Observer* observer) { |
| 159 observers_.RemoveObserver(observer); | 161 observers_.RemoveObserver(observer); |
| 160 } | 162 } |
| 161 | 163 |
| 162 void CloudPolicyClient::SetRegistrationType( | 164 void CloudPolicyClient::SetRegistrationType( |
| 163 em::DeviceRegisterRequest* request) const { | 165 em::DeviceRegisterRequest* request) const { |
| 164 switch (scope_) { | 166 switch (type_) { |
| 165 case POLICY_SCOPE_USER: | 167 case POLICY_TYPE_USER: |
| 166 request->set_type(em::DeviceRegisterRequest::USER); | 168 request->set_type(em::DeviceRegisterRequest::USER); |
| 167 return; | 169 return; |
| 168 case POLICY_SCOPE_MACHINE: | 170 case POLICY_TYPE_DEVICE: |
| 169 request->set_type(em::DeviceRegisterRequest::DEVICE); | 171 request->set_type(em::DeviceRegisterRequest::DEVICE); |
| 170 return; | 172 return; |
| 173 case POLICY_TYPE_PUBLIC_ACCOUNT: |
| 174 LOG(FATAL) << "Cannot register for public account policy."; |
| 175 return; |
| 171 } | 176 } |
| 172 NOTREACHED() << "Invalid policy scope " << scope_; | 177 NOTREACHED() << "Invalid policy type " << type_; |
| 173 } | 178 } |
| 174 | 179 |
| 175 void CloudPolicyClient::SetPolicyType(em::PolicyFetchRequest* request) const { | 180 void CloudPolicyClient::SetPolicyType(em::PolicyFetchRequest* request) const { |
| 176 switch (scope_) { | 181 switch (type_) { |
| 177 case POLICY_SCOPE_USER: | 182 case POLICY_TYPE_USER: |
| 178 request->set_policy_type(dm_protocol::kChromeUserPolicyType); | 183 request->set_policy_type(dm_protocol::kChromeUserPolicyType); |
| 179 return; | 184 return; |
| 180 case POLICY_SCOPE_MACHINE: | 185 case POLICY_TYPE_DEVICE: |
| 181 request->set_policy_type(dm_protocol::kChromeDevicePolicyType); | 186 request->set_policy_type(dm_protocol::kChromeDevicePolicyType); |
| 182 return; | 187 return; |
| 188 case POLICY_TYPE_PUBLIC_ACCOUNT: |
| 189 request->set_policy_type(dm_protocol::kChromePublicAccountPolicyType); |
| 190 return; |
| 183 } | 191 } |
| 184 NOTREACHED() << "Invalid policy scope " << scope_; | 192 NOTREACHED() << "Invalid policy type " << type_; |
| 185 } | 193 } |
| 186 | 194 |
| 187 void CloudPolicyClient::OnRegisterCompleted( | 195 void CloudPolicyClient::OnRegisterCompleted( |
| 188 DeviceManagementStatus status, | 196 DeviceManagementStatus status, |
| 189 const em::DeviceManagementResponse& response) { | 197 const em::DeviceManagementResponse& response) { |
| 190 if (status == DM_STATUS_SUCCESS && | 198 if (status == DM_STATUS_SUCCESS && |
| 191 (!response.has_register_response() || | 199 (!response.has_register_response() || |
| 192 !response.register_response().has_device_management_token())) { | 200 !response.register_response().has_device_management_token())) { |
| 193 LOG(WARNING) << "Invalid registration response."; | 201 LOG(WARNING) << "Invalid registration response."; |
| 194 status = DM_STATUS_RESPONSE_DECODING_ERROR; | 202 status = DM_STATUS_RESPONSE_DECODING_ERROR; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 | 268 |
| 261 void CloudPolicyClient::NotifyRegistrationStateChanged() { | 269 void CloudPolicyClient::NotifyRegistrationStateChanged() { |
| 262 FOR_EACH_OBSERVER(Observer, observers_, OnRegistrationStateChanged(this)); | 270 FOR_EACH_OBSERVER(Observer, observers_, OnRegistrationStateChanged(this)); |
| 263 } | 271 } |
| 264 | 272 |
| 265 void CloudPolicyClient::NotifyClientError() { | 273 void CloudPolicyClient::NotifyClientError() { |
| 266 FOR_EACH_OBSERVER(Observer, observers_, OnClientError(this)); | 274 FOR_EACH_OBSERVER(Observer, observers_, OnClientError(this)); |
| 267 } | 275 } |
| 268 | 276 |
| 269 } // namespace policy | 277 } // namespace policy |
| OLD | NEW |