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