Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / chromeos / dbus / fake_power_manager_client.h
blobb6b28691f80de0bfdb2d78f73bad2129354c2ca3
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
3 // found in the LICENSE file.
5 #ifndef CHROMEOS_DBUS_FAKE_POWER_MANAGER_CLIENT_H_
6 #define CHROMEOS_DBUS_FAKE_POWER_MANAGER_CLIENT_H_
8 #include <string>
10 #include "base/basictypes.h"
11 #include "base/macros.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/observer_list.h"
14 #include "chromeos/chromeos_export.h"
15 #include "chromeos/dbus/power_manager/policy.pb.h"
16 #include "chromeos/dbus/power_manager/power_supply_properties.pb.h"
17 #include "chromeos/dbus/power_manager/suspend.pb.h"
18 #include "chromeos/dbus/power_manager_client.h"
20 namespace chromeos {
22 // A fake implementation of PowerManagerClient. This remembers the policy passed
23 // to SetPolicy() and the user of this class can inspect the last set policy by
24 // get_policy().
25 class CHROMEOS_EXPORT FakePowerManagerClient : public PowerManagerClient {
26 public:
27 FakePowerManagerClient();
28 ~FakePowerManagerClient() override;
30 power_manager::PowerManagementPolicy& policy() { return policy_; }
31 const power_manager::PowerSupplyProperties& props() const { return props_; }
32 int num_request_restart_calls() const { return num_request_restart_calls_; }
33 int num_request_shutdown_calls() const { return num_request_shutdown_calls_; }
34 int num_set_policy_calls() const { return num_set_policy_calls_; }
35 int num_set_is_projecting_calls() const {
36 return num_set_is_projecting_calls_;
38 bool is_projecting() const { return is_projecting_; }
40 // PowerManagerClient overrides
41 void Init(dbus::Bus* bus) override;
42 void AddObserver(Observer* observer) override;
43 void RemoveObserver(Observer* observer) override;
44 bool HasObserver(const Observer* observer) const override;
45 void SetRenderProcessManagerDelegate(
46 base::WeakPtr<RenderProcessManagerDelegate> delegate) override;
47 void DecreaseScreenBrightness(bool allow_off) override;
48 void IncreaseScreenBrightness() override;
49 void SetScreenBrightnessPercent(double percent, bool gradual) override;
50 void GetScreenBrightnessPercent(
51 const GetScreenBrightnessPercentCallback& callback) override;
52 void DecreaseKeyboardBrightness() override;
53 void IncreaseKeyboardBrightness() override;
54 void RequestStatusUpdate() override;
55 void RequestSuspend() override;
56 void RequestRestart() override;
57 void RequestShutdown() override;
58 void NotifyUserActivity(power_manager::UserActivityType type) override;
59 void NotifyVideoActivity(bool is_fullscreen) override;
60 void SetPolicy(const power_manager::PowerManagementPolicy& policy) override;
61 void SetIsProjecting(bool is_projecting) override;
62 void SetPowerSource(const std::string& id) override;
63 base::Closure GetSuspendReadinessCallback() override;
64 int GetNumPendingSuspendReadinessCallbacks() override;
66 // Emulates the power manager announcing that the system is starting or
67 // completing a suspend attempt.
68 void SendSuspendImminent();
69 void SendSuspendDone();
70 void SendDarkSuspendImminent();
72 // Notifies observers that the power button has been pressed or released.
73 void SendPowerButtonEvent(bool down, const base::TimeTicks& timestamp);
75 // Updates |props_| and notifies observers of its changes.
76 void UpdatePowerProperties(
77 const power_manager::PowerSupplyProperties& power_props);
79 private:
80 // Callback that will be run by asynchronous suspend delays to report
81 // readiness.
82 void HandleSuspendReadiness();
84 // Notifies |observers_| that |props_| has been updated.
85 void NotifyObservers();
87 base::ObserverList<Observer> observers_;
89 // Last policy passed to SetPolicy().
90 power_manager::PowerManagementPolicy policy_;
92 // Power status received from the power manager.
93 power_manager::PowerSupplyProperties props_;
95 // Number of times that various methods have been called.
96 int num_request_restart_calls_;
97 int num_request_shutdown_calls_;
98 int num_set_policy_calls_;
99 int num_set_is_projecting_calls_;
101 // Number of pending suspend readiness callbacks.
102 int num_pending_suspend_readiness_callbacks_;
104 // Last projecting state set in SetIsProjecting().
105 bool is_projecting_;
107 // Delegate for managing power consumption of Chrome's renderer processes.
108 base::WeakPtr<RenderProcessManagerDelegate> render_process_manager_delegate_;
110 // Note: This should remain the last member so it'll be destroyed and
111 // invalidate its weak pointers before any other members are destroyed.
112 base::WeakPtrFactory<FakePowerManagerClient> weak_ptr_factory_;
114 DISALLOW_COPY_AND_ASSIGN(FakePowerManagerClient);
117 } // namespace chromeos
119 #endif // CHROMEOS_DBUS_FAKE_POWER_MANAGER_CLIENT_H_