| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chromeos/dbus/fake_session_manager_client.h" | 5 #include "chromeos/dbus/fake_session_manager_client.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| 11 #include "base/numerics/safe_conversions.h" | 11 #include "base/numerics/safe_conversions.h" |
| 12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
| 13 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
| 14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
| 15 #include "base/threading/thread_task_runner_handle.h" | 15 #include "base/threading/thread_task_runner_handle.h" |
| 16 #include "chromeos/chromeos_paths.h" | 16 #include "chromeos/chromeos_paths.h" |
| 17 #include "chromeos/dbus/cryptohome_client.h" | 17 #include "chromeos/dbus/cryptohome_client.h" |
| 18 #include "components/policy/proto/device_management_backend.pb.h" | 18 #include "components/policy/proto/device_management_backend.pb.h" |
| 19 | 19 |
| 20 using RetrievePolicyResponseType = | |
| 21 chromeos::FakeSessionManagerClient::RetrievePolicyResponseType; | |
| 22 | |
| 23 namespace chromeos { | 20 namespace chromeos { |
| 24 | 21 |
| 25 namespace { | 22 namespace { |
| 26 | 23 |
| 27 // Store the owner key in a file on the disk, so that it can be loaded by | 24 // Store the owner key in a file on the disk, so that it can be loaded by |
| 28 // DeviceSettingsService and used e.g. for validating policy signatures in the | 25 // DeviceSettingsService and used e.g. for validating policy signatures in the |
| 29 // integration tests. This is done on behalf of the real session manager, that | 26 // integration tests. This is done on behalf of the real session manager, that |
| 30 // would be managing the owner key file on Chrome OS. | 27 // would be managing the owner key file on Chrome OS. |
| 31 bool StoreOwnerKey(const std::string& public_key) { | 28 bool StoreOwnerKey(const std::string& public_key) { |
| 32 base::FilePath owner_key_path; | 29 base::FilePath owner_key_path; |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 | 121 |
| 125 void FakeSessionManagerClient::RetrieveActiveSessions( | 122 void FakeSessionManagerClient::RetrieveActiveSessions( |
| 126 const ActiveSessionsCallback& callback) { | 123 const ActiveSessionsCallback& callback) { |
| 127 base::ThreadTaskRunnerHandle::Get()->PostTask( | 124 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 128 FROM_HERE, base::Bind(callback, user_sessions_, true)); | 125 FROM_HERE, base::Bind(callback, user_sessions_, true)); |
| 129 } | 126 } |
| 130 | 127 |
| 131 void FakeSessionManagerClient::RetrieveDevicePolicy( | 128 void FakeSessionManagerClient::RetrieveDevicePolicy( |
| 132 const RetrievePolicyCallback& callback) { | 129 const RetrievePolicyCallback& callback) { |
| 133 base::ThreadTaskRunnerHandle::Get()->PostTask( | 130 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 134 FROM_HERE, base::Bind(callback, device_policy_, | 131 FROM_HERE, base::Bind(callback, device_policy_)); |
| 135 RetrievePolicyResponseType::SUCCESS)); | |
| 136 } | 132 } |
| 137 | 133 |
| 138 RetrievePolicyResponseType | 134 std::string FakeSessionManagerClient::BlockingRetrieveDevicePolicy() { |
| 139 FakeSessionManagerClient::BlockingRetrieveDevicePolicy( | 135 return device_policy_; |
| 140 std::string* policy_out) { | |
| 141 *policy_out = device_policy_; | |
| 142 return RetrievePolicyResponseType::SUCCESS; | |
| 143 } | 136 } |
| 144 | 137 |
| 145 void FakeSessionManagerClient::RetrievePolicyForUser( | 138 void FakeSessionManagerClient::RetrievePolicyForUser( |
| 146 const cryptohome::Identification& cryptohome_id, | 139 const cryptohome::Identification& cryptohome_id, |
| 147 const RetrievePolicyCallback& callback) { | 140 const RetrievePolicyCallback& callback) { |
| 148 base::ThreadTaskRunnerHandle::Get()->PostTask( | 141 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 149 FROM_HERE, base::Bind(callback, user_policies_[cryptohome_id], | 142 FROM_HERE, base::Bind(callback, user_policies_[cryptohome_id])); |
| 150 RetrievePolicyResponseType::SUCCESS)); | |
| 151 } | 143 } |
| 152 | 144 |
| 153 RetrievePolicyResponseType | 145 std::string FakeSessionManagerClient::BlockingRetrievePolicyForUser( |
| 154 FakeSessionManagerClient::BlockingRetrievePolicyForUser( | 146 const cryptohome::Identification& cryptohome_id) { |
| 155 const cryptohome::Identification& cryptohome_id, | 147 return user_policies_[cryptohome_id]; |
| 156 std::string* policy_out) { | |
| 157 *policy_out = user_policies_[cryptohome_id]; | |
| 158 return RetrievePolicyResponseType::SUCCESS; | |
| 159 } | 148 } |
| 160 | 149 |
| 161 void FakeSessionManagerClient::RetrieveDeviceLocalAccountPolicy( | 150 void FakeSessionManagerClient::RetrieveDeviceLocalAccountPolicy( |
| 162 const std::string& account_id, | 151 const std::string& account_id, |
| 163 const RetrievePolicyCallback& callback) { | 152 const RetrievePolicyCallback& callback) { |
| 164 base::ThreadTaskRunnerHandle::Get()->PostTask( | 153 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 165 FROM_HERE, base::Bind(callback, device_local_account_policy_[account_id], | 154 FROM_HERE, |
| 166 RetrievePolicyResponseType::SUCCESS)); | 155 base::Bind(callback, device_local_account_policy_[account_id])); |
| 167 } | 156 } |
| 168 | 157 |
| 169 RetrievePolicyResponseType | 158 std::string FakeSessionManagerClient::BlockingRetrieveDeviceLocalAccountPolicy( |
| 170 FakeSessionManagerClient::BlockingRetrieveDeviceLocalAccountPolicy( | 159 const std::string& account_id) { |
| 171 const std::string& account_id, | 160 return device_local_account_policy_[account_id]; |
| 172 std::string* policy_out) { | |
| 173 *policy_out = device_local_account_policy_[account_id]; | |
| 174 return RetrievePolicyResponseType::SUCCESS; | |
| 175 } | 161 } |
| 176 | 162 |
| 177 void FakeSessionManagerClient::StoreDevicePolicy( | 163 void FakeSessionManagerClient::StoreDevicePolicy( |
| 178 const std::string& policy_blob, | 164 const std::string& policy_blob, |
| 179 const StorePolicyCallback& callback) { | 165 const StorePolicyCallback& callback) { |
| 180 enterprise_management::PolicyFetchResponse policy; | 166 enterprise_management::PolicyFetchResponse policy; |
| 181 if (!policy.ParseFromString(policy_blob)) { | 167 if (!policy.ParseFromString(policy_blob)) { |
| 182 LOG(ERROR) << "Unable to parse policy protobuf"; | 168 LOG(ERROR) << "Unable to parse policy protobuf"; |
| 183 base::ThreadTaskRunnerHandle::Get()->PostTask( | 169 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 184 FROM_HERE, base::Bind(callback, false /* success */)); | 170 FROM_HERE, base::Bind(callback, false /* success */)); |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 const std::string& policy_blob) { | 304 const std::string& policy_blob) { |
| 319 device_local_account_policy_[account_id] = policy_blob; | 305 device_local_account_policy_[account_id] = policy_blob; |
| 320 } | 306 } |
| 321 | 307 |
| 322 void FakeSessionManagerClient::OnPropertyChangeComplete(bool success) { | 308 void FakeSessionManagerClient::OnPropertyChangeComplete(bool success) { |
| 323 for (auto& observer : observers_) | 309 for (auto& observer : observers_) |
| 324 observer.PropertyChangeComplete(success); | 310 observer.PropertyChangeComplete(success); |
| 325 } | 311 } |
| 326 | 312 |
| 327 } // namespace chromeos | 313 } // namespace chromeos |
| OLD | NEW |