Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(441)

Side by Side Diff: chromeos/dbus/fake_power_manager_client.h

Issue 1206733002: ChromeOs Power Emulation Impl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Making a better battery emu! Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/scoped_ptr.h"
Daniel Erat 2015/07/15 22:39:05 oshima mentioned this before, and you said that it
mozartalouis 2015/07/15 22:55:43 I had just taken a quick look at the previous impl
12 #include "base/observer_list.h" 13 #include "base/observer_list.h"
14 #include "chromeos/chromeos_export.h"
13 #include "chromeos/dbus/power_manager/policy.pb.h" 15 #include "chromeos/dbus/power_manager/policy.pb.h"
16 #include "chromeos/dbus/power_manager/power_supply_properties.pb.h"
14 #include "chromeos/dbus/power_manager/suspend.pb.h" 17 #include "chromeos/dbus/power_manager/suspend.pb.h"
15 #include "chromeos/dbus/power_manager_client.h" 18 #include "chromeos/dbus/power_manager_client.h"
16 19
17 namespace chromeos { 20 namespace chromeos {
18 21
19 // A fake implementation of PowerManagerClient. This remembers the policy passed 22 // 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 23 // to SetPolicy() and the user of this class can inspect the last set policy by
21 // get_policy(). 24 // get_policy().
22 class FakePowerManagerClient : public PowerManagerClient { 25 class CHROMEOS_EXPORT FakePowerManagerClient : public PowerManagerClient {
23 public: 26 public:
24 FakePowerManagerClient(); 27 FakePowerManagerClient();
25 ~FakePowerManagerClient() override; 28 ~FakePowerManagerClient() override;
26 29
27 power_manager::PowerManagementPolicy& policy() { return policy_; } 30 power_manager::PowerManagementPolicy& policy() { return policy_; }
31 const power_manager::PowerSupplyProperties& props() const { return props_; }
28 int num_request_restart_calls() const { return num_request_restart_calls_; } 32 int num_request_restart_calls() const { return num_request_restart_calls_; }
29 int num_request_shutdown_calls() const { return num_request_shutdown_calls_; } 33 int num_request_shutdown_calls() const { return num_request_shutdown_calls_; }
30 int num_set_policy_calls() const { return num_set_policy_calls_; } 34 int num_set_policy_calls() const { return num_set_policy_calls_; }
31 int num_set_is_projecting_calls() const { 35 int num_set_is_projecting_calls() const {
32 return num_set_is_projecting_calls_; 36 return num_set_is_projecting_calls_;
33 } 37 }
34 bool is_projecting() const { return is_projecting_; } 38 bool is_projecting() const { return is_projecting_; }
35 39
36 // PowerManagerClient overrides 40 // PowerManagerClient overrides
37 void Init(dbus::Bus* bus) override; 41 void Init(dbus::Bus* bus) override;
(...skipping 22 matching lines...) Expand all
60 64
61 // Emulates the power manager announcing that the system is starting or 65 // Emulates the power manager announcing that the system is starting or
62 // completing a suspend attempt. 66 // completing a suspend attempt.
63 void SendSuspendImminent(); 67 void SendSuspendImminent();
64 void SendSuspendDone(); 68 void SendSuspendDone();
65 void SendDarkSuspendImminent(); 69 void SendDarkSuspendImminent();
66 70
67 // Notifies observers that the power button has been pressed or released. 71 // Notifies observers that the power button has been pressed or released.
68 void SendPowerButtonEvent(bool down, const base::TimeTicks& timestamp); 72 void SendPowerButtonEvent(bool down, const base::TimeTicks& timestamp);
69 73
74 // Updates |props_| and notifies observers of its changes.
75 void UpdatePowerProperties(
76 const power_manager::PowerSupplyProperties& power_props);
77
70 private: 78 private:
71 // Callback that will be run by asynchronous suspend delays to report 79 // Callback that will be run by asynchronous suspend delays to report
72 // readiness. 80 // readiness.
73 void HandleSuspendReadiness(); 81 void HandleSuspendReadiness();
74 82
83 // Notifies |observers_| that |props_| has been updated.
84 void NotifyObservers();
85
75 base::ObserverList<Observer> observers_; 86 base::ObserverList<Observer> observers_;
76 87
77 // Last policy passed to SetPolicy(). 88 // Last policy passed to SetPolicy().
78 power_manager::PowerManagementPolicy policy_; 89 power_manager::PowerManagementPolicy policy_;
79 90
91 // Power status received from the power manager.
92 power_manager::PowerSupplyProperties props_;
93
80 // Number of times that various methods have been called. 94 // Number of times that various methods have been called.
81 int num_request_restart_calls_; 95 int num_request_restart_calls_;
82 int num_request_shutdown_calls_; 96 int num_request_shutdown_calls_;
83 int num_set_policy_calls_; 97 int num_set_policy_calls_;
84 int num_set_is_projecting_calls_; 98 int num_set_is_projecting_calls_;
85 99
86 // Number of pending suspend readiness callbacks. 100 // Number of pending suspend readiness callbacks.
87 int num_pending_suspend_readiness_callbacks_; 101 int num_pending_suspend_readiness_callbacks_;
88 102
89 // Last projecting state set in SetIsProjecting(). 103 // Last projecting state set in SetIsProjecting().
90 bool is_projecting_; 104 bool is_projecting_;
91 105
92 // Delegate for managing power consumption of Chrome's renderer processes. 106 // Delegate for managing power consumption of Chrome's renderer processes.
93 base::WeakPtr<RenderProcessManagerDelegate> render_process_manager_delegate_; 107 base::WeakPtr<RenderProcessManagerDelegate> render_process_manager_delegate_;
94 108
109 // Note: This should remain the last member so it'll be destroyed and
110 // invalidate its weak pointers before any other members are destroyed.
111 base::WeakPtrFactory<FakePowerManagerClient> weak_ptr_factory_;
112
95 DISALLOW_COPY_AND_ASSIGN(FakePowerManagerClient); 113 DISALLOW_COPY_AND_ASSIGN(FakePowerManagerClient);
96 }; 114 };
97 115
98 } // namespace chromeos 116 } // namespace chromeos
99 117
100 #endif // CHROMEOS_DBUS_FAKE_POWER_MANAGER_CLIENT_H_ 118 #endif // CHROMEOS_DBUS_FAKE_POWER_MANAGER_CLIENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698