Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 #ifndef CHROMEOS_DBUS_FAKE_POWER_MANAGER_CLIENT_H_ | 5 #ifndef CHROMEOS_DBUS_FAKE_POWER_MANAGER_CLIENT_H_ |
| 6 #define CHROMEOS_DBUS_FAKE_POWER_MANAGER_CLIENT_H_ | 6 #define CHROMEOS_DBUS_FAKE_POWER_MANAGER_CLIENT_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
|
stevenjb
2015/06/26 20:42:19
We should keep <string> since we use it (even thou
| |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/command_line.h" |
| 11 #include "base/macros.h" | |
| 12 #include "base/observer_list.h" | 11 #include "base/observer_list.h" |
| 12 #include "base/power_monitor/power_monitor_device_source.h" | |
| 13 #include "base/strings/string_number_conversions.h" | |
| 14 #include "base/strings/string_split.h" | |
| 15 #include "chromeos/chromeos_switches.h" | |
| 16 #include "chromeos/dbus/power_manager/input_event.pb.h" | |
| 17 #include "chromeos/dbus/power_manager/peripheral_battery_status.pb.h" | |
| 13 #include "chromeos/dbus/power_manager/policy.pb.h" | 18 #include "chromeos/dbus/power_manager/policy.pb.h" |
| 19 #include "chromeos/dbus/power_manager/power_supply_properties.pb.h" | |
|
stevenjb
2015/06/25 17:03:47
It doesn't look like we need most of these in the
| |
| 14 #include "chromeos/dbus/power_manager/suspend.pb.h" | 20 #include "chromeos/dbus/power_manager/suspend.pb.h" |
| 15 #include "chromeos/dbus/power_manager_client.h" | 21 #include "chromeos/dbus/power_manager_client.h" |
| 16 | 22 |
| 17 namespace chromeos { | 23 namespace chromeos { |
| 18 | 24 |
| 19 // A fake implementation of PowerManagerClient. This remembers the policy passed | 25 // A fake implementation of PowerManagerClient. This remembers the policy passed |
| 20 // to SetPolicy() and the user of this class can inspect the last set policy by | 26 // to SetPolicy() and the user of this class can inspect the last set policy by |
| 21 // get_policy(). | 27 // get_policy(). |
| 22 class FakePowerManagerClient : public PowerManagerClient { | 28 class FakePowerManagerClient : public PowerManagerClient { |
| 23 public: | 29 public: |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 60 | 66 |
| 61 // Emulates the power manager announcing that the system is starting or | 67 // Emulates the power manager announcing that the system is starting or |
| 62 // completing a suspend attempt. | 68 // completing a suspend attempt. |
| 63 void SendSuspendImminent(); | 69 void SendSuspendImminent(); |
| 64 void SendSuspendDone(); | 70 void SendSuspendDone(); |
| 65 void SendDarkSuspendImminent(); | 71 void SendDarkSuspendImminent(); |
| 66 | 72 |
| 67 // Notifies observers that the power button has been pressed or released. | 73 // Notifies observers that the power button has been pressed or released. |
| 68 void SendPowerButtonEvent(bool down, const base::TimeTicks& timestamp); | 74 void SendPowerButtonEvent(bool down, const base::TimeTicks& timestamp); |
| 69 | 75 |
| 76 // Emulates the changes in various power settings. | |
| 77 void UpdateBatteryPercentage(int percentage); | |
| 78 void UpdateBatteryFullTimeToEmpty(int time_in_hours); | |
| 79 void UpdateExternalPower(int external_power); | |
| 80 void UpdateIsBatteryCharging(bool is_charging); | |
| 81 void UpdateIsCalculatingBatteryTime(bool is_calculating); | |
| 82 | |
| 83 // Called once any power states are changed to notify the observer of the | |
| 84 // change. | |
| 85 void UpdatePowerStatus(); | |
| 86 | |
| 70 private: | 87 private: |
| 71 // Callback that will be run by asynchronous suspend delays to report | 88 // Callback that will be run by asynchronous suspend delays to report |
| 72 // readiness. | 89 // readiness. |
| 73 void HandleSuspendReadiness(); | 90 void HandleSuspendReadiness(); |
| 74 | 91 |
| 92 void ParseCommandLineSwitch(); | |
| 93 | |
| 94 void ParseOption(const std::string& arg0, const std::string& arg1); | |
| 95 | |
| 75 base::ObserverList<Observer> observers_; | 96 base::ObserverList<Observer> observers_; |
| 76 | 97 |
| 77 // Last policy passed to SetPolicy(). | 98 // Last policy passed to SetPolicy(). |
| 78 power_manager::PowerManagementPolicy policy_; | 99 power_manager::PowerManagementPolicy policy_; |
| 79 | 100 |
| 101 // The power properties set for for the UI. | |
| 102 power_manager::PowerSupplyProperties props_; | |
| 103 | |
| 104 // Variables that handle states of the battery and power. | |
| 105 bool is_charging_; | |
| 106 bool is_calculating_; | |
| 107 int battery_percentage_; | |
| 108 int power_source_; | |
| 109 int hours_to_empty_full_battery = 4 * 60 * 60; // 4 hours. default value. | |
|
stevenjb
2015/06/25 17:03:47
We should use inline initialization for all of the
| |
| 110 | |
| 80 // Number of times that various methods have been called. | 111 // Number of times that various methods have been called. |
| 81 int num_request_restart_calls_; | 112 int num_request_restart_calls_; |
| 82 int num_request_shutdown_calls_; | 113 int num_request_shutdown_calls_; |
| 83 int num_set_policy_calls_; | 114 int num_set_policy_calls_; |
| 84 int num_set_is_projecting_calls_; | 115 int num_set_is_projecting_calls_; |
| 85 | 116 |
| 86 // Number of pending suspend readiness callbacks. | 117 // Number of pending suspend readiness callbacks. |
| 87 int num_pending_suspend_readiness_callbacks_; | 118 int num_pending_suspend_readiness_callbacks_; |
| 88 | 119 |
| 89 // Last projecting state set in SetIsProjecting(). | 120 // Last projecting state set in SetIsProjecting(). |
| 90 bool is_projecting_; | 121 bool is_projecting_; |
| 91 | 122 |
| 92 // Delegate for managing power consumption of Chrome's renderer processes. | 123 // Delegate for managing power consumption of Chrome's renderer processes. |
| 93 base::WeakPtr<RenderProcessManagerDelegate> render_process_manager_delegate_; | 124 base::WeakPtr<RenderProcessManagerDelegate> render_process_manager_delegate_; |
| 94 | 125 |
| 126 // Note: This should remain the last member so it'll be destroyed and | |
| 127 // invalidate its weak pointers before any other members are destroyed. | |
| 128 base::WeakPtrFactory<FakePowerManagerClient> weak_ptr_factory_; | |
| 129 | |
| 95 DISALLOW_COPY_AND_ASSIGN(FakePowerManagerClient); | 130 DISALLOW_COPY_AND_ASSIGN(FakePowerManagerClient); |
| 96 }; | 131 }; |
| 97 | 132 |
| 98 } // namespace chromeos | 133 } // namespace chromeos |
| 99 | 134 |
| 100 #endif // CHROMEOS_DBUS_FAKE_POWER_MANAGER_CLIENT_H_ | 135 #endif // CHROMEOS_DBUS_FAKE_POWER_MANAGER_CLIENT_H_ |
| OLD | NEW |