| 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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 EnsurePublicKey(base::Bind(&SessionManagerOperation::RetrieveDeviceSettings, | 67 EnsurePublicKey(base::Bind(&SessionManagerOperation::RetrieveDeviceSettings, |
| 68 weak_factory_.GetWeakPtr())); | 68 weak_factory_.GetWeakPtr())); |
| 69 } | 69 } |
| 70 | 70 |
| 71 void SessionManagerOperation::ReportResult( | 71 void SessionManagerOperation::ReportResult( |
| 72 DeviceSettingsService::Status status) { | 72 DeviceSettingsService::Status status) { |
| 73 callback_.Run(this, status); | 73 callback_.Run(this, status); |
| 74 } | 74 } |
| 75 | 75 |
| 76 void SessionManagerOperation::EnsurePublicKey(const base::Closure& callback) { | 76 void SessionManagerOperation::EnsurePublicKey(const base::Closure& callback) { |
| 77 if (force_key_load_ || !public_key_ || !public_key_->is_loaded()) { | 77 if (force_key_load_ || !public_key_.get() || !public_key_->is_loaded()) { |
| 78 scoped_refptr<base::TaskRunner> task_runner = | 78 scoped_refptr<base::TaskRunner> task_runner = |
| 79 content::BrowserThread::GetBlockingPool() | 79 content::BrowserThread::GetBlockingPool() |
| 80 ->GetTaskRunnerWithShutdownBehavior( | 80 ->GetTaskRunnerWithShutdownBehavior( |
| 81 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); | 81 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); |
| 82 base::PostTaskAndReplyWithResult( | 82 base::PostTaskAndReplyWithResult( |
| 83 task_runner.get(), | 83 task_runner.get(), |
| 84 FROM_HERE, | 84 FROM_HERE, |
| 85 base::Bind(&SessionManagerOperation::LoadPublicKey, | 85 base::Bind(&SessionManagerOperation::LoadPublicKey, |
| 86 owner_key_util_, | 86 owner_key_util_, |
| 87 public_key_), | 87 public_key_), |
| 88 base::Bind(&SessionManagerOperation::StorePublicKey, | 88 base::Bind(&SessionManagerOperation::StorePublicKey, |
| 89 weak_factory_.GetWeakPtr(), | 89 weak_factory_.GetWeakPtr(), |
| 90 callback)); | 90 callback)); |
| 91 } else { | 91 } else { |
| 92 callback.Run(); | 92 callback.Run(); |
| 93 } | 93 } |
| 94 } | 94 } |
| 95 | 95 |
| 96 // static | 96 // static |
| 97 scoped_refptr<PublicKey> SessionManagerOperation::LoadPublicKey( | 97 scoped_refptr<PublicKey> SessionManagerOperation::LoadPublicKey( |
| 98 scoped_refptr<OwnerKeyUtil> util, | 98 scoped_refptr<OwnerKeyUtil> util, |
| 99 scoped_refptr<PublicKey> current_key) { | 99 scoped_refptr<PublicKey> current_key) { |
| 100 scoped_refptr<PublicKey> public_key(new PublicKey()); | 100 scoped_refptr<PublicKey> public_key(new PublicKey()); |
| 101 | 101 |
| 102 // Keep already-existing public key. | 102 // Keep already-existing public key. |
| 103 if (current_key && current_key->is_loaded()) { | 103 if (current_key.get() && current_key->is_loaded()) { |
| 104 public_key->data() = current_key->data(); | 104 public_key->data() = current_key->data(); |
| 105 } | 105 } |
| 106 if (!public_key->is_loaded() && util->IsPublicKeyPresent()) { | 106 if (!public_key->is_loaded() && util->IsPublicKeyPresent()) { |
| 107 if (!util->ImportPublicKey(&public_key->data())) | 107 if (!util->ImportPublicKey(&public_key->data())) |
| 108 LOG(ERROR) << "Failed to load public owner key."; | 108 LOG(ERROR) << "Failed to load public owner key."; |
| 109 } | 109 } |
| 110 | 110 |
| 111 return public_key; | 111 return public_key; |
| 112 } | 112 } |
| 113 | 113 |
| 114 void SessionManagerOperation::StorePublicKey(const base::Closure& callback, | 114 void SessionManagerOperation::StorePublicKey(const base::Closure& callback, |
| 115 scoped_refptr<PublicKey> new_key) { | 115 scoped_refptr<PublicKey> new_key) { |
| 116 force_key_load_ = false; | 116 force_key_load_ = false; |
| 117 public_key_ = new_key; | 117 public_key_ = new_key; |
| 118 | 118 |
| 119 if (!public_key_ || !public_key_->is_loaded()) { | 119 if (!public_key_.get() || !public_key_->is_loaded()) { |
| 120 ReportResult(DeviceSettingsService::STORE_KEY_UNAVAILABLE); | 120 ReportResult(DeviceSettingsService::STORE_KEY_UNAVAILABLE); |
| 121 return; | 121 return; |
| 122 } | 122 } |
| 123 | 123 |
| 124 callback.Run(); | 124 callback.Run(); |
| 125 } | 125 } |
| 126 | 126 |
| 127 void SessionManagerOperation::RetrieveDeviceSettings() { | 127 void SessionManagerOperation::RetrieveDeviceSettings() { |
| 128 session_manager_client()->RetrieveDevicePolicy( | 128 session_manager_client()->RetrieveDevicePolicy( |
| 129 base::Bind(&SessionManagerOperation::ValidateDeviceSettings, | 129 base::Bind(&SessionManagerOperation::ValidateDeviceSettings, |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 } | 290 } |
| 291 | 291 |
| 292 void SignAndStoreSettingsOperation::HandleStoreResult(bool success) { | 292 void SignAndStoreSettingsOperation::HandleStoreResult(bool success) { |
| 293 if (!success) | 293 if (!success) |
| 294 ReportResult(DeviceSettingsService::STORE_OPERATION_FAILED); | 294 ReportResult(DeviceSettingsService::STORE_OPERATION_FAILED); |
| 295 else | 295 else |
| 296 StartLoading(); | 296 StartLoading(); |
| 297 } | 297 } |
| 298 | 298 |
| 299 } // namespace chromeos | 299 } // namespace chromeos |
| OLD | NEW |