| 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 786 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 797 const power_manager::PowerManagementPolicy& policy) OVERRIDE {} | 797 const power_manager::PowerManagementPolicy& policy) OVERRIDE {} |
| 798 virtual void SetIsProjecting(bool is_projecting) OVERRIDE {} | 798 virtual void SetIsProjecting(bool is_projecting) OVERRIDE {} |
| 799 virtual base::Closure GetSuspendReadinessCallback() OVERRIDE { | 799 virtual base::Closure GetSuspendReadinessCallback() OVERRIDE { |
| 800 return base::Closure(); | 800 return base::Closure(); |
| 801 } | 801 } |
| 802 | 802 |
| 803 private: | 803 private: |
| 804 void UpdateStatus() { | 804 void UpdateStatus() { |
| 805 if (pause_count_ > 0) { | 805 if (pause_count_ > 0) { |
| 806 pause_count_--; | 806 pause_count_--; |
| 807 if (pause_count_ == 2) |
| 808 discharging_ = !discharging_; |
| 807 } else { | 809 } else { |
| 808 int discharge_amt = battery_percentage_ <= 10 ? 1 : 10; | 810 if (discharging_) |
| 809 battery_percentage_ += (discharging_ ? -discharge_amt : discharge_amt); | 811 battery_percentage_ -= (battery_percentage_ <= 10 ? 1 : 10); |
| 812 else |
| 813 battery_percentage_ += (battery_percentage_ >= 10 ? 10 : 1); |
| 810 battery_percentage_ = std::min(std::max(battery_percentage_, 0), 100); | 814 battery_percentage_ = std::min(std::max(battery_percentage_, 0), 100); |
| 811 // We pause at 0 and 100% so that it's easier to check those conditions. | 815 // We pause at 0 and 100% so that it's easier to check those conditions. |
| 812 if (battery_percentage_ == 0 || battery_percentage_ == 100) { | 816 if (battery_percentage_ == 0 || battery_percentage_ == 100) { |
| 813 discharging_ = !discharging_; | |
| 814 pause_count_ = 4; | 817 pause_count_ = 4; |
| 815 if (battery_percentage_ == 100) | 818 if (battery_percentage_ == 100) |
| 816 cycle_count_ = (cycle_count_ + 1) % 3; | 819 cycle_count_ = (cycle_count_ + 1) % 3; |
| 817 } | 820 } |
| 818 } | 821 } |
| 819 const int kSecondsToEmptyFullBattery(3 * 60 * 60); // 3 hours. | 822 const int kSecondsToEmptyFullBattery = 3 * 60 * 60; // 3 hours. |
| 820 | 823 |
| 821 status_.is_calculating_battery_time = (pause_count_ > 1); | 824 status_.is_calculating_battery_time = (pause_count_ > 1); |
| 822 status_.line_power_on = !discharging_; | 825 status_.line_power_on = !discharging_; |
| 823 status_.battery_is_present = true; | 826 status_.battery_is_present = true; |
| 824 status_.battery_percentage = battery_percentage_; | 827 status_.battery_percentage = battery_percentage_; |
| 828 status_.battery_is_full = battery_percentage_ == 100 && !discharging_; |
| 825 if (cycle_count_ != 2) { | 829 if (cycle_count_ != 2) { |
| 826 status_.battery_state = discharging_ ? | 830 status_.battery_state = discharging_ ? |
| 827 PowerSupplyStatus::DISCHARGING : PowerSupplyStatus::CHARGING; | 831 PowerSupplyStatus::DISCHARGING : PowerSupplyStatus::CHARGING; |
| 828 } else { | 832 } else { |
| 829 status_.battery_state = PowerSupplyStatus::CONNECTED_TO_USB; | 833 status_.battery_state = PowerSupplyStatus::CONNECTED_TO_USB; |
| 830 } | 834 } |
| 831 | 835 |
| 832 int64 remaining_battery_time = | 836 int64 remaining_battery_time = |
| 833 std::max(1, battery_percentage_ * kSecondsToEmptyFullBattery / 100); | 837 std::max(1, battery_percentage_ * kSecondsToEmptyFullBattery / 100); |
| 834 status_.battery_seconds_to_empty = | 838 status_.battery_seconds_to_empty = |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 876 PowerManagerClient* PowerManagerClient::Create( | 880 PowerManagerClient* PowerManagerClient::Create( |
| 877 DBusClientImplementationType type, | 881 DBusClientImplementationType type, |
| 878 dbus::Bus* bus) { | 882 dbus::Bus* bus) { |
| 879 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) | 883 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) |
| 880 return new PowerManagerClientImpl(bus); | 884 return new PowerManagerClientImpl(bus); |
| 881 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); | 885 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); |
| 882 return new PowerManagerClientStubImpl(); | 886 return new PowerManagerClientStubImpl(); |
| 883 } | 887 } |
| 884 | 888 |
| 885 } // namespace chromeos | 889 } // namespace chromeos |
| OLD | NEW |