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