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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 else | 238 else |
239 StartLoading(); | 239 StartLoading(); |
240 } | 240 } |
241 | 241 |
242 SignAndStoreSettingsOperation::SignAndStoreSettingsOperation( | 242 SignAndStoreSettingsOperation::SignAndStoreSettingsOperation( |
243 const Callback& callback, | 243 const Callback& callback, |
244 scoped_ptr<em::PolicyData> new_policy) | 244 scoped_ptr<em::PolicyData> new_policy) |
245 : SessionManagerOperation(callback), | 245 : SessionManagerOperation(callback), |
246 new_policy_(new_policy.Pass()), | 246 new_policy_(new_policy.Pass()), |
247 weak_factory_(this) { | 247 weak_factory_(this) { |
248 DCHECK(new_policy_); | |
249 } | 248 } |
250 | 249 |
251 SignAndStoreSettingsOperation::~SignAndStoreSettingsOperation() {} | 250 SignAndStoreSettingsOperation::~SignAndStoreSettingsOperation() {} |
252 | 251 |
253 void SignAndStoreSettingsOperation::Run() { | 252 void SignAndStoreSettingsOperation::Run() { |
| 253 if (!new_policy_) { |
| 254 ReportResult(DeviceSettingsService::STORE_POLICY_ERROR); |
| 255 return; |
| 256 } |
254 if (!owner_settings_service_) { | 257 if (!owner_settings_service_) { |
255 ReportResult(DeviceSettingsService::STORE_KEY_UNAVAILABLE); | 258 ReportResult(DeviceSettingsService::STORE_KEY_UNAVAILABLE); |
256 return; | 259 return; |
257 } | 260 } |
258 owner_settings_service_->IsOwnerAsync( | 261 owner_settings_service_->IsOwnerAsync( |
259 base::Bind(&SignAndStoreSettingsOperation::StartSigning, | 262 base::Bind(&SignAndStoreSettingsOperation::StartSigning, |
260 weak_factory_.GetWeakPtr())); | 263 weak_factory_.GetWeakPtr())); |
261 } | 264 } |
262 | 265 |
263 void SignAndStoreSettingsOperation::StartSigning(bool is_owner) { | 266 void SignAndStoreSettingsOperation::StartSigning(bool is_owner) { |
264 if (!owner_settings_service_ || !is_owner) { | 267 if (!owner_settings_service_ || !is_owner) { |
265 ReportResult(DeviceSettingsService::STORE_KEY_UNAVAILABLE); | 268 ReportResult(DeviceSettingsService::STORE_KEY_UNAVAILABLE); |
266 return; | 269 return; |
267 } | 270 } |
268 | 271 |
269 bool rv = owner_settings_service_->AssembleAndSignPolicyAsync( | 272 bool rv = owner_settings_service_->AssembleAndSignPolicyAsync( |
270 content::BrowserThread::GetBlockingPool(), | 273 content::BrowserThread::GetBlockingPool(), |
271 new_policy_.Pass(), | 274 new_policy_.Pass(), |
272 base::Bind(&SignAndStoreSettingsOperation::StoreDeviceSettingsBlob, | 275 base::Bind(&SignAndStoreSettingsOperation::StoreDeviceSettings, |
273 weak_factory_.GetWeakPtr())); | 276 weak_factory_.GetWeakPtr())); |
274 if (!rv) { | 277 if (!rv) { |
275 ReportResult(DeviceSettingsService::STORE_KEY_UNAVAILABLE); | 278 ReportResult(DeviceSettingsService::STORE_KEY_UNAVAILABLE); |
276 return; | 279 return; |
277 } | 280 } |
278 } | 281 } |
279 | 282 |
280 void SignAndStoreSettingsOperation::StoreDeviceSettingsBlob( | 283 void SignAndStoreSettingsOperation::StoreDeviceSettings( |
281 std::string device_settings_blob) { | 284 scoped_ptr<em::PolicyFetchResponse> policy_response) { |
282 if (device_settings_blob.empty()) { | 285 if (!policy_response.get()) { |
283 ReportResult(DeviceSettingsService::STORE_POLICY_ERROR); | 286 ReportResult(DeviceSettingsService::STORE_POLICY_ERROR); |
284 return; | 287 return; |
285 } | 288 } |
286 | 289 |
287 session_manager_client()->StoreDevicePolicy( | 290 session_manager_client()->StoreDevicePolicy( |
288 device_settings_blob, | 291 policy_response->SerializeAsString(), |
289 base::Bind(&SignAndStoreSettingsOperation::HandleStoreResult, | 292 base::Bind(&SignAndStoreSettingsOperation::HandleStoreResult, |
290 weak_factory_.GetWeakPtr())); | 293 weak_factory_.GetWeakPtr())); |
291 } | 294 } |
292 | 295 |
293 void SignAndStoreSettingsOperation::HandleStoreResult(bool success) { | 296 void SignAndStoreSettingsOperation::HandleStoreResult(bool success) { |
294 if (!success) | 297 if (!success) |
295 ReportResult(DeviceSettingsService::STORE_OPERATION_FAILED); | 298 ReportResult(DeviceSettingsService::STORE_OPERATION_FAILED); |
296 else | 299 else |
297 StartLoading(); | 300 StartLoading(); |
298 } | 301 } |
299 | 302 |
300 } // namespace chromeos | 303 } // namespace chromeos |
OLD | NEW |