Chromium Code Reviews| 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" | |
| 9 #include "base/files/file_util.h" | |
| 8 #include "base/location.h" | 10 #include "base/location.h" |
| 11 #include "base/numerics/safe_conversions.h" | |
| 12 #include "base/path_service.h" | |
| 9 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
| 10 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
| 11 #include "base/threading/thread_task_runner_handle.h" | 15 #include "base/threading/thread_task_runner_handle.h" |
| 16 #include "chromeos/chromeos_paths.h" | |
| 12 #include "chromeos/dbus/cryptohome_client.h" | 17 #include "chromeos/dbus/cryptohome_client.h" |
| 18 #include "components/policy/proto/device_management_backend.pb.h" | |
| 13 | 19 |
| 14 namespace chromeos { | 20 namespace chromeos { |
| 15 | 21 |
| 22 namespace { | |
| 23 | |
|
stevenjb
2017/03/02 22:23:43
Can you explain in a comment why we need to actual
emaxx
2017/03/02 22:47:13
Done, PTAL.
| |
| 24 bool StoreOwnerKey(const std::string& public_key) { | |
| 25 base::FilePath owner_key_path; | |
| 26 DCHECK(base::PathService::Get(FILE_OWNER_KEY, &owner_key_path)); | |
| 27 if (!base::CreateDirectory(owner_key_path.DirName())) { | |
| 28 LOG(ERROR) << "Failed to create the directory for the owner key file"; | |
| 29 return false; | |
| 30 } | |
| 31 if (base::WriteFile(owner_key_path, public_key.c_str(), | |
| 32 public_key.length()) != | |
| 33 base::checked_cast<int>(public_key.length())) { | |
| 34 LOG(ERROR) << "Failed to store the owner key file"; | |
| 35 return false; | |
| 36 } | |
| 37 return true; | |
| 38 } | |
| 39 | |
| 40 } // namespace | |
| 41 | |
| 16 FakeSessionManagerClient::FakeSessionManagerClient() | 42 FakeSessionManagerClient::FakeSessionManagerClient() |
| 17 : start_device_wipe_call_count_(0), | 43 : start_device_wipe_call_count_(0), |
| 18 request_lock_screen_call_count_(0), | 44 request_lock_screen_call_count_(0), |
| 19 notify_lock_screen_shown_call_count_(0), | 45 notify_lock_screen_shown_call_count_(0), |
| 20 notify_lock_screen_dismissed_call_count_(0), | 46 notify_lock_screen_dismissed_call_count_(0), |
| 21 arc_available_(false) {} | 47 arc_available_(false) {} |
| 22 | 48 |
| 23 FakeSessionManagerClient::~FakeSessionManagerClient() { | 49 FakeSessionManagerClient::~FakeSessionManagerClient() { |
| 24 } | 50 } |
| 25 | 51 |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 114 const std::string& account_id, | 140 const std::string& account_id, |
| 115 const RetrievePolicyCallback& callback) { | 141 const RetrievePolicyCallback& callback) { |
| 116 base::ThreadTaskRunnerHandle::Get()->PostTask( | 142 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 117 FROM_HERE, | 143 FROM_HERE, |
| 118 base::Bind(callback, device_local_account_policy_[account_id])); | 144 base::Bind(callback, device_local_account_policy_[account_id])); |
| 119 } | 145 } |
| 120 | 146 |
| 121 void FakeSessionManagerClient::StoreDevicePolicy( | 147 void FakeSessionManagerClient::StoreDevicePolicy( |
| 122 const std::string& policy_blob, | 148 const std::string& policy_blob, |
| 123 const StorePolicyCallback& callback) { | 149 const StorePolicyCallback& callback) { |
| 150 enterprise_management::PolicyFetchResponse policy; | |
| 151 if (!policy.ParseFromString(policy_blob)) { | |
| 152 LOG(ERROR) << "Unable to parse policy protobuf"; | |
| 153 base::ThreadTaskRunnerHandle::Get()->PostTask( | |
| 154 FROM_HERE, base::Bind(callback, false /* success */)); | |
| 155 return; | |
| 156 } | |
| 157 | |
| 158 bool owner_key_store_success = false; | |
| 159 if (policy.has_new_public_key()) | |
| 160 owner_key_store_success = StoreOwnerKey(policy.new_public_key()); | |
| 124 device_policy_ = policy_blob; | 161 device_policy_ = policy_blob; |
| 125 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, | 162 |
| 126 base::Bind(callback, true)); | 163 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 164 FROM_HERE, base::Bind(callback, true /* success */)); | |
| 165 if (policy.has_new_public_key()) { | |
| 166 for (auto& observer : observers_) | |
| 167 observer.OwnerKeySet(owner_key_store_success); | |
| 168 } | |
| 127 for (auto& observer : observers_) | 169 for (auto& observer : observers_) |
| 128 observer.PropertyChangeComplete(true); | 170 observer.PropertyChangeComplete(true /* success */); |
| 129 } | 171 } |
| 130 | 172 |
| 131 void FakeSessionManagerClient::StorePolicyForUser( | 173 void FakeSessionManagerClient::StorePolicyForUser( |
| 132 const cryptohome::Identification& cryptohome_id, | 174 const cryptohome::Identification& cryptohome_id, |
| 133 const std::string& policy_blob, | 175 const std::string& policy_blob, |
| 134 const StorePolicyCallback& callback) { | 176 const StorePolicyCallback& callback) { |
| 135 user_policies_[cryptohome_id] = policy_blob; | 177 user_policies_[cryptohome_id] = policy_blob; |
| 136 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, | 178 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
| 137 base::Bind(callback, true)); | 179 base::Bind(callback, true)); |
| 138 } | 180 } |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 246 const std::string& policy_blob) { | 288 const std::string& policy_blob) { |
| 247 device_local_account_policy_[account_id] = policy_blob; | 289 device_local_account_policy_[account_id] = policy_blob; |
| 248 } | 290 } |
| 249 | 291 |
| 250 void FakeSessionManagerClient::OnPropertyChangeComplete(bool success) { | 292 void FakeSessionManagerClient::OnPropertyChangeComplete(bool success) { |
| 251 for (auto& observer : observers_) | 293 for (auto& observer : observers_) |
| 252 observer.PropertyChangeComplete(success); | 294 observer.PropertyChangeComplete(success); |
| 253 } | 295 } |
| 254 | 296 |
| 255 } // namespace chromeos | 297 } // namespace chromeos |
| OLD | NEW |