power_library.h revision 731df977c0511bca2206b5f333555b1205ff1f43
1// Copyright (c) 2009 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 CHROME_BROWSER_CHROMEOS_CROS_POWER_LIBRARY_H_
6#define CHROME_BROWSER_CHROMEOS_CROS_POWER_LIBRARY_H_
7#pragma once
8
9#include "base/observer_list.h"
10#include "base/singleton.h"
11#include "base/time.h"
12#include "cros/chromeos_power.h"
13
14namespace chromeos {
15
16// This interface defines interaction with the ChromeOS power library APIs.
17// Classes can add themselves as observers. Users can get an instance of this
18// library class like this: chromeos::CrosLibrary::Get()->GetPowerLibrary()
19class PowerLibrary {
20 public:
21  class Observer {
22   public:
23    virtual void PowerChanged(PowerLibrary* obj) = 0;
24  };
25  virtual ~PowerLibrary() {}
26  virtual void AddObserver(Observer* observer) = 0;
27  virtual void RemoveObserver(Observer* observer) = 0;
28  // Whether or not the line power is connected.
29  virtual bool line_power_on() const = 0;
30
31  // Whether or not the battery is fully charged..
32  virtual bool battery_fully_charged() const = 0;
33
34  // The percentage (0-100) of remaining battery.
35  virtual double battery_percentage() const = 0;
36
37  // Whether there is a battery present.
38  virtual bool battery_is_present() const = 0;
39
40  // The amount of time until battery is empty.
41  virtual base::TimeDelta battery_time_to_empty() const = 0;
42
43  // The amount of time until battery is full.
44  virtual base::TimeDelta battery_time_to_full() const = 0;
45
46  // Enable/disable screen lock for current session.
47  virtual void EnableScreenLock(bool enable) = 0;
48
49  // Requests restart of the system.
50  virtual void RequestRestart() = 0;
51
52  // Requests shutdown of the system.
53  virtual void RequestShutdown() = 0;
54
55  // Factory function, creates a new instance and returns ownership.
56  // For normal usage, access the singleton via CrosLibrary::Get().
57  static PowerLibrary* GetImpl(bool stub);
58};
59
60}  // namespace chromeos
61
62#endif  // CHROME_BROWSER_CHROMEOS_CROS_POWER_LIBRARY_H_
63