| 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> |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 #include "dbus/bus.h" | 29 #include "dbus/bus.h" |
| 30 #include "dbus/message.h" | 30 #include "dbus/message.h" |
| 31 #include "dbus/object_path.h" | 31 #include "dbus/object_path.h" |
| 32 #include "dbus/object_proxy.h" | 32 #include "dbus/object_proxy.h" |
| 33 #include "third_party/cros_system_api/dbus/service_constants.h" | 33 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 34 | 34 |
| 35 namespace chromeos { | 35 namespace chromeos { |
| 36 | 36 |
| 37 namespace { | 37 namespace { |
| 38 | 38 |
| 39 // TODO(hidehiko): Share the constant between Chrome and ChromeOS. |
| 40 constexpr char kArcLowDiskError[] = |
| 41 "org.chromium.SessionManagerInterface.LowFreeDisk"; |
| 42 |
| 39 // Returns a location for |file| that is specific to the given |cryptohome_id|. | 43 // Returns a location for |file| that is specific to the given |cryptohome_id|. |
| 40 // These paths will be relative to DIR_USER_POLICY_KEYS, and can be used only | 44 // These paths will be relative to DIR_USER_POLICY_KEYS, and can be used only |
| 41 // to store stub files. | 45 // to store stub files. |
| 42 base::FilePath GetUserFilePath(const cryptohome::Identification& cryptohome_id, | 46 base::FilePath GetUserFilePath(const cryptohome::Identification& cryptohome_id, |
| 43 const char* file) { | 47 const char* file) { |
| 44 base::FilePath keys_path; | 48 base::FilePath keys_path; |
| 45 if (!PathService::Get(chromeos::DIR_USER_POLICY_KEYS, &keys_path)) | 49 if (!PathService::Get(chromeos::DIR_USER_POLICY_KEYS, &keys_path)) |
| 46 return base::FilePath(); | 50 return base::FilePath(); |
| 47 const std::string sanitized = | 51 const std::string sanitized = |
| 48 CryptohomeClient::GetStubSanitizedUsername(cryptohome_id); | 52 CryptohomeClient::GetStubSanitizedUsername(cryptohome_id); |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 login_manager::kSessionManagerCheckArcAvailability); | 307 login_manager::kSessionManagerCheckArcAvailability); |
| 304 | 308 |
| 305 session_manager_proxy_->CallMethod( | 309 session_manager_proxy_->CallMethod( |
| 306 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 310 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 307 base::Bind(&SessionManagerClientImpl::OnCheckArcAvailability, | 311 base::Bind(&SessionManagerClientImpl::OnCheckArcAvailability, |
| 308 weak_ptr_factory_.GetWeakPtr(), callback)); | 312 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 309 } | 313 } |
| 310 | 314 |
| 311 void StartArcInstance(const cryptohome::Identification& cryptohome_id, | 315 void StartArcInstance(const cryptohome::Identification& cryptohome_id, |
| 312 bool disable_boot_completed_broadcast, | 316 bool disable_boot_completed_broadcast, |
| 313 const ArcCallback& callback) override { | 317 const StartArcInstanceCallback& callback) override { |
| 314 dbus::MethodCall method_call( | 318 dbus::MethodCall method_call( |
| 315 login_manager::kSessionManagerInterface, | 319 login_manager::kSessionManagerInterface, |
| 316 login_manager::kSessionManagerStartArcInstance); | 320 login_manager::kSessionManagerStartArcInstance); |
| 317 dbus::MessageWriter writer(&method_call); | 321 dbus::MessageWriter writer(&method_call); |
| 318 writer.AppendString(cryptohome_id.id()); | 322 writer.AppendString(cryptohome_id.id()); |
| 319 writer.AppendBool(disable_boot_completed_broadcast); | 323 writer.AppendBool(disable_boot_completed_broadcast); |
| 320 session_manager_proxy_->CallMethod( | 324 session_manager_proxy_->CallMethodWithErrorCallback( |
| 321 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 325 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 322 base::Bind(&SessionManagerClientImpl::OnArcMethod, | 326 base::Bind(&SessionManagerClientImpl::OnStartArcInstanceSucceeded, |
| 323 weak_ptr_factory_.GetWeakPtr(), | 327 weak_ptr_factory_.GetWeakPtr(), callback), |
| 324 login_manager::kSessionManagerStartArcInstance, callback)); | 328 base::Bind(&SessionManagerClientImpl::OnStartArcInstanceFailed, |
| 329 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 325 } | 330 } |
| 326 | 331 |
| 327 void StopArcInstance(const ArcCallback& callback) override { | 332 void StopArcInstance(const ArcCallback& callback) override { |
| 328 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, | 333 dbus::MethodCall method_call(login_manager::kSessionManagerInterface, |
| 329 login_manager::kSessionManagerStopArcInstance); | 334 login_manager::kSessionManagerStopArcInstance); |
| 330 session_manager_proxy_->CallMethod( | 335 session_manager_proxy_->CallMethod( |
| 331 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 336 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 332 base::Bind(&SessionManagerClientImpl::OnArcMethod, | 337 base::Bind(&SessionManagerClientImpl::OnArcMethod, |
| 333 weak_ptr_factory_.GetWeakPtr(), | 338 weak_ptr_factory_.GetWeakPtr(), |
| 334 login_manager::kSessionManagerStopArcInstance, callback)); | 339 login_manager::kSessionManagerStopArcInstance, callback)); |
| (...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 715 if (!response) { | 720 if (!response) { |
| 716 LOG(ERROR) << "Failed to call " << method_name; | 721 LOG(ERROR) << "Failed to call " << method_name; |
| 717 } else { | 722 } else { |
| 718 success = true; | 723 success = true; |
| 719 } | 724 } |
| 720 | 725 |
| 721 if (!callback.is_null()) | 726 if (!callback.is_null()) |
| 722 callback.Run(success); | 727 callback.Run(success); |
| 723 } | 728 } |
| 724 | 729 |
| 730 void OnStartArcInstanceSucceeded(const StartArcInstanceCallback& callback, |
| 731 dbus::Response* response) { |
| 732 if (!callback.is_null()) |
| 733 callback.Run(StartArcInstanceResult::SUCCESS); |
| 734 } |
| 735 |
| 736 void OnStartArcInstanceFailed(const StartArcInstanceCallback& callback, |
| 737 dbus::ErrorResponse* response) { |
| 738 LOG(ERROR) << "Failed to call StartArcInstance: " |
| 739 << (response ? response->ToString() : "(null)"); |
| 740 if (!callback.is_null()) |
| 741 callback.Run(response && response->GetErrorName() == kArcLowDiskError |
| 742 ? StartArcInstanceResult::LOW_FREE_DISK_SPACE |
| 743 : StartArcInstanceResult::UNKNOWN_ERROR); |
| 744 } |
| 745 |
| 725 dbus::ObjectProxy* session_manager_proxy_; | 746 dbus::ObjectProxy* session_manager_proxy_; |
| 726 std::unique_ptr<BlockingMethodCaller> blocking_method_caller_; | 747 std::unique_ptr<BlockingMethodCaller> blocking_method_caller_; |
| 727 base::ObserverList<Observer> observers_; | 748 base::ObserverList<Observer> observers_; |
| 728 | 749 |
| 729 // Most recent screen-lock state received from session_manager. | 750 // Most recent screen-lock state received from session_manager. |
| 730 bool screen_is_locked_; | 751 bool screen_is_locked_; |
| 731 | 752 |
| 732 // Note: This should remain the last member so it'll be destroyed and | 753 // Note: This should remain the last member so it'll be destroyed and |
| 733 // invalidate its weak pointers before any other members are destroyed. | 754 // invalidate its weak pointers before any other members are destroyed. |
| 734 base::WeakPtrFactory<SessionManagerClientImpl> weak_ptr_factory_; | 755 base::WeakPtrFactory<SessionManagerClientImpl> weak_ptr_factory_; |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 891 if (!callback.is_null()) | 912 if (!callback.is_null()) |
| 892 callback.Run(state_keys); | 913 callback.Run(state_keys); |
| 893 } | 914 } |
| 894 | 915 |
| 895 void CheckArcAvailability(const ArcCallback& callback) override { | 916 void CheckArcAvailability(const ArcCallback& callback) override { |
| 896 callback.Run(false); | 917 callback.Run(false); |
| 897 } | 918 } |
| 898 | 919 |
| 899 void StartArcInstance(const cryptohome::Identification& cryptohome_id, | 920 void StartArcInstance(const cryptohome::Identification& cryptohome_id, |
| 900 bool disable_boot_completed_broadcast, | 921 bool disable_boot_completed_broadcast, |
| 901 const ArcCallback& callback) override { | 922 const StartArcInstanceCallback& callback) override { |
| 902 callback.Run(false); | 923 callback.Run(StartArcInstanceResult::UNKNOWN_ERROR); |
| 903 } | 924 } |
| 904 | 925 |
| 905 void PrioritizeArcInstance(const ArcCallback& callback) override { | 926 void PrioritizeArcInstance(const ArcCallback& callback) override { |
| 906 callback.Run(false); | 927 callback.Run(false); |
| 907 } | 928 } |
| 908 | 929 |
| 909 void EmitArcBooted() override {} | 930 void EmitArcBooted() override {} |
| 910 | 931 |
| 911 void StopArcInstance(const ArcCallback& callback) override { | 932 void StopArcInstance(const ArcCallback& callback) override { |
| 912 callback.Run(false); | 933 callback.Run(false); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 939 | 960 |
| 940 SessionManagerClient* SessionManagerClient::Create( | 961 SessionManagerClient* SessionManagerClient::Create( |
| 941 DBusClientImplementationType type) { | 962 DBusClientImplementationType type) { |
| 942 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) | 963 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) |
| 943 return new SessionManagerClientImpl(); | 964 return new SessionManagerClientImpl(); |
| 944 DCHECK_EQ(FAKE_DBUS_CLIENT_IMPLEMENTATION, type); | 965 DCHECK_EQ(FAKE_DBUS_CLIENT_IMPLEMENTATION, type); |
| 945 return new SessionManagerClientStubImpl(); | 966 return new SessionManagerClientStubImpl(); |
| 946 } | 967 } |
| 947 | 968 |
| 948 } // namespace chromeos | 969 } // namespace chromeos |
| OLD | NEW |