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 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
536 << " signal about pending suspend attempt " | 536 << " signal about pending suspend attempt " |
537 << proto.suspend_id() | 537 << proto.suspend_id() |
538 << " while still waiting on attempt " | 538 << " while still waiting on attempt " |
539 << pending_suspend_id_; | 539 << pending_suspend_id_; |
540 } | 540 } |
541 | 541 |
542 pending_suspend_id_ = proto.suspend_id(); | 542 pending_suspend_id_ = proto.suspend_id(); |
543 suspend_is_pending_ = true; | 543 suspend_is_pending_ = true; |
544 suspending_from_dark_resume_ = in_dark_resume; | 544 suspending_from_dark_resume_ = in_dark_resume; |
545 num_pending_suspend_readiness_callbacks_ = 0; | 545 num_pending_suspend_readiness_callbacks_ = 0; |
| 546 |
546 if (suspending_from_dark_resume_) | 547 if (suspending_from_dark_resume_) |
547 FOR_EACH_OBSERVER(Observer, observers_, DarkSuspendImminent()); | 548 FOR_EACH_OBSERVER(Observer, observers_, DarkSuspendImminent()); |
548 else | 549 else |
549 FOR_EACH_OBSERVER(Observer, observers_, SuspendImminent()); | 550 FOR_EACH_OBSERVER(Observer, observers_, SuspendImminent()); |
550 base::PowerMonitorDeviceSource::HandleSystemSuspending(); | 551 base::PowerMonitorDeviceSource::HandleSystemSuspending(); |
551 MaybeReportSuspendReadiness(); | 552 MaybeReportSuspendReadiness(); |
552 } | 553 } |
553 | 554 |
554 void SuspendDoneReceived(dbus::Signal* signal) { | 555 void SuspendDoneReceived(dbus::Signal* signal) { |
555 dbus::MessageReader reader(signal); | 556 dbus::MessageReader reader(signal); |
556 power_manager::SuspendDone proto; | 557 power_manager::SuspendDone proto; |
557 if (!reader.PopArrayOfBytesAsProto(&proto)) { | 558 if (!reader.PopArrayOfBytesAsProto(&proto)) { |
558 POWER_LOG(ERROR) << "Unable to decode protocol buffer from " | 559 POWER_LOG(ERROR) << "Unable to decode protocol buffer from " |
559 << power_manager::kSuspendDoneSignal << " signal"; | 560 << power_manager::kSuspendDoneSignal << " signal"; |
560 return; | 561 return; |
561 } | 562 } |
562 | 563 |
563 const base::TimeDelta duration = | 564 const base::TimeDelta duration = |
564 base::TimeDelta::FromInternalValue(proto.suspend_duration()); | 565 base::TimeDelta::FromInternalValue(proto.suspend_duration()); |
565 POWER_LOG(EVENT) << "Got " << power_manager::kSuspendDoneSignal | 566 POWER_LOG(EVENT) << "Got " << power_manager::kSuspendDoneSignal |
566 << " signal:" | 567 << " signal:" |
567 << " suspend_id=" << proto.suspend_id() | 568 << " suspend_id=" << proto.suspend_id() |
568 << " duration=" << duration.InSeconds() << " sec"; | 569 << " duration=" << duration.InSeconds() << " sec"; |
569 | 570 |
570 if (render_process_manager_delegate_) | 571 // RenderProcessManagerDelegate is only notified that suspend is imminent |
| 572 // when readiness is being reported to powerd. If the suspend attempt was |
| 573 // cancelled before then, we shouldn't notify the delegate about completion. |
| 574 const bool cancelled_while_regular_suspend_pending = |
| 575 suspend_is_pending_ && !suspending_from_dark_resume_; |
| 576 if (render_process_manager_delegate_ && |
| 577 !cancelled_while_regular_suspend_pending) |
571 render_process_manager_delegate_->SuspendDone(); | 578 render_process_manager_delegate_->SuspendDone(); |
572 | 579 |
| 580 // powerd always pairs each SuspendImminent signal with SuspendDone before |
| 581 // starting the next suspend attempt, so we should no longer report |
| 582 // readiness for any in-progress suspend attempts. |
| 583 pending_suspend_id_ = -1; |
| 584 suspend_is_pending_ = false; |
| 585 suspending_from_dark_resume_ = false; |
| 586 num_pending_suspend_readiness_callbacks_ = 0; |
| 587 |
573 FOR_EACH_OBSERVER( | 588 FOR_EACH_OBSERVER( |
574 PowerManagerClient::Observer, observers_, SuspendDone(duration)); | 589 PowerManagerClient::Observer, observers_, SuspendDone(duration)); |
575 base::PowerMonitorDeviceSource::HandleSystemResumed(); | 590 base::PowerMonitorDeviceSource::HandleSystemResumed(); |
576 } | 591 } |
577 | 592 |
578 void IdleActionImminentReceived(dbus::Signal* signal) { | 593 void IdleActionImminentReceived(dbus::Signal* signal) { |
579 dbus::MessageReader reader(signal); | 594 dbus::MessageReader reader(signal); |
580 power_manager::IdleActionImminent proto; | 595 power_manager::IdleActionImminent proto; |
581 if (!reader.PopArrayOfBytesAsProto(&proto)) { | 596 if (!reader.PopArrayOfBytesAsProto(&proto)) { |
582 POWER_LOG(ERROR) << "Unable to decode protocol buffer from " | 597 POWER_LOG(ERROR) << "Unable to decode protocol buffer from " |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
704 in_dark_resume != suspending_from_dark_resume_) | 719 in_dark_resume != suspending_from_dark_resume_) |
705 return; | 720 return; |
706 | 721 |
707 num_pending_suspend_readiness_callbacks_--; | 722 num_pending_suspend_readiness_callbacks_--; |
708 MaybeReportSuspendReadiness(); | 723 MaybeReportSuspendReadiness(); |
709 } | 724 } |
710 | 725 |
711 // Reports suspend readiness to powerd if no observers are still holding | 726 // Reports suspend readiness to powerd if no observers are still holding |
712 // suspend readiness callbacks. | 727 // suspend readiness callbacks. |
713 void MaybeReportSuspendReadiness() { | 728 void MaybeReportSuspendReadiness() { |
714 if (!suspend_is_pending_ || num_pending_suspend_readiness_callbacks_ > 0) | 729 CHECK(suspend_is_pending_); |
| 730 |
| 731 if (num_pending_suspend_readiness_callbacks_ > 0) |
715 return; | 732 return; |
716 | 733 |
717 std::string method_name; | 734 std::string method_name; |
718 int32_t delay_id = -1; | 735 int32_t delay_id = -1; |
719 if (suspending_from_dark_resume_) { | 736 if (suspending_from_dark_resume_) { |
720 method_name = power_manager::kHandleDarkSuspendReadinessMethod; | 737 method_name = power_manager::kHandleDarkSuspendReadinessMethod; |
721 delay_id = dark_suspend_delay_id_; | 738 delay_id = dark_suspend_delay_id_; |
722 } else { | 739 } else { |
723 method_name = power_manager::kHandleSuspendReadinessMethod; | 740 method_name = power_manager::kHandleSuspendReadinessMethod; |
724 delay_id = suspend_delay_id_; | 741 delay_id = suspend_delay_id_; |
(...skipping 24 matching lines...) Expand all Loading... |
749 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 766 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
750 dbus::ObjectProxy::EmptyResponseCallback()); | 767 dbus::ObjectProxy::EmptyResponseCallback()); |
751 } | 768 } |
752 | 769 |
753 // Origin thread (i.e. the UI thread in production). | 770 // Origin thread (i.e. the UI thread in production). |
754 base::PlatformThreadId origin_thread_id_; | 771 base::PlatformThreadId origin_thread_id_; |
755 | 772 |
756 dbus::ObjectProxy* power_manager_proxy_; | 773 dbus::ObjectProxy* power_manager_proxy_; |
757 base::ObserverList<Observer> observers_; | 774 base::ObserverList<Observer> observers_; |
758 | 775 |
759 // The delay_id_ obtained from the RegisterSuspendDelay request. | 776 // The delay ID obtained from the RegisterSuspendDelay request. |
760 int32_t suspend_delay_id_; | 777 int32_t suspend_delay_id_; |
761 bool has_suspend_delay_id_; | 778 bool has_suspend_delay_id_; |
762 | 779 |
763 // The delay_id_ obtained from the RegisterDarkSuspendDelay request. | 780 // The delay ID obtained from the RegisterDarkSuspendDelay request. |
764 int32_t dark_suspend_delay_id_; | 781 int32_t dark_suspend_delay_id_; |
765 bool has_dark_suspend_delay_id_; | 782 bool has_dark_suspend_delay_id_; |
766 | 783 |
767 // powerd-supplied ID corresponding to an imminent suspend attempt that is | 784 // powerd-supplied ID corresponding to an imminent (either regular or dark) |
768 // currently being delayed. | 785 // suspend attempt that is currently being delayed. |
769 int32_t pending_suspend_id_; | 786 int32_t pending_suspend_id_; |
770 bool suspend_is_pending_; | 787 bool suspend_is_pending_; |
771 | 788 |
772 // Set to true when the suspend currently being delayed was triggered during a | 789 // Set to true when the suspend currently being delayed was triggered during a |
773 // dark resume. Since |pending_suspend_id_| and |suspend_is_pending_| are | 790 // dark resume. Since |pending_suspend_id_| and |suspend_is_pending_| are |
774 // both shared by normal and dark suspends, |suspending_from_dark_resume_| | 791 // both shared by normal and dark suspends, |suspending_from_dark_resume_| |
775 // helps distinguish the context within which these variables are being used. | 792 // helps distinguish the context within which these variables are being used. |
776 bool suspending_from_dark_resume_; | 793 bool suspending_from_dark_resume_; |
777 | 794 |
778 // Number of callbacks that have been returned by | 795 // Number of callbacks that have been returned by |
(...skipping 24 matching lines...) Expand all Loading... |
803 // static | 820 // static |
804 PowerManagerClient* PowerManagerClient::Create( | 821 PowerManagerClient* PowerManagerClient::Create( |
805 DBusClientImplementationType type) { | 822 DBusClientImplementationType type) { |
806 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) | 823 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) |
807 return new PowerManagerClientImpl(); | 824 return new PowerManagerClientImpl(); |
808 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); | 825 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); |
809 return new FakePowerManagerClient(); | 826 return new FakePowerManagerClient(); |
810 } | 827 } |
811 | 828 |
812 } // namespace chromeos | 829 } // namespace chromeos |
OLD | NEW |