power_library.h revision ddb351dbec246cf1fab5ec20d2d5520909041de1
1// Copyright (c) 2011 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/memory/singleton.h"
10#include "base/observer_list.h"
11#include "base/time.h"
12#include "third_party/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    virtual void SystemResumed() = 0;
25  };
26  virtual ~PowerLibrary() {}
27  virtual void AddObserver(Observer* observer) = 0;
28  virtual void RemoveObserver(Observer* observer) = 0;
29  // Whether or not the line power is connected.
30  virtual bool line_power_on() const = 0;
31
32  // Whether or not the battery is fully charged..
33  virtual bool battery_fully_charged() const = 0;
34
35  // The percentage (0-100) of remaining battery.
36  virtual double battery_percentage() const = 0;
37
38  // Whether there is a battery present.
39  virtual bool battery_is_present() const = 0;
40
41  // The amount of time until battery is empty.
42  virtual base::TimeDelta battery_time_to_empty() const = 0;
43
44  // The amount of time until battery is full.
45  virtual base::TimeDelta battery_time_to_full() const = 0;
46
47  // Enable/disable screen lock for current session.
48  virtual void EnableScreenLock(bool enable) = 0;
49
50  // Requests restart of the system.
51  virtual void RequestRestart() = 0;
52
53  // Requests shutdown of the system.
54  virtual void RequestShutdown() = 0;
55
56  // Factory function, creates a new instance and returns ownership.
57  // For normal usage, access the singleton via CrosLibrary::Get().
58  static PowerLibrary* GetImpl(bool stub);
59};
60
61}  // namespace chromeos
62
63#endif  // CHROME_BROWSER_CHROMEOS_CROS_POWER_LIBRARY_H_
64