Home | History | Annotate | Download | only in dbus
      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.
      4 
      5 #ifndef CHROMEOS_DBUS_FAKE_POWER_MANAGER_CLIENT_H_
      6 #define CHROMEOS_DBUS_FAKE_POWER_MANAGER_CLIENT_H_
      7 
      8 #include <string>
      9 
     10 #include "base/basictypes.h"
     11 #include "base/macros.h"
     12 #include "base/observer_list.h"
     13 #include "chromeos/dbus/power_manager/policy.pb.h"
     14 #include "chromeos/dbus/power_manager/suspend.pb.h"
     15 #include "chromeos/dbus/power_manager_client.h"
     16 
     17 namespace chromeos {
     18 
     19 // 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
     21 // get_policy().
     22 class FakePowerManagerClient : public PowerManagerClient {
     23  public:
     24   FakePowerManagerClient();
     25   virtual ~FakePowerManagerClient();
     26 
     27   power_manager::PowerManagementPolicy& policy() { return policy_; }
     28   int num_request_restart_calls() const { return num_request_restart_calls_; }
     29   int num_request_shutdown_calls() const { return num_request_shutdown_calls_; }
     30   int num_set_policy_calls() const { return num_set_policy_calls_; }
     31   int num_set_is_projecting_calls() const {
     32     return num_set_is_projecting_calls_;
     33   }
     34   bool is_projecting() const { return is_projecting_; }
     35 
     36   // PowerManagerClient overrides
     37   virtual void Init(dbus::Bus* bus) OVERRIDE;
     38   virtual void AddObserver(Observer* observer) OVERRIDE;
     39   virtual void RemoveObserver(Observer* observer) OVERRIDE;
     40   virtual bool HasObserver(Observer* observer) OVERRIDE;
     41   virtual void DecreaseScreenBrightness(bool allow_off) OVERRIDE;
     42   virtual void IncreaseScreenBrightness() OVERRIDE;
     43   virtual void SetScreenBrightnessPercent(
     44       double percent, bool gradual) OVERRIDE;
     45   virtual void GetScreenBrightnessPercent(
     46       const GetScreenBrightnessPercentCallback& callback) OVERRIDE;
     47   virtual void DecreaseKeyboardBrightness() OVERRIDE;
     48   virtual void IncreaseKeyboardBrightness() OVERRIDE;
     49   virtual void RequestStatusUpdate() OVERRIDE;
     50   virtual void RequestSuspend() OVERRIDE;
     51   virtual void RequestRestart() OVERRIDE;
     52   virtual void RequestShutdown() OVERRIDE;
     53   virtual void NotifyUserActivity(
     54       power_manager::UserActivityType type) OVERRIDE;
     55   virtual void NotifyVideoActivity(bool is_fullscreen) OVERRIDE;
     56   virtual void SetPolicy(
     57       const power_manager::PowerManagementPolicy& policy) OVERRIDE;
     58   virtual void SetIsProjecting(bool is_projecting) OVERRIDE;
     59   virtual base::Closure GetSuspendReadinessCallback() OVERRIDE;
     60   virtual int GetNumPendingSuspendReadinessCallbacks() OVERRIDE;
     61 
     62   // Emulates the power manager announcing that the system is starting or
     63   // completing a suspend attempt.
     64   void SendSuspendImminent();
     65   void SendSuspendDone();
     66   void SendDarkSuspendImminent();
     67 
     68   // Notifies observers that the power button has been pressed or released.
     69   void SendPowerButtonEvent(bool down, const base::TimeTicks& timestamp);
     70 
     71  private:
     72   // Callback that will be run by asynchronous suspend delays to report
     73   // readiness.
     74   void HandleSuspendReadiness();
     75 
     76   ObserverList<Observer> observers_;
     77 
     78   // Last policy passed to SetPolicy().
     79   power_manager::PowerManagementPolicy policy_;
     80 
     81   // Number of times that various methods have been called.
     82   int num_request_restart_calls_;
     83   int num_request_shutdown_calls_;
     84   int num_set_policy_calls_;
     85   int num_set_is_projecting_calls_;
     86 
     87   // Number of pending suspend readiness callbacks.
     88   int num_pending_suspend_readiness_callbacks_;
     89 
     90   // Last projecting state set in SetIsProjecting().
     91   bool is_projecting_;
     92 
     93   DISALLOW_COPY_AND_ASSIGN(FakePowerManagerClient);
     94 };
     95 
     96 }  // namespace chromeos
     97 
     98 #endif  // CHROMEOS_DBUS_FAKE_POWER_MANAGER_CLIENT_H_
     99