Chromium Code Reviews| 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 } 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(const base::StringPiece& method_name, | |
|
Alexei Svitkine (slow)
2017/04/26 14:57:26
Pass StringPiece by value (see comments in its hea
igorcov
2017/04/27 09:51:19
Done.
| |
| 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 | |
| 106 } // namespace | 149 } // namespace |
| 107 | 150 |
| 108 // The SessionManagerClient implementation used in production. | 151 // The SessionManagerClient implementation used in production. |
| 109 class SessionManagerClientImpl : public SessionManagerClient { | 152 class SessionManagerClientImpl : public SessionManagerClient { |
| 110 public: | 153 public: |
| 111 SessionManagerClientImpl() | 154 SessionManagerClientImpl() |
| 112 : session_manager_proxy_(NULL), | 155 : session_manager_proxy_(NULL), |
| 113 screen_is_locked_(false), | 156 screen_is_locked_(false), |
| 114 weak_ptr_factory_(this) {} | 157 weak_ptr_factory_(this) {} |
| 115 | 158 |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 224 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 267 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 225 base::Bind(&SessionManagerClientImpl::OnRetrieveActiveSessions, | 268 base::Bind(&SessionManagerClientImpl::OnRetrieveActiveSessions, |
| 226 weak_ptr_factory_.GetWeakPtr(), | 269 weak_ptr_factory_.GetWeakPtr(), |
| 227 login_manager::kSessionManagerRetrieveActiveSessions, | 270 login_manager::kSessionManagerRetrieveActiveSessions, |
| 228 callback)); | 271 callback)); |
| 229 } | 272 } |
| 230 | 273 |
| 231 void RetrieveDevicePolicy(const RetrievePolicyCallback& callback) override { | 274 void RetrieveDevicePolicy(const RetrievePolicyCallback& callback) override { |
| 232 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, | 275 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, |
| 233 login_manager::kSessionManagerRetrievePolicy); | 276 login_manager::kSessionManagerRetrievePolicy); |
| 234 session_manager_proxy_->CallMethod( | 277 session_manager_proxy_->CallMethodWithErrorCallback( |
| 235 &method_call, | 278 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 236 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 279 base::Bind(&SessionManagerClientImpl::OnRetrievePolicySuccess, |
| 237 base::Bind(&SessionManagerClientImpl::OnRetrievePolicy, | |
| 238 weak_ptr_factory_.GetWeakPtr(), | 280 weak_ptr_factory_.GetWeakPtr(), |
| 239 login_manager::kSessionManagerRetrievePolicy, | 281 login_manager::kSessionManagerRetrievePolicy, callback), |
| 240 callback)); | 282 base::Bind(&SessionManagerClientImpl::OnRetrievePolicyError, |
| 283 weak_ptr_factory_.GetWeakPtr(), | |
| 284 login_manager::kSessionManagerRetrievePolicy, callback)); | |
| 241 } | 285 } |
| 242 | 286 |
| 243 std::string BlockingRetrieveDevicePolicy() override { | 287 RetrievePolicyResponseType BlockingRetrieveDevicePolicy( |
| 288 std::string* policy_out) override { | |
| 244 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, | 289 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, |
| 245 login_manager::kSessionManagerRetrievePolicy); | 290 login_manager::kSessionManagerRetrievePolicy); |
| 291 dbus::ScopedDBusError error; | |
| 246 std::unique_ptr<dbus::Response> response = | 292 std::unique_ptr<dbus::Response> response = |
| 247 blocking_method_caller_->CallMethodAndBlock(&method_call); | 293 blocking_method_caller_->CallMethodAndBlockWithError(&method_call, |
| 248 std::string policy; | 294 &error); |
| 249 ExtractString(login_manager::kSessionManagerRetrievePolicy, response.get(), | 295 RetrievePolicyResponseType result = RetrievePolicyResponseType::SUCCESS; |
| 250 &policy); | 296 if (error.is_set() && error.name()) { |
| 251 return policy; | 297 result = GetResponseTypeBasedOnError(error.name()); |
| 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; | |
| 252 } | 307 } |
| 253 | 308 |
| 254 void RetrievePolicyForUser(const cryptohome::Identification& cryptohome_id, | 309 void RetrievePolicyForUser(const cryptohome::Identification& cryptohome_id, |
| 255 const RetrievePolicyCallback& callback) override { | 310 const RetrievePolicyCallback& callback) override { |
| 256 CallRetrievePolicyByUsername( | 311 CallRetrievePolicyByUsername( |
| 257 login_manager::kSessionManagerRetrievePolicyForUser, cryptohome_id.id(), | 312 login_manager::kSessionManagerRetrievePolicyForUser, cryptohome_id.id(), |
| 258 callback); | 313 callback); |
| 259 } | 314 } |
| 260 | 315 |
| 261 std::string BlockingRetrievePolicyForUser( | 316 RetrievePolicyResponseType BlockingRetrievePolicyForUser( |
| 262 const cryptohome::Identification& cryptohome_id) override { | 317 const cryptohome::Identification& cryptohome_id, |
| 263 dbus::MethodCall method_call( | 318 std::string* policy_out) override { |
| 264 login_manager::kSessionManagerInterface, | 319 return BlockingRetrievePolicyByUsername( |
| 265 login_manager::kSessionManagerRetrievePolicyForUser); | 320 login_manager::kSessionManagerRetrievePolicyForUser, cryptohome_id.id(), |
| 266 dbus::MessageWriter writer(&method_call); | 321 policy_out); |
| 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 } | 322 } |
| 276 | 323 |
| 277 void RetrieveDeviceLocalAccountPolicy( | 324 void RetrieveDeviceLocalAccountPolicy( |
| 278 const std::string& account_name, | 325 const std::string& account_name, |
| 279 const RetrievePolicyCallback& callback) override { | 326 const RetrievePolicyCallback& callback) override { |
| 280 CallRetrievePolicyByUsername( | 327 CallRetrievePolicyByUsername( |
| 281 login_manager::kSessionManagerRetrieveDeviceLocalAccountPolicy, | 328 login_manager::kSessionManagerRetrieveDeviceLocalAccountPolicy, |
| 282 account_name, | 329 account_name, callback); |
| 283 callback); | |
| 284 } | 330 } |
| 285 | 331 |
| 286 std::string BlockingRetrieveDeviceLocalAccountPolicy( | 332 RetrievePolicyResponseType BlockingRetrieveDeviceLocalAccountPolicy( |
| 287 const std::string& account_name) override { | 333 const std::string& account_name, |
| 288 dbus::MethodCall method_call( | 334 std::string* policy_out) override { |
| 289 login_manager::kSessionManagerInterface, | 335 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, | 336 login_manager::kSessionManagerRetrieveDeviceLocalAccountPolicy, |
| 298 response.get(), &policy); | 337 account_name, policy_out); |
| 299 return policy; | |
| 300 } | 338 } |
| 301 | 339 |
| 302 void StoreDevicePolicy(const std::string& policy_blob, | 340 void StoreDevicePolicy(const std::string& policy_blob, |
| 303 const StorePolicyCallback& callback) override { | 341 const StorePolicyCallback& callback) override { |
| 304 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, | 342 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, |
| 305 login_manager::kSessionManagerStorePolicy); | 343 login_manager::kSessionManagerStorePolicy); |
| 306 dbus::MessageWriter writer(&method_call); | 344 dbus::MessageWriter writer(&method_call); |
| 307 // static_cast does not work due to signedness. | 345 // static_cast does not work due to signedness. |
| 308 writer.AppendArrayOfBytes( | 346 writer.AppendArrayOfBytes( |
| 309 reinterpret_cast<const uint8_t*>(policy_blob.data()), | 347 reinterpret_cast<const uint8_t*>(policy_blob.data()), |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 517 } | 555 } |
| 518 | 556 |
| 519 // Helper for RetrieveDeviceLocalAccountPolicy and RetrievePolicyForUser. | 557 // Helper for RetrieveDeviceLocalAccountPolicy and RetrievePolicyForUser. |
| 520 void CallRetrievePolicyByUsername(const std::string& method_name, | 558 void CallRetrievePolicyByUsername(const std::string& method_name, |
| 521 const std::string& account_id, | 559 const std::string& account_id, |
| 522 const RetrievePolicyCallback& callback) { | 560 const RetrievePolicyCallback& callback) { |
| 523 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, | 561 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, |
| 524 method_name); | 562 method_name); |
| 525 dbus::MessageWriter writer(&method_call); | 563 dbus::MessageWriter writer(&method_call); |
| 526 writer.AppendString(account_id); | 564 writer.AppendString(account_id); |
| 527 session_manager_proxy_->CallMethod( | 565 session_manager_proxy_->CallMethodWithErrorCallback( |
| 528 &method_call, | 566 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 529 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 567 base::Bind(&SessionManagerClientImpl::OnRetrievePolicySuccess, |
| 530 base::Bind( | 568 weak_ptr_factory_.GetWeakPtr(), method_name, callback), |
| 531 &SessionManagerClientImpl::OnRetrievePolicy, | 569 base::Bind(&SessionManagerClientImpl::OnRetrievePolicyError, |
| 532 weak_ptr_factory_.GetWeakPtr(), | 570 weak_ptr_factory_.GetWeakPtr(), method_name, callback)); |
| 533 method_name, | 571 } |
| 534 callback)); | 572 |
| 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; | |
| 535 } | 598 } |
| 536 | 599 |
| 537 void CallStorePolicyByUsername(const std::string& method_name, | 600 void CallStorePolicyByUsername(const std::string& method_name, |
| 538 const std::string& account_id, | 601 const std::string& account_id, |
| 539 const std::string& policy_blob, | 602 const std::string& policy_blob, |
| 540 const StorePolicyCallback& callback) { | 603 const StorePolicyCallback& callback) { |
| 541 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, | 604 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, |
| 542 method_name); | 605 method_name); |
| 543 dbus::MessageWriter writer(&method_call); | 606 dbus::MessageWriter writer(&method_call); |
| 544 writer.AppendString(account_id); | 607 writer.AppendString(account_id); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 636 size_t length = 0; | 699 size_t length = 0; |
| 637 if (!reader.PopArrayOfBytes(&values, &length)) { | 700 if (!reader.PopArrayOfBytes(&values, &length)) { |
| 638 LOG(ERROR) << "Invalid response: " << response->ToString(); | 701 LOG(ERROR) << "Invalid response: " << response->ToString(); |
| 639 return; | 702 return; |
| 640 } | 703 } |
| 641 // static_cast does not work due to signedness. | 704 // static_cast does not work due to signedness. |
| 642 extracted->assign(reinterpret_cast<const char*>(values), length); | 705 extracted->assign(reinterpret_cast<const char*>(values), length); |
| 643 } | 706 } |
| 644 | 707 |
| 645 // Called when kSessionManagerRetrievePolicy or | 708 // Called when kSessionManagerRetrievePolicy or |
| 646 // kSessionManagerRetrievePolicyForUser method is complete. | 709 // kSessionManagerRetrievePolicyForUser method is successfully complete. |
| 647 void OnRetrievePolicy(const std::string& method_name, | 710 void OnRetrievePolicySuccess(const std::string& method_name, |
| 648 const RetrievePolicyCallback& callback, | 711 const RetrievePolicyCallback& callback, |
| 649 dbus::Response* response) { | 712 dbus::Response* response) { |
| 650 std::string serialized_proto; | 713 std::string serialized_proto; |
| 651 ExtractString(method_name, response, &serialized_proto); | 714 ExtractString(method_name, response, &serialized_proto); |
| 652 callback.Run(serialized_proto); | 715 callback.Run(serialized_proto, RetrievePolicyResponseType::SUCCESS); |
| 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); | |
| 653 } | 730 } |
| 654 | 731 |
| 655 // Called when kSessionManagerStorePolicy or kSessionManagerStorePolicyForUser | 732 // Called when kSessionManagerStorePolicy or kSessionManagerStorePolicyForUser |
| 656 // method is complete. | 733 // method is complete. |
| 657 void OnStorePolicy(const std::string& method_name, | 734 void OnStorePolicy(const std::string& method_name, |
| 658 const StorePolicyCallback& callback, | 735 const StorePolicyCallback& callback, |
| 659 dbus::Response* response) { | 736 dbus::Response* response) { |
| 660 bool success = false; | 737 bool success = false; |
| 661 if (!response) { | 738 if (!response) { |
| 662 LOG(ERROR) << "Failed to call " << method_name; | 739 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, | 890 void OnStartArcInstanceSucceeded(const StartArcInstanceCallback& callback, |
| 814 dbus::Response* response) { | 891 dbus::Response* response) { |
| 815 if (!callback.is_null()) | 892 if (!callback.is_null()) |
| 816 callback.Run(StartArcInstanceResult::SUCCESS); | 893 callback.Run(StartArcInstanceResult::SUCCESS); |
| 817 } | 894 } |
| 818 | 895 |
| 819 void OnStartArcInstanceFailed(const StartArcInstanceCallback& callback, | 896 void OnStartArcInstanceFailed(const StartArcInstanceCallback& callback, |
| 820 dbus::ErrorResponse* response) { | 897 dbus::ErrorResponse* response) { |
| 821 LOG(ERROR) << "Failed to call StartArcInstance: " | 898 LOG(ERROR) << "Failed to call StartArcInstance: " |
| 822 << (response ? response->ToString() : "(null)"); | 899 << (response ? response->ToString() : "(null)"); |
| 823 if (!callback.is_null()) | 900 if (!callback.is_null()) { |
| 824 callback.Run(response && response->GetErrorName() == kArcLowDiskError | 901 callback.Run(response && response->GetErrorName() == |
| 902 login_manager::dbus_error::kLowFreeDisk | |
| 825 ? StartArcInstanceResult::LOW_FREE_DISK_SPACE | 903 ? StartArcInstanceResult::LOW_FREE_DISK_SPACE |
| 826 : StartArcInstanceResult::UNKNOWN_ERROR); | 904 : StartArcInstanceResult::UNKNOWN_ERROR); |
| 905 } | |
| 827 } | 906 } |
| 828 | 907 |
| 829 dbus::ObjectProxy* session_manager_proxy_; | 908 dbus::ObjectProxy* session_manager_proxy_; |
| 830 std::unique_ptr<BlockingMethodCaller> blocking_method_caller_; | 909 std::unique_ptr<BlockingMethodCaller> blocking_method_caller_; |
| 831 base::ObserverList<Observer> observers_; | 910 base::ObserverList<Observer> observers_; |
| 832 | 911 |
| 833 // Most recent screen-lock state received from session_manager. | 912 // Most recent screen-lock state received from session_manager. |
| 834 bool screen_is_locked_; | 913 bool screen_is_locked_; |
| 835 | 914 |
| 836 // Note: This should remain the last member so it'll be destroyed and | 915 // 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 { | 962 void NotifyLockScreenDismissed() override { |
| 884 screen_is_locked_ = false; | 963 screen_is_locked_ = false; |
| 885 for (auto& observer : observers_) | 964 for (auto& observer : observers_) |
| 886 observer.ScreenIsUnlocked(); | 965 observer.ScreenIsUnlocked(); |
| 887 } | 966 } |
| 888 void RetrieveActiveSessions(const ActiveSessionsCallback& callback) override { | 967 void RetrieveActiveSessions(const ActiveSessionsCallback& callback) override { |
| 889 } | 968 } |
| 890 void RetrieveDevicePolicy(const RetrievePolicyCallback& callback) override { | 969 void RetrieveDevicePolicy(const RetrievePolicyCallback& callback) override { |
| 891 base::FilePath owner_key_path; | 970 base::FilePath owner_key_path; |
| 892 if (!PathService::Get(chromeos::FILE_OWNER_KEY, &owner_key_path)) { | 971 if (!PathService::Get(chromeos::FILE_OWNER_KEY, &owner_key_path)) { |
| 893 callback.Run(""); | 972 callback.Run("", RetrievePolicyResponseType::SUCCESS); |
| 894 return; | 973 return; |
| 895 } | 974 } |
| 896 base::FilePath device_policy_path = | 975 base::FilePath device_policy_path = |
| 897 owner_key_path.DirName().AppendASCII(kStubDevicePolicyFile); | 976 owner_key_path.DirName().AppendASCII(kStubDevicePolicyFile); |
| 898 base::PostTaskWithTraitsAndReplyWithResult( | 977 base::PostTaskWithTraitsAndReplyWithResult( |
| 899 FROM_HERE, base::TaskTraits() | 978 FROM_HERE, |
| 900 .WithShutdownBehavior( | 979 base::TaskTraits() |
| 901 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN) | 980 .WithShutdownBehavior( |
| 902 .MayBlock(), | 981 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN) |
| 903 base::Bind(&GetFileContent, device_policy_path), callback); | 982 .MayBlock(), |
| 983 base::Bind(&GetFileContent, device_policy_path), | |
| 984 base::Bind(&NotifyOnRetrievePolicySuccess, callback)); | |
| 904 } | 985 } |
| 905 std::string BlockingRetrieveDevicePolicy() override { | 986 RetrievePolicyResponseType BlockingRetrieveDevicePolicy( |
| 987 std::string* policy_out) override { | |
| 906 base::FilePath owner_key_path; | 988 base::FilePath owner_key_path; |
| 907 if (!PathService::Get(chromeos::FILE_OWNER_KEY, &owner_key_path)) { | 989 if (!PathService::Get(chromeos::FILE_OWNER_KEY, &owner_key_path)) { |
| 908 return ""; | 990 *policy_out = ""; |
| 991 return RetrievePolicyResponseType::SUCCESS; | |
| 909 } | 992 } |
| 910 base::FilePath device_policy_path = | 993 base::FilePath device_policy_path = |
| 911 owner_key_path.DirName().AppendASCII(kStubDevicePolicyFile); | 994 owner_key_path.DirName().AppendASCII(kStubDevicePolicyFile); |
| 912 return GetFileContent(device_policy_path); | 995 *policy_out = GetFileContent(device_policy_path); |
| 996 return RetrievePolicyResponseType::SUCCESS; | |
| 913 } | 997 } |
| 914 void RetrievePolicyForUser(const cryptohome::Identification& cryptohome_id, | 998 void RetrievePolicyForUser(const cryptohome::Identification& cryptohome_id, |
| 915 const RetrievePolicyCallback& callback) override { | 999 const RetrievePolicyCallback& callback) override { |
| 916 base::PostTaskWithTraitsAndReplyWithResult( | 1000 base::PostTaskWithTraitsAndReplyWithResult( |
| 917 FROM_HERE, | 1001 FROM_HERE, |
| 918 base::TaskTraits() | 1002 base::TaskTraits() |
| 919 .WithShutdownBehavior( | 1003 .WithShutdownBehavior( |
| 920 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN) | 1004 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN) |
| 921 .MayBlock(), | 1005 .MayBlock(), |
| 922 base::Bind(&GetFileContent, | 1006 base::Bind(&GetFileContent, |
| 923 GetUserFilePath(cryptohome_id, kStubPolicyFile)), | 1007 GetUserFilePath(cryptohome_id, kStubPolicyFile)), |
| 924 callback); | 1008 base::Bind(&NotifyOnRetrievePolicySuccess, callback)); |
| 925 } | 1009 } |
| 926 std::string BlockingRetrievePolicyForUser( | 1010 RetrievePolicyResponseType BlockingRetrievePolicyForUser( |
| 927 const cryptohome::Identification& cryptohome_id) override { | 1011 const cryptohome::Identification& cryptohome_id, |
| 928 return GetFileContent(GetUserFilePath(cryptohome_id, kStubPolicyFile)); | 1012 std::string* policy_out) override { |
| 1013 *policy_out = | |
| 1014 GetFileContent(GetUserFilePath(cryptohome_id, kStubPolicyFile)); | |
| 1015 return RetrievePolicyResponseType::SUCCESS; | |
| 929 } | 1016 } |
| 930 void RetrieveDeviceLocalAccountPolicy( | 1017 void RetrieveDeviceLocalAccountPolicy( |
| 931 const std::string& account_id, | 1018 const std::string& account_id, |
| 932 const RetrievePolicyCallback& callback) override { | 1019 const RetrievePolicyCallback& callback) override { |
| 933 RetrievePolicyForUser(cryptohome::Identification::FromString(account_id), | 1020 RetrievePolicyForUser(cryptohome::Identification::FromString(account_id), |
| 934 callback); | 1021 callback); |
| 935 } | 1022 } |
| 936 std::string BlockingRetrieveDeviceLocalAccountPolicy( | 1023 RetrievePolicyResponseType BlockingRetrieveDeviceLocalAccountPolicy( |
| 937 const std::string& account_id) override { | 1024 const std::string& account_id, |
| 1025 std::string* policy_out) override { | |
| 938 return BlockingRetrievePolicyForUser( | 1026 return BlockingRetrievePolicyForUser( |
| 939 cryptohome::Identification::FromString(account_id)); | 1027 cryptohome::Identification::FromString(account_id), policy_out); |
| 940 } | 1028 } |
| 941 void StoreDevicePolicy(const std::string& policy_blob, | 1029 void StoreDevicePolicy(const std::string& policy_blob, |
| 942 const StorePolicyCallback& callback) override { | 1030 const StorePolicyCallback& callback) override { |
| 943 enterprise_management::PolicyFetchResponse response; | 1031 enterprise_management::PolicyFetchResponse response; |
| 944 base::FilePath owner_key_path; | 1032 base::FilePath owner_key_path; |
| 945 if (!response.ParseFromString(policy_blob) || | 1033 if (!response.ParseFromString(policy_blob) || |
| 946 !PathService::Get(chromeos::FILE_OWNER_KEY, &owner_key_path)) { | 1034 !PathService::Get(chromeos::FILE_OWNER_KEY, &owner_key_path)) { |
| 947 callback.Run(false); | 1035 callback.Run(false); |
| 948 return; | 1036 return; |
| 949 } | 1037 } |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1088 | 1176 |
| 1089 SessionManagerClient* SessionManagerClient::Create( | 1177 SessionManagerClient* SessionManagerClient::Create( |
| 1090 DBusClientImplementationType type) { | 1178 DBusClientImplementationType type) { |
| 1091 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) | 1179 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) |
| 1092 return new SessionManagerClientImpl(); | 1180 return new SessionManagerClientImpl(); |
| 1093 DCHECK_EQ(FAKE_DBUS_CLIENT_IMPLEMENTATION, type); | 1181 DCHECK_EQ(FAKE_DBUS_CLIENT_IMPLEMENTATION, type); |
| 1094 return new SessionManagerClientStubImpl(); | 1182 return new SessionManagerClientStubImpl(); |
| 1095 } | 1183 } |
| 1096 | 1184 |
| 1097 } // namespace chromeos | 1185 } // namespace chromeos |
| OLD | NEW |