Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chromeos / dbus / fake_power_manager_client.h
blob2b8883330fefedc14d4b34a8f602d8a20a47ab3f
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 base::Closure GetSuspendReadinessCallback() override;
63 int GetNumPendingSuspendReadinessCallbacks() override;
65 // Emulates the power manager announcing that the system is starting or
66 // completing a suspend attempt.
67 void SendSuspendImminent();
68 void SendSuspendDone();
69 void SendDarkSuspendImminent();
71 // Notifies observers that the power button has been pressed or released.
72 void SendPowerButtonEvent(bool down, const base::TimeTicks& timestamp);
74 // Updates |props_| and notifies observers of its changes.
75 void UpdatePowerProperties(
76 const power_manager::PowerSupplyProperties& power_props);
78 private:
79 // Callback that will be run by asynchronous suspend delays to report
80 // readiness.
81 void HandleSuspendReadiness();
83 // Notifies |observers_| that |props_| has been updated.
84 void NotifyObservers();
86 base::ObserverList<Observer> observers_;
88 // Last policy passed to SetPolicy().
89 power_manager::PowerManagementPolicy policy_;
91 // Power status received from the power manager.
92 power_manager::PowerSupplyProperties props_;
94 // Number of times that various methods have been called.
95 int num_request_restart_calls_;
96 int num_request_shutdown_calls_;
97 int num_set_policy_calls_;
98 int num_set_is_projecting_calls_;
100 // Number of pending suspend readiness callbacks.
101 int num_pending_suspend_readiness_callbacks_;
103 // Last projecting state set in SetIsProjecting().
104 bool is_projecting_;
106 // Delegate for managing power consumption of Chrome's renderer processes.
107 base::WeakPtr<RenderProcessManagerDelegate> render_process_manager_delegate_;
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_;
113 DISALLOW_COPY_AND_ASSIGN(FakePowerManagerClient);
116 } // namespace chromeos
118 #endif // CHROMEOS_DBUS_FAKE_POWER_MANAGER_CLIENT_H_