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/power_manager_client.h" | 5 #include "chromeos/dbus/power_manager_client.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
75 } | 75 } |
76 | 76 |
77 virtual void RemoveObserver(Observer* observer) override { | 77 virtual void RemoveObserver(Observer* observer) override { |
78 observers_.RemoveObserver(observer); | 78 observers_.RemoveObserver(observer); |
79 } | 79 } |
80 | 80 |
81 virtual bool HasObserver(const Observer* observer) const override { | 81 virtual bool HasObserver(const Observer* observer) const override { |
82 return observers_.HasObserver(observer); | 82 return observers_.HasObserver(observer); |
83 } | 83 } |
84 | 84 |
85 virtual void SetRenderProcessManagerDelegate( | |
86 base::WeakPtr<RenderProcessManagerDelegate> delegate) override { | |
87 DCHECK(!delegate_) << "There can be only one! " | |
88 << "...RenderProcessManagerDelegate"; | |
89 delegate_ = delegate; | |
90 } | |
91 | |
85 virtual void DecreaseScreenBrightness(bool allow_off) override { | 92 virtual void DecreaseScreenBrightness(bool allow_off) override { |
86 dbus::MethodCall method_call( | 93 dbus::MethodCall method_call( |
87 power_manager::kPowerManagerInterface, | 94 power_manager::kPowerManagerInterface, |
88 power_manager::kDecreaseScreenBrightnessMethod); | 95 power_manager::kDecreaseScreenBrightnessMethod); |
89 dbus::MessageWriter writer(&method_call); | 96 dbus::MessageWriter writer(&method_call); |
90 writer.AppendBool(allow_off); | 97 writer.AppendBool(allow_off); |
91 power_manager_proxy_->CallMethod( | 98 power_manager_proxy_->CallMethod( |
92 &method_call, | 99 &method_call, |
93 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 100 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
94 dbus::ObjectProxy::EmptyResponseCallback()); | 101 dbus::ObjectProxy::EmptyResponseCallback()); |
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
527 LOG(ERROR) << "Unable to decode protocol buffer from " | 534 LOG(ERROR) << "Unable to decode protocol buffer from " |
528 << power_manager::kSuspendDoneSignal << " signal"; | 535 << power_manager::kSuspendDoneSignal << " signal"; |
529 return; | 536 return; |
530 } | 537 } |
531 | 538 |
532 const base::TimeDelta duration = | 539 const base::TimeDelta duration = |
533 base::TimeDelta::FromInternalValue(proto.suspend_duration()); | 540 base::TimeDelta::FromInternalValue(proto.suspend_duration()); |
534 VLOG(1) << "Got " << power_manager::kSuspendDoneSignal << " signal:" | 541 VLOG(1) << "Got " << power_manager::kSuspendDoneSignal << " signal:" |
535 << " suspend_id=" << proto.suspend_id() | 542 << " suspend_id=" << proto.suspend_id() |
536 << " duration=" << duration.InSeconds() << " sec"; | 543 << " duration=" << duration.InSeconds() << " sec"; |
544 | |
545 if (delegate_) | |
546 delegate_->SuspendDone(); | |
547 | |
537 FOR_EACH_OBSERVER( | 548 FOR_EACH_OBSERVER( |
538 PowerManagerClient::Observer, observers_, SuspendDone(duration)); | 549 PowerManagerClient::Observer, observers_, SuspendDone(duration)); |
539 base::PowerMonitorDeviceSource::HandleSystemResumed(); | 550 base::PowerMonitorDeviceSource::HandleSystemResumed(); |
540 } | 551 } |
541 | 552 |
542 void IdleActionImminentReceived(dbus::Signal* signal) { | 553 void IdleActionImminentReceived(dbus::Signal* signal) { |
543 dbus::MessageReader reader(signal); | 554 dbus::MessageReader reader(signal); |
544 power_manager::IdleActionImminent proto; | 555 power_manager::IdleActionImminent proto; |
545 if (!reader.PopArrayOfBytesAsProto(&proto)) { | 556 if (!reader.PopArrayOfBytesAsProto(&proto)) { |
546 LOG(ERROR) << "Unable to decode protocol buffer from " | 557 LOG(ERROR) << "Unable to decode protocol buffer from " |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
672 std::string method_name; | 683 std::string method_name; |
673 int32_t delay_id = -1; | 684 int32_t delay_id = -1; |
674 if (suspending_from_dark_resume_) { | 685 if (suspending_from_dark_resume_) { |
675 method_name = power_manager::kHandleDarkSuspendReadinessMethod; | 686 method_name = power_manager::kHandleDarkSuspendReadinessMethod; |
676 delay_id = dark_suspend_delay_id_; | 687 delay_id = dark_suspend_delay_id_; |
677 } else { | 688 } else { |
678 method_name = power_manager::kHandleSuspendReadinessMethod; | 689 method_name = power_manager::kHandleSuspendReadinessMethod; |
679 delay_id = suspend_delay_id_; | 690 delay_id = suspend_delay_id_; |
680 } | 691 } |
681 | 692 |
693 if (delegate_ && !suspending_from_dark_resume_) | |
694 delegate_->SuspendImminent(); | |
695 | |
682 dbus::MethodCall method_call( | 696 dbus::MethodCall method_call( |
683 power_manager::kPowerManagerInterface, method_name); | 697 power_manager::kPowerManagerInterface, method_name); |
684 dbus::MessageWriter writer(&method_call); | 698 dbus::MessageWriter writer(&method_call); |
685 | 699 |
686 VLOG(1) << "Announcing readiness of suspend delay " << delay_id | 700 VLOG(1) << "Announcing readiness of suspend delay " << delay_id |
687 << " for suspend attempt " << pending_suspend_id_; | 701 << " for suspend attempt " << pending_suspend_id_; |
688 power_manager::SuspendReadinessInfo protobuf_request; | 702 power_manager::SuspendReadinessInfo protobuf_request; |
689 protobuf_request.set_delay_id(delay_id); | 703 protobuf_request.set_delay_id(delay_id); |
690 protobuf_request.set_suspend_id(pending_suspend_id_); | 704 protobuf_request.set_suspend_id(pending_suspend_id_); |
691 | 705 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
728 bool suspending_from_dark_resume_; | 742 bool suspending_from_dark_resume_; |
729 | 743 |
730 // Number of callbacks that have been returned by | 744 // Number of callbacks that have been returned by |
731 // GetSuspendReadinessCallback() during the currently-pending suspend | 745 // GetSuspendReadinessCallback() during the currently-pending suspend |
732 // attempt but have not yet been called. | 746 // attempt but have not yet been called. |
733 int num_pending_suspend_readiness_callbacks_; | 747 int num_pending_suspend_readiness_callbacks_; |
734 | 748 |
735 // Last state passed to SetIsProjecting(). | 749 // Last state passed to SetIsProjecting(). |
736 bool last_is_projecting_; | 750 bool last_is_projecting_; |
737 | 751 |
752 // The delegate used to manage the power consumption of Chrome's renderer | |
753 // processes. | |
754 base::WeakPtr<RenderProcessManagerDelegate> delegate_; | |
Daniel Erat
2014/11/19 23:41:26
nit: maybe rename to render_process_manager_delega
Chirantan Ekbote
2014/11/20 00:59:37
Done.
| |
755 | |
738 // Note: This should remain the last member so it'll be destroyed and | 756 // Note: This should remain the last member so it'll be destroyed and |
739 // invalidate its weak pointers before any other members are destroyed. | 757 // invalidate its weak pointers before any other members are destroyed. |
740 base::WeakPtrFactory<PowerManagerClientImpl> weak_ptr_factory_; | 758 base::WeakPtrFactory<PowerManagerClientImpl> weak_ptr_factory_; |
741 | 759 |
742 DISALLOW_COPY_AND_ASSIGN(PowerManagerClientImpl); | 760 DISALLOW_COPY_AND_ASSIGN(PowerManagerClientImpl); |
743 }; | 761 }; |
744 | 762 |
745 // The PowerManagerClient implementation used on Linux desktop, | 763 // The PowerManagerClient implementation used on Linux desktop, |
746 // which does nothing. | 764 // which does nothing. |
747 class PowerManagerClientStubImpl : public PowerManagerClient { | 765 class PowerManagerClientStubImpl : public PowerManagerClient { |
(...skipping 29 matching lines...) Expand all Loading... | |
777 } | 795 } |
778 | 796 |
779 virtual void RemoveObserver(Observer* observer) override { | 797 virtual void RemoveObserver(Observer* observer) override { |
780 observers_.RemoveObserver(observer); | 798 observers_.RemoveObserver(observer); |
781 } | 799 } |
782 | 800 |
783 virtual bool HasObserver(const Observer* observer) const override { | 801 virtual bool HasObserver(const Observer* observer) const override { |
784 return observers_.HasObserver(observer); | 802 return observers_.HasObserver(observer); |
785 } | 803 } |
786 | 804 |
805 virtual void SetRenderProcessManagerDelegate( | |
806 base::WeakPtr<RenderProcessManagerDelegate> delegate) override { | |
807 } | |
808 | |
787 virtual void DecreaseScreenBrightness(bool allow_off) override { | 809 virtual void DecreaseScreenBrightness(bool allow_off) override { |
788 VLOG(1) << "Requested to descrease screen brightness"; | 810 VLOG(1) << "Requested to descrease screen brightness"; |
789 SetBrightness(brightness_ - 5.0, true); | 811 SetBrightness(brightness_ - 5.0, true); |
790 } | 812 } |
791 | 813 |
792 virtual void IncreaseScreenBrightness() override { | 814 virtual void IncreaseScreenBrightness() override { |
793 VLOG(1) << "Requested to increase screen brightness"; | 815 VLOG(1) << "Requested to increase screen brightness"; |
794 SetBrightness(brightness_ + 5.0, true); | 816 SetBrightness(brightness_ + 5.0, true); |
795 } | 817 } |
796 | 818 |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
970 // static | 992 // static |
971 PowerManagerClient* PowerManagerClient::Create( | 993 PowerManagerClient* PowerManagerClient::Create( |
972 DBusClientImplementationType type) { | 994 DBusClientImplementationType type) { |
973 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) | 995 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) |
974 return new PowerManagerClientImpl(); | 996 return new PowerManagerClientImpl(); |
975 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); | 997 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); |
976 return new PowerManagerClientStubImpl(); | 998 return new PowerManagerClientStubImpl(); |
977 } | 999 } |
978 | 1000 |
979 } // namespace chromeos | 1001 } // namespace chromeos |
OLD | NEW |