| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 void RemoveObserver(Observer* observer) override { | 82 void RemoveObserver(Observer* observer) override { |
| 83 observers_.RemoveObserver(observer); | 83 observers_.RemoveObserver(observer); |
| 84 } | 84 } |
| 85 | 85 |
| 86 bool HasObserver(const Observer* observer) const override { | 86 bool HasObserver(const Observer* observer) const override { |
| 87 return observers_.HasObserver(observer); | 87 return observers_.HasObserver(observer); |
| 88 } | 88 } |
| 89 | 89 |
| 90 void SetRenderProcessManagerDelegate( | 90 void SetRenderProcessManagerDelegate( |
| 91 base::WeakPtr<RenderProcessManagerDelegate> delegate) override { | 91 base::WeakPtr<RenderProcessManagerDelegate> delegate) override { |
| 92 // TODO(derat): Remove after http://crbug.com/648580 is fixed. | |
| 93 VLOG(1) << "Setting RenderProcessManagerDelegate to " << delegate.get(); | |
| 94 VLOG(1) << "vtable is " << *reinterpret_cast<uintptr_t*>(delegate.get()); | |
| 95 DCHECK(!render_process_manager_delegate_) | 92 DCHECK(!render_process_manager_delegate_) |
| 96 << "There can be only one! ...RenderProcessManagerDelegate"; | 93 << "There can be only one! ...RenderProcessManagerDelegate"; |
| 97 render_process_manager_delegate_ = delegate; | 94 render_process_manager_delegate_ = delegate; |
| 98 } | 95 } |
| 99 | 96 |
| 100 void DecreaseScreenBrightness(bool allow_off) override { | 97 void DecreaseScreenBrightness(bool allow_off) override { |
| 101 dbus::MethodCall method_call( | 98 dbus::MethodCall method_call( |
| 102 power_manager::kPowerManagerInterface, | 99 power_manager::kPowerManagerInterface, |
| 103 power_manager::kDecreaseScreenBrightnessMethod); | 100 power_manager::kDecreaseScreenBrightnessMethod); |
| 104 dbus::MessageWriter writer(&method_call); | 101 dbus::MessageWriter writer(&method_call); |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 } | 518 } |
| 522 | 519 |
| 523 dbus::MessageReader reader(signal); | 520 dbus::MessageReader reader(signal); |
| 524 power_manager::SuspendImminent proto; | 521 power_manager::SuspendImminent proto; |
| 525 if (!reader.PopArrayOfBytesAsProto(&proto)) { | 522 if (!reader.PopArrayOfBytesAsProto(&proto)) { |
| 526 POWER_LOG(ERROR) << "Unable to decode protocol buffer from " | 523 POWER_LOG(ERROR) << "Unable to decode protocol buffer from " |
| 527 << signal_name << " signal"; | 524 << signal_name << " signal"; |
| 528 return; | 525 return; |
| 529 } | 526 } |
| 530 | 527 |
| 531 // TODO(derat): Switch back to POWER_LOG(EVENT) after | 528 POWER_LOG(EVENT) << "Got " << signal_name |
| 532 // http://crbug.com/648580 is fixed. | 529 << " signal announcing suspend attempt " |
| 533 VLOG(1) << "Got " << signal_name << " signal announcing suspend attempt " | 530 << proto.suspend_id(); |
| 534 << proto.suspend_id(); | |
| 535 | 531 |
| 536 // If a previous suspend is pending from the same state we are currently in | 532 // If a previous suspend is pending from the same state we are currently in |
| 537 // (fully powered on or in dark resume), then something's gone a little | 533 // (fully powered on or in dark resume), then something's gone a little |
| 538 // wonky. | 534 // wonky. |
| 539 if (suspend_is_pending_ && suspending_from_dark_resume_ == in_dark_resume) { | 535 if (suspend_is_pending_ && suspending_from_dark_resume_ == in_dark_resume) { |
| 540 POWER_LOG(ERROR) << "Got " << signal_name | 536 POWER_LOG(ERROR) << "Got " << signal_name |
| 541 << " signal about pending suspend attempt " | 537 << " signal about pending suspend attempt " |
| 542 << proto.suspend_id() | 538 << proto.suspend_id() |
| 543 << " while still waiting on attempt " | 539 << " while still waiting on attempt " |
| 544 << pending_suspend_id_; | 540 << pending_suspend_id_; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 568 dbus::MessageReader reader(signal); | 564 dbus::MessageReader reader(signal); |
| 569 power_manager::SuspendDone proto; | 565 power_manager::SuspendDone proto; |
| 570 if (!reader.PopArrayOfBytesAsProto(&proto)) { | 566 if (!reader.PopArrayOfBytesAsProto(&proto)) { |
| 571 POWER_LOG(ERROR) << "Unable to decode protocol buffer from " | 567 POWER_LOG(ERROR) << "Unable to decode protocol buffer from " |
| 572 << power_manager::kSuspendDoneSignal << " signal"; | 568 << power_manager::kSuspendDoneSignal << " signal"; |
| 573 return; | 569 return; |
| 574 } | 570 } |
| 575 | 571 |
| 576 const base::TimeDelta duration = | 572 const base::TimeDelta duration = |
| 577 base::TimeDelta::FromInternalValue(proto.suspend_duration()); | 573 base::TimeDelta::FromInternalValue(proto.suspend_duration()); |
| 578 // TODO(derat): Switch back to POWER_LOG(EVENT) after | 574 POWER_LOG(EVENT) << "Got " << power_manager::kSuspendDoneSignal |
| 579 // http://crbug.com/648580 is fixed. | 575 << " signal:" |
| 580 VLOG(1) << "Got " << power_manager::kSuspendDoneSignal << " signal:" | 576 << " suspend_id=" << proto.suspend_id() |
| 581 << " suspend_id=" << proto.suspend_id() | 577 << " duration=" << duration.InSeconds() << " sec"; |
| 582 << " duration=" << duration.InSeconds() << " sec"; | |
| 583 | 578 |
| 584 // RenderProcessManagerDelegate is only notified that suspend is imminent | 579 // RenderProcessManagerDelegate is only notified that suspend is imminent |
| 585 // when readiness is being reported to powerd. If the suspend attempt was | 580 // when readiness is being reported to powerd. If the suspend attempt was |
| 586 // cancelled before then, we shouldn't notify the delegate about completion. | 581 // cancelled before then, we shouldn't notify the delegate about completion. |
| 587 const bool cancelled_while_regular_suspend_pending = | 582 const bool cancelled_while_regular_suspend_pending = |
| 588 suspend_is_pending_ && !suspending_from_dark_resume_; | 583 suspend_is_pending_ && !suspending_from_dark_resume_; |
| 589 // TODO(derat): Remove VLOG(1)s after http://crbug.com/648580 is fixed. | |
| 590 VLOG(1) << "RenderProcessManagerDelegate is " | |
| 591 << render_process_manager_delegate_.get() << "; suspend is" | |
| 592 << (suspend_is_pending_ ? "" : "n't") << " pending and was" | |
| 593 << (suspending_from_dark_resume_ ? "" : "n't") | |
| 594 << " suspending from dark resume"; | |
| 595 if (render_process_manager_delegate_ && | 584 if (render_process_manager_delegate_ && |
| 596 !cancelled_while_regular_suspend_pending) { | 585 !cancelled_while_regular_suspend_pending) |
| 597 VLOG(1) << "Calling RenderProcessManagerDelegate::SuspendDone()"; | |
| 598 VLOG(1) << "vtable is " | |
| 599 << *reinterpret_cast<uintptr_t*>( | |
| 600 render_process_manager_delegate_.get()); | |
| 601 render_process_manager_delegate_->SuspendDone(); | 586 render_process_manager_delegate_->SuspendDone(); |
| 602 } | |
| 603 | 587 |
| 604 // powerd always pairs each SuspendImminent signal with SuspendDone before | 588 // powerd always pairs each SuspendImminent signal with SuspendDone before |
| 605 // starting the next suspend attempt, so we should no longer report | 589 // starting the next suspend attempt, so we should no longer report |
| 606 // readiness for any in-progress suspend attempts. | 590 // readiness for any in-progress suspend attempts. |
| 607 pending_suspend_id_ = -1; | 591 pending_suspend_id_ = -1; |
| 608 suspend_is_pending_ = false; | 592 suspend_is_pending_ = false; |
| 609 suspending_from_dark_resume_ = false; | 593 suspending_from_dark_resume_ = false; |
| 610 num_pending_suspend_readiness_callbacks_ = 0; | 594 num_pending_suspend_readiness_callbacks_ = 0; |
| 611 | 595 |
| 612 FOR_EACH_OBSERVER( | 596 FOR_EACH_OBSERVER( |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 732 weak_ptr_factory_.GetWeakPtr(), true, | 716 weak_ptr_factory_.GetWeakPtr(), true, |
| 733 power_manager::kRegisterDarkSuspendDelayMethod)); | 717 power_manager::kRegisterDarkSuspendDelayMethod)); |
| 734 } | 718 } |
| 735 | 719 |
| 736 // Records the fact that an observer has finished doing asynchronous work | 720 // Records the fact that an observer has finished doing asynchronous work |
| 737 // that was blocking a pending suspend attempt and possibly reports | 721 // that was blocking a pending suspend attempt and possibly reports |
| 738 // suspend readiness to powerd. Called by callbacks returned via | 722 // suspend readiness to powerd. Called by callbacks returned via |
| 739 // GetSuspendReadinessCallback(). | 723 // GetSuspendReadinessCallback(). |
| 740 void HandleObserverSuspendReadiness(int32_t suspend_id, bool in_dark_resume) { | 724 void HandleObserverSuspendReadiness(int32_t suspend_id, bool in_dark_resume) { |
| 741 DCHECK(OnOriginThread()); | 725 DCHECK(OnOriginThread()); |
| 742 // TODO(derat): Remove after http://crbug.com/648580 is fixed. | |
| 743 VLOG(1) << "Got notification of observer readiness for " | |
| 744 << (in_dark_resume ? "dark" : "regular") << " suspend ID " | |
| 745 << suspend_id << " (pending " << pending_suspend_id_ << ")"; | |
| 746 if (!suspend_is_pending_ || suspend_id != pending_suspend_id_ || | 726 if (!suspend_is_pending_ || suspend_id != pending_suspend_id_ || |
| 747 in_dark_resume != suspending_from_dark_resume_) | 727 in_dark_resume != suspending_from_dark_resume_) |
| 748 return; | 728 return; |
| 749 | 729 |
| 750 num_pending_suspend_readiness_callbacks_--; | 730 num_pending_suspend_readiness_callbacks_--; |
| 751 MaybeReportSuspendReadiness(); | 731 MaybeReportSuspendReadiness(); |
| 752 } | 732 } |
| 753 | 733 |
| 754 // Reports suspend readiness to powerd if no observers are still holding | 734 // Reports suspend readiness to powerd if no observers are still holding |
| 755 // suspend readiness callbacks. | 735 // suspend readiness callbacks. |
| 756 void MaybeReportSuspendReadiness() { | 736 void MaybeReportSuspendReadiness() { |
| 757 CHECK(suspend_is_pending_); | 737 CHECK(suspend_is_pending_); |
| 758 | 738 |
| 759 // Avoid reporting suspend readiness if some observers have yet to be | 739 // Avoid reporting suspend readiness if some observers have yet to be |
| 760 // notified about the pending attempt. | 740 // notified about the pending attempt. |
| 761 if (notifying_observers_about_suspend_imminent_) | 741 if (notifying_observers_about_suspend_imminent_) |
| 762 return; | 742 return; |
| 763 | 743 |
| 764 if (num_pending_suspend_readiness_callbacks_ > 0) { | 744 if (num_pending_suspend_readiness_callbacks_ > 0) |
| 765 // TODO(derat): Remove after http://crbug.com/648580 is fixed. | |
| 766 VLOG(1) << "Not reporting suspend readiness; waiting for " | |
| 767 << num_pending_suspend_readiness_callbacks_ << " callback(s)"; | |
| 768 return; | 745 return; |
| 769 } | |
| 770 | 746 |
| 771 std::string method_name; | 747 std::string method_name; |
| 772 int32_t delay_id = -1; | 748 int32_t delay_id = -1; |
| 773 if (suspending_from_dark_resume_) { | 749 if (suspending_from_dark_resume_) { |
| 774 method_name = power_manager::kHandleDarkSuspendReadinessMethod; | 750 method_name = power_manager::kHandleDarkSuspendReadinessMethod; |
| 775 delay_id = dark_suspend_delay_id_; | 751 delay_id = dark_suspend_delay_id_; |
| 776 } else { | 752 } else { |
| 777 method_name = power_manager::kHandleSuspendReadinessMethod; | 753 method_name = power_manager::kHandleSuspendReadinessMethod; |
| 778 delay_id = suspend_delay_id_; | 754 delay_id = suspend_delay_id_; |
| 779 } | 755 } |
| 780 | 756 |
| 781 // TODO(derat): Remove VLOG(1)s after http://crbug.com/648580 is fixed. | 757 if (render_process_manager_delegate_ && !suspending_from_dark_resume_) |
| 782 VLOG(1) << "RenderProcessManagerDelegate is " | |
| 783 << render_process_manager_delegate_.get() << "; " | |
| 784 << (suspending_from_dark_resume_ ? "" : "not ") | |
| 785 << "suspending from dark resume"; | |
| 786 if (render_process_manager_delegate_ && !suspending_from_dark_resume_) { | |
| 787 VLOG(1) << "Calling RenderProcessManagerDelegate::SuspendImminent()"; | |
| 788 VLOG(1) << "vtable is " | |
| 789 << *reinterpret_cast<uintptr_t*>( | |
| 790 render_process_manager_delegate_.get()); | |
| 791 render_process_manager_delegate_->SuspendImminent(); | 758 render_process_manager_delegate_->SuspendImminent(); |
| 792 } | |
| 793 | 759 |
| 794 dbus::MethodCall method_call( | 760 dbus::MethodCall method_call( |
| 795 power_manager::kPowerManagerInterface, method_name); | 761 power_manager::kPowerManagerInterface, method_name); |
| 796 dbus::MessageWriter writer(&method_call); | 762 dbus::MessageWriter writer(&method_call); |
| 797 | 763 |
| 798 // TODO(derat): Switch back to POWER_LOG(EVENT) after | 764 POWER_LOG(EVENT) << "Announcing readiness of suspend delay " << delay_id |
| 799 // http://crbug.com/648580 is fixed. | 765 << " for suspend attempt " << pending_suspend_id_; |
| 800 VLOG(1) << "Announcing readiness of suspend delay " << delay_id | |
| 801 << " for suspend attempt " << pending_suspend_id_; | |
| 802 power_manager::SuspendReadinessInfo protobuf_request; | 766 power_manager::SuspendReadinessInfo protobuf_request; |
| 803 protobuf_request.set_delay_id(delay_id); | 767 protobuf_request.set_delay_id(delay_id); |
| 804 protobuf_request.set_suspend_id(pending_suspend_id_); | 768 protobuf_request.set_suspend_id(pending_suspend_id_); |
| 805 | 769 |
| 806 pending_suspend_id_ = -1; | 770 pending_suspend_id_ = -1; |
| 807 suspend_is_pending_ = false; | 771 suspend_is_pending_ = false; |
| 808 | 772 |
| 809 if (!writer.AppendProtoAsArrayOfBytes(protobuf_request)) { | 773 if (!writer.AppendProtoAsArrayOfBytes(protobuf_request)) { |
| 810 POWER_LOG(ERROR) << "Error constructing message for " << method_name; | 774 POWER_LOG(ERROR) << "Error constructing message for " << method_name; |
| 811 return; | 775 return; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 874 // static | 838 // static |
| 875 PowerManagerClient* PowerManagerClient::Create( | 839 PowerManagerClient* PowerManagerClient::Create( |
| 876 DBusClientImplementationType type) { | 840 DBusClientImplementationType type) { |
| 877 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) | 841 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) |
| 878 return new PowerManagerClientImpl(); | 842 return new PowerManagerClientImpl(); |
| 879 DCHECK_EQ(FAKE_DBUS_CLIENT_IMPLEMENTATION, type); | 843 DCHECK_EQ(FAKE_DBUS_CLIENT_IMPLEMENTATION, type); |
| 880 return new FakePowerManagerClient(); | 844 return new FakePowerManagerClient(); |
| 881 } | 845 } |
| 882 | 846 |
| 883 } // namespace chromeos | 847 } // namespace chromeos |
| OLD | NEW |