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 "chromeos/dbus/session_manager_client.h" | 5 #include "chromeos/dbus/session_manager_client.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 | 11 |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/callback.h" | 13 #include "base/callback.h" |
14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
15 #include "base/files/file_util.h" | 15 #include "base/files/file_util.h" |
16 #include "base/location.h" | 16 #include "base/location.h" |
17 #include "base/macros.h" | 17 #include "base/macros.h" |
| 18 #include "base/metrics/histogram_macros.h" |
18 #include "base/path_service.h" | 19 #include "base/path_service.h" |
19 #include "base/strings/string_number_conversions.h" | 20 #include "base/strings/string_number_conversions.h" |
20 #include "base/strings/string_util.h" | 21 #include "base/strings/string_util.h" |
21 #include "base/task_scheduler/post_task.h" | 22 #include "base/task_scheduler/post_task.h" |
22 #include "base/threading/thread_task_runner_handle.h" | 23 #include "base/threading/thread_task_runner_handle.h" |
23 #include "chromeos/chromeos_paths.h" | 24 #include "chromeos/chromeos_paths.h" |
24 #include "chromeos/cryptohome/cryptohome_parameters.h" | 25 #include "chromeos/cryptohome/cryptohome_parameters.h" |
25 #include "chromeos/dbus/blocking_method_caller.h" | 26 #include "chromeos/dbus/blocking_method_caller.h" |
26 #include "chromeos/dbus/cryptohome_client.h" | 27 #include "chromeos/dbus/cryptohome_client.h" |
27 #include "components/policy/proto/device_management_backend.pb.h" | 28 #include "components/policy/proto/device_management_backend.pb.h" |
28 #include "crypto/sha2.h" | 29 #include "crypto/sha2.h" |
29 #include "dbus/bus.h" | 30 #include "dbus/bus.h" |
30 #include "dbus/message.h" | 31 #include "dbus/message.h" |
31 #include "dbus/object_path.h" | 32 #include "dbus/object_path.h" |
32 #include "dbus/object_proxy.h" | 33 #include "dbus/object_proxy.h" |
| 34 #include "dbus/scoped_dbus_error.h" |
33 #include "third_party/cros_system_api/dbus/service_constants.h" | 35 #include "third_party/cros_system_api/dbus/service_constants.h" |
34 | 36 |
35 namespace chromeos { | 37 namespace chromeos { |
36 | 38 |
37 namespace { | 39 namespace { |
38 | 40 |
39 // TODO(hidehiko): Share the constant between Chrome and ChromeOS. | 41 using RetrievePolicyResponseType = |
40 constexpr char kArcLowDiskError[] = | 42 SessionManagerClient::RetrievePolicyResponseType; |
41 "org.chromium.SessionManagerInterface.LowFreeDisk"; | |
42 | 43 |
43 constexpr char kStubPolicyFile[] = "stub_policy"; | 44 constexpr char kStubPolicyFile[] = "stub_policy"; |
44 constexpr char kStubDevicePolicyFile[] = "stub_device_policy"; | 45 constexpr char kStubDevicePolicyFile[] = "stub_device_policy"; |
45 constexpr char kStubStateKeysFile[] = "stub_state_keys"; | 46 constexpr char kStubStateKeysFile[] = "stub_state_keys"; |
46 | 47 |
47 // Returns a location for |file| that is specific to the given |cryptohome_id|. | 48 // Returns a location for |file| that is specific to the given |cryptohome_id|. |
48 // These paths will be relative to DIR_USER_POLICY_KEYS, and can be used only | 49 // These paths will be relative to DIR_USER_POLICY_KEYS, and can be used only |
49 // to store stub files. | 50 // to store stub files. |
50 base::FilePath GetUserFilePath(const cryptohome::Identification& cryptohome_id, | 51 base::FilePath GetUserFilePath(const cryptohome::Identification& cryptohome_id, |
51 const char* file) { | 52 const char* file) { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 } | 97 } |
97 return state_keys; | 98 return state_keys; |
98 } | 99 } |
99 | 100 |
100 // Turn pass-by-value into pass-by-reference as expected by StateKeysCallback. | 101 // Turn pass-by-value into pass-by-reference as expected by StateKeysCallback. |
101 void RunStateKeysCallbackStub(SessionManagerClient::StateKeysCallback callback, | 102 void RunStateKeysCallbackStub(SessionManagerClient::StateKeysCallback callback, |
102 std::vector<std::string> state_keys) { | 103 std::vector<std::string> state_keys) { |
103 callback.Run(state_keys); | 104 callback.Run(state_keys); |
104 } | 105 } |
105 | 106 |
| 107 // Helper to notify the callback with SUCCESS, to be used by the stub. |
| 108 void NotifyOnRetrievePolicySuccess( |
| 109 const SessionManagerClient::RetrievePolicyCallback& callback, |
| 110 const std::string& protobuf) { |
| 111 callback.Run(protobuf, RetrievePolicyResponseType::SUCCESS); |
| 112 } |
| 113 |
| 114 // Helper to get the enum type of RetrievePolicyResponseType based on error |
| 115 // name. |
| 116 RetrievePolicyResponseType GetResponseTypeBasedOnError( |
| 117 const std::string& error_name) { |
| 118 if (error_name == login_manager::dbus_error::kNone) { |
| 119 return RetrievePolicyResponseType::SUCCESS; |
| 120 } |
| 121 if (error_name == login_manager::dbus_error::kSessionDoesNotExist) { |
| 122 return RetrievePolicyResponseType::SESSION_DOES_NOT_EXIST; |
| 123 } |
| 124 if (error_name == login_manager::dbus_error::kSigEncodeFail) { |
| 125 return RetrievePolicyResponseType::POLICY_ENCODE_ERROR; |
| 126 } |
| 127 return RetrievePolicyResponseType::OTHER_ERROR; |
| 128 } |
| 129 |
| 130 // Logs UMA stat for retrieve policy request, corresponding to D-Bus method name |
| 131 // used. |
| 132 void LogPolicyResponseUma(const std::string& method_name, |
| 133 RetrievePolicyResponseType response) { |
| 134 if (method_name == login_manager::kSessionManagerRetrievePolicy) { |
| 135 UMA_HISTOGRAM_ENUMERATION("Enterprise.RetrievePolicyResponse.Device", |
| 136 response, RetrievePolicyResponseType::COUNT); |
| 137 } else if (method_name == |
| 138 login_manager::kSessionManagerRetrieveDeviceLocalAccountPolicy) { |
| 139 UMA_HISTOGRAM_ENUMERATION( |
| 140 "Enterprise.RetrievePolicyResponse.DeviceLocalAccount", response, |
| 141 RetrievePolicyResponseType::COUNT); |
| 142 } else if (method_name == |
| 143 login_manager::kSessionManagerRetrievePolicyForUser) { |
| 144 UMA_HISTOGRAM_ENUMERATION("Enterprise.RetrievePolicyResponse.User", |
| 145 response, RetrievePolicyResponseType::COUNT); |
| 146 } else { |
| 147 LOG(ERROR) << "Invalid method_name: " << method_name; |
| 148 } |
| 149 } |
| 150 |
106 } // namespace | 151 } // namespace |
107 | 152 |
108 // The SessionManagerClient implementation used in production. | 153 // The SessionManagerClient implementation used in production. |
109 class SessionManagerClientImpl : public SessionManagerClient { | 154 class SessionManagerClientImpl : public SessionManagerClient { |
110 public: | 155 public: |
111 SessionManagerClientImpl() | 156 SessionManagerClientImpl() |
112 : session_manager_proxy_(NULL), | 157 : session_manager_proxy_(NULL), |
113 screen_is_locked_(false), | 158 screen_is_locked_(false), |
114 weak_ptr_factory_(this) {} | 159 weak_ptr_factory_(this) {} |
115 | 160 |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 269 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
225 base::Bind(&SessionManagerClientImpl::OnRetrieveActiveSessions, | 270 base::Bind(&SessionManagerClientImpl::OnRetrieveActiveSessions, |
226 weak_ptr_factory_.GetWeakPtr(), | 271 weak_ptr_factory_.GetWeakPtr(), |
227 login_manager::kSessionManagerRetrieveActiveSessions, | 272 login_manager::kSessionManagerRetrieveActiveSessions, |
228 callback)); | 273 callback)); |
229 } | 274 } |
230 | 275 |
231 void RetrieveDevicePolicy(const RetrievePolicyCallback& callback) override { | 276 void RetrieveDevicePolicy(const RetrievePolicyCallback& callback) override { |
232 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, | 277 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, |
233 login_manager::kSessionManagerRetrievePolicy); | 278 login_manager::kSessionManagerRetrievePolicy); |
234 session_manager_proxy_->CallMethod( | 279 session_manager_proxy_->CallMethodWithErrorCallback( |
235 &method_call, | 280 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
236 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 281 base::Bind(&SessionManagerClientImpl::OnRetrievePolicySuccess, |
237 base::Bind(&SessionManagerClientImpl::OnRetrievePolicy, | |
238 weak_ptr_factory_.GetWeakPtr(), | 282 weak_ptr_factory_.GetWeakPtr(), |
239 login_manager::kSessionManagerRetrievePolicy, | 283 login_manager::kSessionManagerRetrievePolicy, callback), |
240 callback)); | 284 base::Bind(&SessionManagerClientImpl::OnRetrievePolicyError, |
| 285 weak_ptr_factory_.GetWeakPtr(), |
| 286 login_manager::kSessionManagerRetrievePolicy, callback)); |
241 } | 287 } |
242 | 288 |
243 std::string BlockingRetrieveDevicePolicy() override { | 289 RetrievePolicyResponseType BlockingRetrieveDevicePolicy( |
| 290 std::string* policy) override { |
244 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, | 291 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, |
245 login_manager::kSessionManagerRetrievePolicy); | 292 login_manager::kSessionManagerRetrievePolicy); |
| 293 dbus::ScopedDBusError error; |
246 std::unique_ptr<dbus::Response> response = | 294 std::unique_ptr<dbus::Response> response = |
247 blocking_method_caller_->CallMethodAndBlock(&method_call); | 295 blocking_method_caller_->CallMethodAndBlockWithError(&method_call, |
248 std::string policy; | 296 &error); |
249 ExtractString(login_manager::kSessionManagerRetrievePolicy, response.get(), | 297 RetrievePolicyResponseType result = RetrievePolicyResponseType::SUCCESS; |
250 &policy); | 298 if (error.is_set() && error.name()) { |
251 return policy; | 299 result = GetResponseTypeBasedOnError(error.name()); |
| 300 } |
| 301 if (result == RetrievePolicyResponseType::SUCCESS) { |
| 302 ExtractString(login_manager::kSessionManagerRetrievePolicy, |
| 303 response.get(), policy); |
| 304 } else { |
| 305 *policy = ""; |
| 306 } |
| 307 LogPolicyResponseUma(login_manager::kSessionManagerRetrievePolicy, result); |
| 308 return result; |
252 } | 309 } |
253 | 310 |
254 void RetrievePolicyForUser(const cryptohome::Identification& cryptohome_id, | 311 void RetrievePolicyForUser(const cryptohome::Identification& cryptohome_id, |
255 const RetrievePolicyCallback& callback) override { | 312 const RetrievePolicyCallback& callback) override { |
256 CallRetrievePolicyByUsername( | 313 CallRetrievePolicyByUsername( |
257 login_manager::kSessionManagerRetrievePolicyForUser, cryptohome_id.id(), | 314 login_manager::kSessionManagerRetrievePolicyForUser, cryptohome_id.id(), |
258 callback); | 315 callback); |
259 } | 316 } |
260 | 317 |
261 std::string BlockingRetrievePolicyForUser( | 318 RetrievePolicyResponseType BlockingRetrievePolicyForUser( |
262 const cryptohome::Identification& cryptohome_id) override { | 319 const cryptohome::Identification& cryptohome_id, |
263 dbus::MethodCall method_call( | 320 std::string* policy) override { |
264 login_manager::kSessionManagerInterface, | 321 return BlockingRetrievePolicyByUsername( |
265 login_manager::kSessionManagerRetrievePolicyForUser); | 322 login_manager::kSessionManagerRetrievePolicyForUser, cryptohome_id.id(), |
266 dbus::MessageWriter writer(&method_call); | 323 policy); |
267 writer.AppendString(cryptohome_id.id()); | |
268 std::unique_ptr<dbus::Response> response = | |
269 blocking_method_caller_->CallMethodAndBlock(&method_call); | |
270 std::string policy; | |
271 ExtractString(login_manager::kSessionManagerRetrievePolicyForUser, | |
272 response.get(), | |
273 &policy); | |
274 return policy; | |
275 } | 324 } |
276 | 325 |
277 void RetrieveDeviceLocalAccountPolicy( | 326 void RetrieveDeviceLocalAccountPolicy( |
278 const std::string& account_name, | 327 const std::string& account_name, |
279 const RetrievePolicyCallback& callback) override { | 328 const RetrievePolicyCallback& callback) override { |
280 CallRetrievePolicyByUsername( | 329 CallRetrievePolicyByUsername( |
281 login_manager::kSessionManagerRetrieveDeviceLocalAccountPolicy, | 330 login_manager::kSessionManagerRetrieveDeviceLocalAccountPolicy, |
282 account_name, | 331 account_name, callback); |
283 callback); | |
284 } | 332 } |
285 | 333 |
286 std::string BlockingRetrieveDeviceLocalAccountPolicy( | 334 RetrievePolicyResponseType BlockingRetrieveDeviceLocalAccountPolicy( |
287 const std::string& account_name) override { | 335 const std::string& account_name, |
288 dbus::MethodCall method_call( | 336 std::string* policy) override { |
289 login_manager::kSessionManagerInterface, | 337 return BlockingRetrievePolicyByUsername( |
290 login_manager::kSessionManagerRetrieveDeviceLocalAccountPolicy); | |
291 dbus::MessageWriter writer(&method_call); | |
292 writer.AppendString(account_name); | |
293 std::unique_ptr<dbus::Response> response = | |
294 blocking_method_caller_->CallMethodAndBlock(&method_call); | |
295 std::string policy; | |
296 ExtractString( | |
297 login_manager::kSessionManagerRetrieveDeviceLocalAccountPolicy, | 338 login_manager::kSessionManagerRetrieveDeviceLocalAccountPolicy, |
298 response.get(), &policy); | 339 account_name, policy); |
299 return policy; | |
300 } | 340 } |
301 | 341 |
302 void StoreDevicePolicy(const std::string& policy_blob, | 342 void StoreDevicePolicy(const std::string& policy_blob, |
303 const StorePolicyCallback& callback) override { | 343 const StorePolicyCallback& callback) override { |
304 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, | 344 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, |
305 login_manager::kSessionManagerStorePolicy); | 345 login_manager::kSessionManagerStorePolicy); |
306 dbus::MessageWriter writer(&method_call); | 346 dbus::MessageWriter writer(&method_call); |
307 // static_cast does not work due to signedness. | 347 // static_cast does not work due to signedness. |
308 writer.AppendArrayOfBytes( | 348 writer.AppendArrayOfBytes( |
309 reinterpret_cast<const uint8_t*>(policy_blob.data()), | 349 reinterpret_cast<const uint8_t*>(policy_blob.data()), |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
517 } | 557 } |
518 | 558 |
519 // Helper for RetrieveDeviceLocalAccountPolicy and RetrievePolicyForUser. | 559 // Helper for RetrieveDeviceLocalAccountPolicy and RetrievePolicyForUser. |
520 void CallRetrievePolicyByUsername(const std::string& method_name, | 560 void CallRetrievePolicyByUsername(const std::string& method_name, |
521 const std::string& account_id, | 561 const std::string& account_id, |
522 const RetrievePolicyCallback& callback) { | 562 const RetrievePolicyCallback& callback) { |
523 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, | 563 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, |
524 method_name); | 564 method_name); |
525 dbus::MessageWriter writer(&method_call); | 565 dbus::MessageWriter writer(&method_call); |
526 writer.AppendString(account_id); | 566 writer.AppendString(account_id); |
527 session_manager_proxy_->CallMethod( | 567 session_manager_proxy_->CallMethodWithErrorCallback( |
528 &method_call, | 568 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
529 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 569 base::Bind(&SessionManagerClientImpl::OnRetrievePolicySuccess, |
530 base::Bind( | 570 weak_ptr_factory_.GetWeakPtr(), method_name, callback), |
531 &SessionManagerClientImpl::OnRetrievePolicy, | 571 base::Bind(&SessionManagerClientImpl::OnRetrievePolicyError, |
532 weak_ptr_factory_.GetWeakPtr(), | 572 weak_ptr_factory_.GetWeakPtr(), method_name, callback)); |
533 method_name, | 573 } |
534 callback)); | 574 |
| 575 // Helper for blocking RetrievePolicyForUser and |
| 576 // RetrieveDeviceLocalAccountPolicy. |
| 577 RetrievePolicyResponseType BlockingRetrievePolicyByUsername( |
| 578 const std::string& method_name, |
| 579 const std::string& account_name, |
| 580 std::string* policy) { |
| 581 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, |
| 582 method_name); |
| 583 dbus::MessageWriter writer(&method_call); |
| 584 writer.AppendString(account_name); |
| 585 dbus::ScopedDBusError error; |
| 586 std::unique_ptr<dbus::Response> response = |
| 587 blocking_method_caller_->CallMethodAndBlockWithError(&method_call, |
| 588 &error); |
| 589 RetrievePolicyResponseType result = RetrievePolicyResponseType::SUCCESS; |
| 590 if (error.is_set() && error.name()) { |
| 591 result = GetResponseTypeBasedOnError(error.name()); |
| 592 } |
| 593 if (result == RetrievePolicyResponseType::SUCCESS) { |
| 594 ExtractString(method_name, response.get(), policy); |
| 595 } else { |
| 596 *policy = ""; |
| 597 } |
| 598 LogPolicyResponseUma(method_name, result); |
| 599 return result; |
535 } | 600 } |
536 | 601 |
537 void CallStorePolicyByUsername(const std::string& method_name, | 602 void CallStorePolicyByUsername(const std::string& method_name, |
538 const std::string& account_id, | 603 const std::string& account_id, |
539 const std::string& policy_blob, | 604 const std::string& policy_blob, |
540 const StorePolicyCallback& callback) { | 605 const StorePolicyCallback& callback) { |
541 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, | 606 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, |
542 method_name); | 607 method_name); |
543 dbus::MessageWriter writer(&method_call); | 608 dbus::MessageWriter writer(&method_call); |
544 writer.AppendString(account_id); | 609 writer.AppendString(account_id); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
636 size_t length = 0; | 701 size_t length = 0; |
637 if (!reader.PopArrayOfBytes(&values, &length)) { | 702 if (!reader.PopArrayOfBytes(&values, &length)) { |
638 LOG(ERROR) << "Invalid response: " << response->ToString(); | 703 LOG(ERROR) << "Invalid response: " << response->ToString(); |
639 return; | 704 return; |
640 } | 705 } |
641 // static_cast does not work due to signedness. | 706 // static_cast does not work due to signedness. |
642 extracted->assign(reinterpret_cast<const char*>(values), length); | 707 extracted->assign(reinterpret_cast<const char*>(values), length); |
643 } | 708 } |
644 | 709 |
645 // Called when kSessionManagerRetrievePolicy or | 710 // Called when kSessionManagerRetrievePolicy or |
646 // kSessionManagerRetrievePolicyForUser method is complete. | 711 // kSessionManagerRetrievePolicyForUser method is successfully complete. |
647 void OnRetrievePolicy(const std::string& method_name, | 712 void OnRetrievePolicySuccess(const std::string& method_name, |
648 const RetrievePolicyCallback& callback, | 713 const RetrievePolicyCallback& callback, |
649 dbus::Response* response) { | 714 dbus::Response* response) { |
650 std::string serialized_proto; | 715 std::string serialized_proto; |
651 ExtractString(method_name, response, &serialized_proto); | 716 ExtractString(method_name, response, &serialized_proto); |
652 callback.Run(serialized_proto); | 717 callback.Run(serialized_proto, RetrievePolicyResponseType::SUCCESS); |
| 718 |
| 719 LogPolicyResponseUma(method_name, RetrievePolicyResponseType::SUCCESS); |
| 720 } |
| 721 |
| 722 // Called when kSessionManagerRetrievePolicy or |
| 723 // kSessionManagerRetrievePolicyForUser method fails. |
| 724 void OnRetrievePolicyError(const std::string& method_name, |
| 725 const RetrievePolicyCallback& callback, |
| 726 dbus::ErrorResponse* response) { |
| 727 RetrievePolicyResponseType response_type = |
| 728 GetResponseTypeBasedOnError(response->GetErrorName()); |
| 729 callback.Run(std::string(), response_type); |
| 730 |
| 731 LogPolicyResponseUma(method_name, response_type); |
653 } | 732 } |
654 | 733 |
655 // Called when kSessionManagerStorePolicy or kSessionManagerStorePolicyForUser | 734 // Called when kSessionManagerStorePolicy or kSessionManagerStorePolicyForUser |
656 // method is complete. | 735 // method is complete. |
657 void OnStorePolicy(const std::string& method_name, | 736 void OnStorePolicy(const std::string& method_name, |
658 const StorePolicyCallback& callback, | 737 const StorePolicyCallback& callback, |
659 dbus::Response* response) { | 738 dbus::Response* response) { |
660 bool success = false; | 739 bool success = false; |
661 if (!response) { | 740 if (!response) { |
662 LOG(ERROR) << "Failed to call " << method_name; | 741 LOG(ERROR) << "Failed to call " << method_name; |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
813 void OnStartArcInstanceSucceeded(const StartArcInstanceCallback& callback, | 892 void OnStartArcInstanceSucceeded(const StartArcInstanceCallback& callback, |
814 dbus::Response* response) { | 893 dbus::Response* response) { |
815 if (!callback.is_null()) | 894 if (!callback.is_null()) |
816 callback.Run(StartArcInstanceResult::SUCCESS); | 895 callback.Run(StartArcInstanceResult::SUCCESS); |
817 } | 896 } |
818 | 897 |
819 void OnStartArcInstanceFailed(const StartArcInstanceCallback& callback, | 898 void OnStartArcInstanceFailed(const StartArcInstanceCallback& callback, |
820 dbus::ErrorResponse* response) { | 899 dbus::ErrorResponse* response) { |
821 LOG(ERROR) << "Failed to call StartArcInstance: " | 900 LOG(ERROR) << "Failed to call StartArcInstance: " |
822 << (response ? response->ToString() : "(null)"); | 901 << (response ? response->ToString() : "(null)"); |
823 if (!callback.is_null()) | 902 if (!callback.is_null()) { |
824 callback.Run(response && response->GetErrorName() == kArcLowDiskError | 903 callback.Run(response && response->GetErrorName() == |
| 904 login_manager::dbus_error::kLowFreeDisk |
825 ? StartArcInstanceResult::LOW_FREE_DISK_SPACE | 905 ? StartArcInstanceResult::LOW_FREE_DISK_SPACE |
826 : StartArcInstanceResult::UNKNOWN_ERROR); | 906 : StartArcInstanceResult::UNKNOWN_ERROR); |
| 907 } |
827 } | 908 } |
828 | 909 |
829 dbus::ObjectProxy* session_manager_proxy_; | 910 dbus::ObjectProxy* session_manager_proxy_; |
830 std::unique_ptr<BlockingMethodCaller> blocking_method_caller_; | 911 std::unique_ptr<BlockingMethodCaller> blocking_method_caller_; |
831 base::ObserverList<Observer> observers_; | 912 base::ObserverList<Observer> observers_; |
832 | 913 |
833 // Most recent screen-lock state received from session_manager. | 914 // Most recent screen-lock state received from session_manager. |
834 bool screen_is_locked_; | 915 bool screen_is_locked_; |
835 | 916 |
836 // Note: This should remain the last member so it'll be destroyed and | 917 // Note: This should remain the last member so it'll be destroyed and |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
883 void NotifyLockScreenDismissed() override { | 964 void NotifyLockScreenDismissed() override { |
884 screen_is_locked_ = false; | 965 screen_is_locked_ = false; |
885 for (auto& observer : observers_) | 966 for (auto& observer : observers_) |
886 observer.ScreenIsUnlocked(); | 967 observer.ScreenIsUnlocked(); |
887 } | 968 } |
888 void RetrieveActiveSessions(const ActiveSessionsCallback& callback) override { | 969 void RetrieveActiveSessions(const ActiveSessionsCallback& callback) override { |
889 } | 970 } |
890 void RetrieveDevicePolicy(const RetrievePolicyCallback& callback) override { | 971 void RetrieveDevicePolicy(const RetrievePolicyCallback& callback) override { |
891 base::FilePath owner_key_path; | 972 base::FilePath owner_key_path; |
892 if (!PathService::Get(chromeos::FILE_OWNER_KEY, &owner_key_path)) { | 973 if (!PathService::Get(chromeos::FILE_OWNER_KEY, &owner_key_path)) { |
893 callback.Run(""); | 974 callback.Run("", RetrievePolicyResponseType::SUCCESS); |
894 return; | 975 return; |
895 } | 976 } |
896 base::FilePath device_policy_path = | 977 base::FilePath device_policy_path = |
897 owner_key_path.DirName().AppendASCII(kStubDevicePolicyFile); | 978 owner_key_path.DirName().AppendASCII(kStubDevicePolicyFile); |
898 base::PostTaskWithTraitsAndReplyWithResult( | 979 base::PostTaskWithTraitsAndReplyWithResult( |
899 FROM_HERE, base::TaskTraits() | 980 FROM_HERE, |
900 .WithShutdownBehavior( | 981 base::TaskTraits() |
901 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN) | 982 .WithShutdownBehavior( |
902 .MayBlock(), | 983 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN) |
903 base::Bind(&GetFileContent, device_policy_path), callback); | 984 .MayBlock(), |
| 985 base::Bind(&GetFileContent, device_policy_path), |
| 986 base::Bind(&NotifyOnRetrievePolicySuccess, callback)); |
904 } | 987 } |
905 std::string BlockingRetrieveDevicePolicy() override { | 988 RetrievePolicyResponseType BlockingRetrieveDevicePolicy( |
| 989 std::string* policy) override { |
906 base::FilePath owner_key_path; | 990 base::FilePath owner_key_path; |
907 if (!PathService::Get(chromeos::FILE_OWNER_KEY, &owner_key_path)) { | 991 if (!PathService::Get(chromeos::FILE_OWNER_KEY, &owner_key_path)) { |
908 return ""; | 992 *policy = ""; |
| 993 return RetrievePolicyResponseType::SUCCESS; |
909 } | 994 } |
910 base::FilePath device_policy_path = | 995 base::FilePath device_policy_path = |
911 owner_key_path.DirName().AppendASCII(kStubDevicePolicyFile); | 996 owner_key_path.DirName().AppendASCII(kStubDevicePolicyFile); |
912 return GetFileContent(device_policy_path); | 997 *policy = GetFileContent(device_policy_path); |
| 998 return RetrievePolicyResponseType::SUCCESS; |
913 } | 999 } |
914 void RetrievePolicyForUser(const cryptohome::Identification& cryptohome_id, | 1000 void RetrievePolicyForUser(const cryptohome::Identification& cryptohome_id, |
915 const RetrievePolicyCallback& callback) override { | 1001 const RetrievePolicyCallback& callback) override { |
916 base::PostTaskWithTraitsAndReplyWithResult( | 1002 base::PostTaskWithTraitsAndReplyWithResult( |
917 FROM_HERE, | 1003 FROM_HERE, |
918 base::TaskTraits() | 1004 base::TaskTraits() |
919 .WithShutdownBehavior( | 1005 .WithShutdownBehavior( |
920 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN) | 1006 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN) |
921 .MayBlock(), | 1007 .MayBlock(), |
922 base::Bind(&GetFileContent, | 1008 base::Bind(&GetFileContent, |
923 GetUserFilePath(cryptohome_id, kStubPolicyFile)), | 1009 GetUserFilePath(cryptohome_id, kStubPolicyFile)), |
924 callback); | 1010 base::Bind(&NotifyOnRetrievePolicySuccess, callback)); |
925 } | 1011 } |
926 std::string BlockingRetrievePolicyForUser( | 1012 RetrievePolicyResponseType BlockingRetrievePolicyForUser( |
927 const cryptohome::Identification& cryptohome_id) override { | 1013 const cryptohome::Identification& cryptohome_id, |
928 return GetFileContent(GetUserFilePath(cryptohome_id, kStubPolicyFile)); | 1014 std::string* policy) override { |
| 1015 *policy = GetFileContent(GetUserFilePath(cryptohome_id, kStubPolicyFile)); |
| 1016 return RetrievePolicyResponseType::SUCCESS; |
929 } | 1017 } |
930 void RetrieveDeviceLocalAccountPolicy( | 1018 void RetrieveDeviceLocalAccountPolicy( |
931 const std::string& account_id, | 1019 const std::string& account_id, |
932 const RetrievePolicyCallback& callback) override { | 1020 const RetrievePolicyCallback& callback) override { |
933 RetrievePolicyForUser(cryptohome::Identification::FromString(account_id), | 1021 RetrievePolicyForUser(cryptohome::Identification::FromString(account_id), |
934 callback); | 1022 callback); |
935 } | 1023 } |
936 std::string BlockingRetrieveDeviceLocalAccountPolicy( | 1024 RetrievePolicyResponseType BlockingRetrieveDeviceLocalAccountPolicy( |
937 const std::string& account_id) override { | 1025 const std::string& account_id, |
| 1026 std::string* policy) override { |
938 return BlockingRetrievePolicyForUser( | 1027 return BlockingRetrievePolicyForUser( |
939 cryptohome::Identification::FromString(account_id)); | 1028 cryptohome::Identification::FromString(account_id), policy); |
940 } | 1029 } |
941 void StoreDevicePolicy(const std::string& policy_blob, | 1030 void StoreDevicePolicy(const std::string& policy_blob, |
942 const StorePolicyCallback& callback) override { | 1031 const StorePolicyCallback& callback) override { |
943 enterprise_management::PolicyFetchResponse response; | 1032 enterprise_management::PolicyFetchResponse response; |
944 base::FilePath owner_key_path; | 1033 base::FilePath owner_key_path; |
945 if (!response.ParseFromString(policy_blob) || | 1034 if (!response.ParseFromString(policy_blob) || |
946 !PathService::Get(chromeos::FILE_OWNER_KEY, &owner_key_path)) { | 1035 !PathService::Get(chromeos::FILE_OWNER_KEY, &owner_key_path)) { |
947 callback.Run(false); | 1036 callback.Run(false); |
948 return; | 1037 return; |
949 } | 1038 } |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1088 | 1177 |
1089 SessionManagerClient* SessionManagerClient::Create( | 1178 SessionManagerClient* SessionManagerClient::Create( |
1090 DBusClientImplementationType type) { | 1179 DBusClientImplementationType type) { |
1091 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) | 1180 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) |
1092 return new SessionManagerClientImpl(); | 1181 return new SessionManagerClientImpl(); |
1093 DCHECK_EQ(FAKE_DBUS_CLIENT_IMPLEMENTATION, type); | 1182 DCHECK_EQ(FAKE_DBUS_CLIENT_IMPLEMENTATION, type); |
1094 return new SessionManagerClientStubImpl(); | 1183 return new SessionManagerClientStubImpl(); |
1095 } | 1184 } |
1096 | 1185 |
1097 } // namespace chromeos | 1186 } // namespace chromeos |
OLD | NEW |