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/chromeos/settings/session_manager_operation.h" | 5 #include "chrome/browser/chromeos/settings/session_manager_operation.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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
63 return; | 63 return; |
64 is_loading_ = true; | 64 is_loading_ = true; |
65 if (cloud_validations_) { | 65 if (cloud_validations_) { |
66 EnsurePublicKey(base::Bind(&SessionManagerOperation::RetrieveDeviceSettings, | 66 EnsurePublicKey(base::Bind(&SessionManagerOperation::RetrieveDeviceSettings, |
67 weak_factory_.GetWeakPtr())); | 67 weak_factory_.GetWeakPtr())); |
68 } else { | 68 } else { |
69 RetrieveDeviceSettings(); | 69 RetrieveDeviceSettings(); |
70 } | 70 } |
71 } | 71 } |
72 | 72 |
73 void SessionManagerOperation::LoadImmediately() { | |
74 StorePublicKey( | |
75 base::Bind(&SessionManagerOperation::BlockingRetrieveDeviceSettings, | |
76 weak_factory_.GetWeakPtr()), | |
77 LoadPublicKey(owner_key_util_, public_key_)); | |
78 } | |
79 | |
73 void SessionManagerOperation::ReportResult( | 80 void SessionManagerOperation::ReportResult( |
74 DeviceSettingsService::Status status) { | 81 DeviceSettingsService::Status status) { |
75 callback_.Run(this, status); | 82 callback_.Run(this, status); |
76 } | 83 } |
77 | 84 |
78 void SessionManagerOperation::EnsurePublicKey(const base::Closure& callback) { | 85 void SessionManagerOperation::EnsurePublicKey(const base::Closure& callback) { |
79 if (force_key_load_ || !public_key_.get() || !public_key_->is_loaded()) { | 86 if (force_key_load_ || !public_key_.get() || !public_key_->is_loaded()) { |
80 scoped_refptr<base::TaskRunner> task_runner = | 87 scoped_refptr<base::TaskRunner> task_runner = |
81 content::BrowserThread::GetBlockingPool() | 88 content::BrowserThread::GetBlockingPool() |
82 ->GetTaskRunnerWithShutdownBehavior( | 89 ->GetTaskRunnerWithShutdownBehavior( |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
125 | 132 |
126 callback.Run(); | 133 callback.Run(); |
127 } | 134 } |
128 | 135 |
129 void SessionManagerOperation::RetrieveDeviceSettings() { | 136 void SessionManagerOperation::RetrieveDeviceSettings() { |
130 session_manager_client()->RetrieveDevicePolicy( | 137 session_manager_client()->RetrieveDevicePolicy( |
131 base::Bind(&SessionManagerOperation::ValidateDeviceSettings, | 138 base::Bind(&SessionManagerOperation::ValidateDeviceSettings, |
132 weak_factory_.GetWeakPtr())); | 139 weak_factory_.GetWeakPtr())); |
133 } | 140 } |
134 | 141 |
142 void SessionManagerOperation::BlockingRetrieveDeviceSettings() { | |
143 ValidateDeviceSettings( | |
144 session_manager_client()->BlockingRetrieveDevicePolicy()); | |
145 } | |
146 | |
135 void SessionManagerOperation::ValidateDeviceSettings( | 147 void SessionManagerOperation::ValidateDeviceSettings( |
136 const std::string& policy_blob) { | 148 const std::string& policy_blob) { |
137 std::unique_ptr<em::PolicyFetchResponse> policy( | 149 std::unique_ptr<em::PolicyFetchResponse> policy( |
138 new em::PolicyFetchResponse()); | 150 new em::PolicyFetchResponse()); |
139 if (policy_blob.empty()) { | 151 if (policy_blob.empty()) { |
140 ReportResult(DeviceSettingsService::STORE_NO_POLICY); | 152 ReportResult(DeviceSettingsService::STORE_NO_POLICY); |
141 return; | 153 return; |
142 } | 154 } |
143 | 155 |
144 if (!policy->ParseFromString(policy_blob) || | 156 if (!policy->ParseFromString(policy_blob) || |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
184 policy::CloudPolicyValidatorBase::DM_TOKEN_NOT_REQUIRED, | 196 policy::CloudPolicyValidatorBase::DM_TOKEN_NOT_REQUIRED, |
185 policy::CloudPolicyValidatorBase::DEVICE_ID_NOT_REQUIRED); | 197 policy::CloudPolicyValidatorBase::DEVICE_ID_NOT_REQUIRED); |
186 | 198 |
187 // We don't check the DMServer verification key below, because the signing | 199 // We don't check the DMServer verification key below, because the signing |
188 // key is validated when it is installed. | 200 // key is validated when it is installed. |
189 validator->ValidateSignature(public_key_->as_string()); | 201 validator->ValidateSignature(public_key_->as_string()); |
190 } | 202 } |
191 | 203 |
192 validator->ValidatePolicyType(policy::dm_protocol::kChromeDevicePolicyType); | 204 validator->ValidatePolicyType(policy::dm_protocol::kChromeDevicePolicyType); |
193 validator->ValidatePayload(); | 205 validator->ValidatePayload(); |
194 validator->StartValidation( | 206 if (force_immediate_load_) { |
195 base::Bind(&SessionManagerOperation::ReportValidatorStatus, | 207 validator->RunValidation(); |
196 weak_factory_.GetWeakPtr())); | 208 ReportValidatorStatus(validator); |
emaxx
2017/02/28 14:31:31
Isn't the validator leaking in this case?
If so, t
Sergey Poromov
2017/02/28 15:47:37
Done.
| |
209 } else { | |
210 validator->StartValidation( | |
211 base::Bind(&SessionManagerOperation::ReportValidatorStatus, | |
212 weak_factory_.GetWeakPtr())); | |
213 } | |
197 } | 214 } |
198 | 215 |
199 void SessionManagerOperation::ReportValidatorStatus( | 216 void SessionManagerOperation::ReportValidatorStatus( |
200 policy::DeviceCloudPolicyValidator* validator) { | 217 policy::DeviceCloudPolicyValidator* validator) { |
201 DeviceSettingsService::Status status = | 218 DeviceSettingsService::Status status = |
202 DeviceSettingsService::STORE_VALIDATION_ERROR; | 219 DeviceSettingsService::STORE_VALIDATION_ERROR; |
203 if (validator->success()) { | 220 if (validator->success()) { |
204 status = DeviceSettingsService::STORE_SUCCESS; | 221 status = DeviceSettingsService::STORE_SUCCESS; |
205 policy_data_ = std::move(validator->policy_data()); | 222 policy_data_ = std::move(validator->policy_data()); |
206 device_settings_ = std::move(validator->payload()); | 223 device_settings_ = std::move(validator->payload()); |
207 } else { | 224 } else { |
208 LOG(ERROR) << "Policy validation failed: " << validator->status(); | 225 LOG(ERROR) << "Policy validation failed: " << validator->status(); |
209 | 226 |
210 // Those are mostly caused by RTC loss and are recoverable. | 227 // Those are mostly caused by RTC loss and are recoverable. |
211 if (validator->status() == | 228 if (validator->status() == |
212 policy::DeviceCloudPolicyValidator::VALIDATION_BAD_TIMESTAMP) { | 229 policy::DeviceCloudPolicyValidator::VALIDATION_BAD_TIMESTAMP) { |
213 status = DeviceSettingsService::STORE_TEMP_VALIDATION_ERROR; | 230 status = DeviceSettingsService::STORE_TEMP_VALIDATION_ERROR; |
214 } | 231 } |
215 } | 232 } |
216 | 233 |
217 ReportResult(status); | 234 ReportResult(status); |
218 } | 235 } |
219 | 236 |
220 LoadSettingsOperation::LoadSettingsOperation(bool force_key_load, | 237 LoadSettingsOperation::LoadSettingsOperation(bool force_key_load, |
221 bool cloud_validations, | 238 bool cloud_validations, |
239 bool force_immediate_load, | |
222 const Callback& callback) | 240 const Callback& callback) |
223 : SessionManagerOperation(callback) { | 241 : SessionManagerOperation(callback) { |
224 force_key_load_ = force_key_load; | 242 force_key_load_ = force_key_load; |
225 cloud_validations_ = cloud_validations; | 243 cloud_validations_ = cloud_validations; |
244 force_immediate_load_ = force_immediate_load; | |
226 } | 245 } |
227 | 246 |
228 LoadSettingsOperation::~LoadSettingsOperation() {} | 247 LoadSettingsOperation::~LoadSettingsOperation() {} |
229 | 248 |
230 void LoadSettingsOperation::Run() { | 249 void LoadSettingsOperation::Run() { |
231 StartLoading(); | 250 if (force_immediate_load_) |
251 LoadImmediately(); | |
252 else | |
253 StartLoading(); | |
232 } | 254 } |
233 | 255 |
234 StoreSettingsOperation::StoreSettingsOperation( | 256 StoreSettingsOperation::StoreSettingsOperation( |
235 const Callback& callback, | 257 const Callback& callback, |
236 std::unique_ptr<em::PolicyFetchResponse> policy) | 258 std::unique_ptr<em::PolicyFetchResponse> policy) |
237 : SessionManagerOperation(callback), | 259 : SessionManagerOperation(callback), |
238 policy_(std::move(policy)), | 260 policy_(std::move(policy)), |
239 weak_factory_(this) {} | 261 weak_factory_(this) {} |
240 | 262 |
241 StoreSettingsOperation::~StoreSettingsOperation() {} | 263 StoreSettingsOperation::~StoreSettingsOperation() {} |
242 | 264 |
243 void StoreSettingsOperation::Run() { | 265 void StoreSettingsOperation::Run() { |
244 session_manager_client()->StoreDevicePolicy( | 266 session_manager_client()->StoreDevicePolicy( |
245 policy_->SerializeAsString(), | 267 policy_->SerializeAsString(), |
246 base::Bind(&StoreSettingsOperation::HandleStoreResult, | 268 base::Bind(&StoreSettingsOperation::HandleStoreResult, |
247 weak_factory_.GetWeakPtr())); | 269 weak_factory_.GetWeakPtr())); |
248 } | 270 } |
249 | 271 |
250 void StoreSettingsOperation::HandleStoreResult(bool success) { | 272 void StoreSettingsOperation::HandleStoreResult(bool success) { |
251 if (!success) | 273 if (!success) |
252 ReportResult(DeviceSettingsService::STORE_OPERATION_FAILED); | 274 ReportResult(DeviceSettingsService::STORE_OPERATION_FAILED); |
253 else | 275 else |
254 StartLoading(); | 276 StartLoading(); |
255 } | 277 } |
256 | 278 |
257 } // namespace chromeos | 279 } // namespace chromeos |
OLD | NEW |