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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
81 void RemoveObserver(Observer* observer) override { | 81 void RemoveObserver(Observer* observer) override { |
82 observers_.RemoveObserver(observer); | 82 observers_.RemoveObserver(observer); |
83 } | 83 } |
84 | 84 |
85 bool HasObserver(const Observer* observer) const override { | 85 bool HasObserver(const Observer* observer) const override { |
86 return observers_.HasObserver(observer); | 86 return observers_.HasObserver(observer); |
87 } | 87 } |
88 | 88 |
89 void SetRenderProcessManagerDelegate( | 89 void SetRenderProcessManagerDelegate( |
90 base::WeakPtr<RenderProcessManagerDelegate> delegate) override { | 90 base::WeakPtr<RenderProcessManagerDelegate> delegate) override { |
91 // TODO(derat): Remove after http://crbug.com/648580 is fixed. | |
92 VLOG(1) << "Setting RenderProcessManagerDelegate to " << delegate.get(); | |
93 VLOG(1) << "vtable is " << *reinterpret_cast<uintptr_t*>(delegate.get()); | |
llozano
2016/10/06 22:55:11
nit: you are not using parenthesis after * like in
Daniel Erat
2016/10/06 23:00:09
true. i'll remove them from the other places
| |
91 DCHECK(!render_process_manager_delegate_) | 94 DCHECK(!render_process_manager_delegate_) |
92 << "There can be only one! ...RenderProcessManagerDelegate"; | 95 << "There can be only one! ...RenderProcessManagerDelegate"; |
93 render_process_manager_delegate_ = delegate; | 96 render_process_manager_delegate_ = delegate; |
94 } | 97 } |
95 | 98 |
96 void DecreaseScreenBrightness(bool allow_off) override { | 99 void DecreaseScreenBrightness(bool allow_off) override { |
97 dbus::MethodCall method_call( | 100 dbus::MethodCall method_call( |
98 power_manager::kPowerManagerInterface, | 101 power_manager::kPowerManagerInterface, |
99 power_manager::kDecreaseScreenBrightnessMethod); | 102 power_manager::kDecreaseScreenBrightnessMethod); |
100 dbus::MessageWriter writer(&method_call); | 103 dbus::MessageWriter writer(&method_call); |
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
517 } | 520 } |
518 | 521 |
519 dbus::MessageReader reader(signal); | 522 dbus::MessageReader reader(signal); |
520 power_manager::SuspendImminent proto; | 523 power_manager::SuspendImminent proto; |
521 if (!reader.PopArrayOfBytesAsProto(&proto)) { | 524 if (!reader.PopArrayOfBytesAsProto(&proto)) { |
522 POWER_LOG(ERROR) << "Unable to decode protocol buffer from " | 525 POWER_LOG(ERROR) << "Unable to decode protocol buffer from " |
523 << signal_name << " signal"; | 526 << signal_name << " signal"; |
524 return; | 527 return; |
525 } | 528 } |
526 | 529 |
527 POWER_LOG(EVENT) << "Got " << signal_name | 530 // TODO(derat): Switch back to POWER_LOG(EVENT) after |
528 << " signal announcing suspend attempt " | 531 // http://crbug.com/648580 is fixed. |
529 << proto.suspend_id(); | 532 VLOG(1) << "Got " << signal_name << " signal announcing suspend attempt " |
533 << proto.suspend_id(); | |
530 | 534 |
531 // If a previous suspend is pending from the same state we are currently in | 535 // If a previous suspend is pending from the same state we are currently in |
532 // (fully powered on or in dark resume), then something's gone a little | 536 // (fully powered on or in dark resume), then something's gone a little |
533 // wonky. | 537 // wonky. |
534 if (suspend_is_pending_ && suspending_from_dark_resume_ == in_dark_resume) { | 538 if (suspend_is_pending_ && suspending_from_dark_resume_ == in_dark_resume) { |
535 POWER_LOG(ERROR) << "Got " << signal_name | 539 POWER_LOG(ERROR) << "Got " << signal_name |
536 << " signal about pending suspend attempt " | 540 << " signal about pending suspend attempt " |
537 << proto.suspend_id() | 541 << proto.suspend_id() |
538 << " while still waiting on attempt " | 542 << " while still waiting on attempt " |
539 << pending_suspend_id_; | 543 << pending_suspend_id_; |
(...skipping 16 matching lines...) Expand all Loading... | |
556 dbus::MessageReader reader(signal); | 560 dbus::MessageReader reader(signal); |
557 power_manager::SuspendDone proto; | 561 power_manager::SuspendDone proto; |
558 if (!reader.PopArrayOfBytesAsProto(&proto)) { | 562 if (!reader.PopArrayOfBytesAsProto(&proto)) { |
559 POWER_LOG(ERROR) << "Unable to decode protocol buffer from " | 563 POWER_LOG(ERROR) << "Unable to decode protocol buffer from " |
560 << power_manager::kSuspendDoneSignal << " signal"; | 564 << power_manager::kSuspendDoneSignal << " signal"; |
561 return; | 565 return; |
562 } | 566 } |
563 | 567 |
564 const base::TimeDelta duration = | 568 const base::TimeDelta duration = |
565 base::TimeDelta::FromInternalValue(proto.suspend_duration()); | 569 base::TimeDelta::FromInternalValue(proto.suspend_duration()); |
566 POWER_LOG(EVENT) << "Got " << power_manager::kSuspendDoneSignal | 570 // TODO(derat): Switch back to POWER_LOG(EVENT) after |
567 << " signal:" | 571 // http://crbug.com/648580 is fixed. |
568 << " suspend_id=" << proto.suspend_id() | 572 VLOG(1) << "Got " << power_manager::kSuspendDoneSignal << " signal:" |
569 << " duration=" << duration.InSeconds() << " sec"; | 573 << " suspend_id=" << proto.suspend_id() |
574 << " duration=" << duration.InSeconds() << " sec"; | |
570 | 575 |
571 // RenderProcessManagerDelegate is only notified that suspend is imminent | 576 // RenderProcessManagerDelegate is only notified that suspend is imminent |
572 // when readiness is being reported to powerd. If the suspend attempt was | 577 // when readiness is being reported to powerd. If the suspend attempt was |
573 // cancelled before then, we shouldn't notify the delegate about completion. | 578 // cancelled before then, we shouldn't notify the delegate about completion. |
574 const bool cancelled_while_regular_suspend_pending = | 579 const bool cancelled_while_regular_suspend_pending = |
575 suspend_is_pending_ && !suspending_from_dark_resume_; | 580 suspend_is_pending_ && !suspending_from_dark_resume_; |
581 // TODO(derat): Remove VLOG(1)s after http://crbug.com/648580 is fixed. | |
582 VLOG(1) << "RenderProcessManagerDelegate is " | |
583 << render_process_manager_delegate_.get() << "; suspend is" | |
584 << (suspend_is_pending_ ? "" : "n't") << " pending and was" | |
585 << (suspending_from_dark_resume_ ? "" : "n't") | |
586 << " suspending from dark resume"; | |
576 if (render_process_manager_delegate_ && | 587 if (render_process_manager_delegate_ && |
577 !cancelled_while_regular_suspend_pending) | 588 !cancelled_while_regular_suspend_pending) { |
589 VLOG(1) << "Calling RenderProcessManagerDelegate::SuspendDone()"; | |
590 VLOG(1) << "vtable is " | |
591 << *(reinterpret_cast<uintptr_t*>( | |
592 render_process_manager_delegate_.get())); | |
578 render_process_manager_delegate_->SuspendDone(); | 593 render_process_manager_delegate_->SuspendDone(); |
594 } | |
579 | 595 |
580 // powerd always pairs each SuspendImminent signal with SuspendDone before | 596 // powerd always pairs each SuspendImminent signal with SuspendDone before |
581 // starting the next suspend attempt, so we should no longer report | 597 // starting the next suspend attempt, so we should no longer report |
582 // readiness for any in-progress suspend attempts. | 598 // readiness for any in-progress suspend attempts. |
583 pending_suspend_id_ = -1; | 599 pending_suspend_id_ = -1; |
584 suspend_is_pending_ = false; | 600 suspend_is_pending_ = false; |
585 suspending_from_dark_resume_ = false; | 601 suspending_from_dark_resume_ = false; |
586 num_pending_suspend_readiness_callbacks_ = 0; | 602 num_pending_suspend_readiness_callbacks_ = 0; |
587 | 603 |
588 FOR_EACH_OBSERVER( | 604 FOR_EACH_OBSERVER( |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
708 weak_ptr_factory_.GetWeakPtr(), true, | 724 weak_ptr_factory_.GetWeakPtr(), true, |
709 power_manager::kRegisterDarkSuspendDelayMethod)); | 725 power_manager::kRegisterDarkSuspendDelayMethod)); |
710 } | 726 } |
711 | 727 |
712 // Records the fact that an observer has finished doing asynchronous work | 728 // Records the fact that an observer has finished doing asynchronous work |
713 // that was blocking a pending suspend attempt and possibly reports | 729 // that was blocking a pending suspend attempt and possibly reports |
714 // suspend readiness to powerd. Called by callbacks returned via | 730 // suspend readiness to powerd. Called by callbacks returned via |
715 // GetSuspendReadinessCallback(). | 731 // GetSuspendReadinessCallback(). |
716 void HandleObserverSuspendReadiness(int32_t suspend_id, bool in_dark_resume) { | 732 void HandleObserverSuspendReadiness(int32_t suspend_id, bool in_dark_resume) { |
717 DCHECK(OnOriginThread()); | 733 DCHECK(OnOriginThread()); |
734 // TODO(derat): Remove after http://crbug.com/648580 is fixed. | |
735 VLOG(1) << "Got notification of observer readiness for " | |
736 << (in_dark_resume ? "dark" : "regular") << " suspend ID " | |
737 << suspend_id << " (pending " << pending_suspend_id_ << ")"; | |
718 if (!suspend_is_pending_ || suspend_id != pending_suspend_id_ || | 738 if (!suspend_is_pending_ || suspend_id != pending_suspend_id_ || |
719 in_dark_resume != suspending_from_dark_resume_) | 739 in_dark_resume != suspending_from_dark_resume_) |
720 return; | 740 return; |
721 | 741 |
722 num_pending_suspend_readiness_callbacks_--; | 742 num_pending_suspend_readiness_callbacks_--; |
723 MaybeReportSuspendReadiness(); | 743 MaybeReportSuspendReadiness(); |
724 } | 744 } |
725 | 745 |
726 // Reports suspend readiness to powerd if no observers are still holding | 746 // Reports suspend readiness to powerd if no observers are still holding |
727 // suspend readiness callbacks. | 747 // suspend readiness callbacks. |
728 void MaybeReportSuspendReadiness() { | 748 void MaybeReportSuspendReadiness() { |
729 CHECK(suspend_is_pending_); | 749 CHECK(suspend_is_pending_); |
730 | 750 |
731 if (num_pending_suspend_readiness_callbacks_ > 0) | 751 if (num_pending_suspend_readiness_callbacks_ > 0) { |
752 // TODO(derat): Remove after http://crbug.com/648580 is fixed. | |
753 VLOG(1) << "Not reporting suspend readiness; waiting for " | |
754 << num_pending_suspend_readiness_callbacks_ << " callback(s)"; | |
732 return; | 755 return; |
756 } | |
733 | 757 |
734 std::string method_name; | 758 std::string method_name; |
735 int32_t delay_id = -1; | 759 int32_t delay_id = -1; |
736 if (suspending_from_dark_resume_) { | 760 if (suspending_from_dark_resume_) { |
737 method_name = power_manager::kHandleDarkSuspendReadinessMethod; | 761 method_name = power_manager::kHandleDarkSuspendReadinessMethod; |
738 delay_id = dark_suspend_delay_id_; | 762 delay_id = dark_suspend_delay_id_; |
739 } else { | 763 } else { |
740 method_name = power_manager::kHandleSuspendReadinessMethod; | 764 method_name = power_manager::kHandleSuspendReadinessMethod; |
741 delay_id = suspend_delay_id_; | 765 delay_id = suspend_delay_id_; |
742 } | 766 } |
743 | 767 |
744 if (render_process_manager_delegate_ && !suspending_from_dark_resume_) | 768 // TODO(derat): Remove VLOG(1)s after http://crbug.com/648580 is fixed. |
769 VLOG(1) << "RenderProcessManagerDelegate is " | |
770 << render_process_manager_delegate_.get() << "; " | |
771 << (suspending_from_dark_resume_ ? "" : "not ") | |
772 << "suspending from dark resume"; | |
773 if (render_process_manager_delegate_ && !suspending_from_dark_resume_) { | |
774 VLOG(1) << "Calling RenderProcessManagerDelegate::SuspendImminent()"; | |
775 VLOG(1) << "vtable is " | |
776 << *(reinterpret_cast<uintptr_t*>( | |
777 render_process_manager_delegate_.get())); | |
745 render_process_manager_delegate_->SuspendImminent(); | 778 render_process_manager_delegate_->SuspendImminent(); |
779 } | |
746 | 780 |
747 dbus::MethodCall method_call( | 781 dbus::MethodCall method_call( |
748 power_manager::kPowerManagerInterface, method_name); | 782 power_manager::kPowerManagerInterface, method_name); |
749 dbus::MessageWriter writer(&method_call); | 783 dbus::MessageWriter writer(&method_call); |
750 | 784 |
751 POWER_LOG(EVENT) << "Announcing readiness of suspend delay " << delay_id | 785 // TODO(derat): Switch back to POWER_LOG(EVENT) after |
752 << " for suspend attempt " << pending_suspend_id_; | 786 // http://crbug.com/648580 is fixed. |
787 VLOG(1) << "Announcing readiness of suspend delay " << delay_id | |
788 << " for suspend attempt " << pending_suspend_id_; | |
753 power_manager::SuspendReadinessInfo protobuf_request; | 789 power_manager::SuspendReadinessInfo protobuf_request; |
754 protobuf_request.set_delay_id(delay_id); | 790 protobuf_request.set_delay_id(delay_id); |
755 protobuf_request.set_suspend_id(pending_suspend_id_); | 791 protobuf_request.set_suspend_id(pending_suspend_id_); |
756 | 792 |
757 pending_suspend_id_ = -1; | 793 pending_suspend_id_ = -1; |
758 suspend_is_pending_ = false; | 794 suspend_is_pending_ = false; |
759 | 795 |
760 if (!writer.AppendProtoAsArrayOfBytes(protobuf_request)) { | 796 if (!writer.AppendProtoAsArrayOfBytes(protobuf_request)) { |
761 POWER_LOG(ERROR) << "Error constructing message for " << method_name; | 797 POWER_LOG(ERROR) << "Error constructing message for " << method_name; |
762 return; | 798 return; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
820 // static | 856 // static |
821 PowerManagerClient* PowerManagerClient::Create( | 857 PowerManagerClient* PowerManagerClient::Create( |
822 DBusClientImplementationType type) { | 858 DBusClientImplementationType type) { |
823 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) | 859 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) |
824 return new PowerManagerClientImpl(); | 860 return new PowerManagerClientImpl(); |
825 DCHECK_EQ(FAKE_DBUS_CLIENT_IMPLEMENTATION, type); | 861 DCHECK_EQ(FAKE_DBUS_CLIENT_IMPLEMENTATION, type); |
826 return new FakePowerManagerClient(); | 862 return new FakePowerManagerClient(); |
827 } | 863 } |
828 | 864 |
829 } // namespace chromeos | 865 } // namespace chromeos |
OLD | NEW |