Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(885)

Side by Side Diff: chrome/browser/chromeos/cros/power_library.h

Issue 1142005: Mocks for all libcros elements (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_CHROMEOS_CROS_POWER_LIBRARY_H_ 5 #ifndef CHROME_BROWSER_CHROMEOS_CROS_POWER_LIBRARY_H_
6 #define CHROME_BROWSER_CHROMEOS_CROS_POWER_LIBRARY_H_ 6 #define CHROME_BROWSER_CHROMEOS_CROS_POWER_LIBRARY_H_
7 7
8 #include "base/observer_list.h" 8 #include "base/observer_list.h"
9 #include "base/singleton.h" 9 #include "base/singleton.h"
10 #include "base/time.h" 10 #include "base/time.h"
11 #include "third_party/cros/chromeos_power.h" 11 #include "third_party/cros/chromeos_power.h"
12 12
13 namespace chromeos { 13 namespace chromeos {
14 14
15 // This class handles the interaction with the ChromeOS power library APIs. 15 // This interface defines interaction with the ChromeOS power library APIs.
16 // Classes can add themselves as observers. Users can get an instance of this 16 // Classes can add themselves as observers. Users can get an instance of this
17 // library class like this: PowerLibrary::Get() 17 // library class like this: PowerLibrary::Get()
18 class PowerLibrary { 18 class PowerLibrary {
19 public: 19 public:
20 class Observer { 20 class Observer {
21 public: 21 public:
22 virtual void PowerChanged(PowerLibrary* obj) = 0; 22 virtual void PowerChanged(PowerLibrary* obj) = 0;
23 }; 23 };
24 virtual ~PowerLibrary() {}
25 virtual void AddObserver(Observer* observer) = 0;
26 virtual void RemoveObserver(Observer* observer) = 0;
27 // Whether or not the line power is connected.
28 virtual bool line_power_on() const = 0;
24 29
25 // This gets the singleton PowerLibrary 30 // Whether or not the battery is fully charged..
26 static PowerLibrary* Get(); 31 virtual bool battery_fully_charged() const = 0;
27 32
28 void AddObserver(Observer* observer); 33 // The percentage (0-100) of remaining battery.
29 void RemoveObserver(Observer* observer); 34 virtual double battery_percentage() const = 0;
35
36 // Whether there is a battery present.
37 virtual bool battery_is_present() const = 0;
38
39 // The amount of time until battery is empty.
40 virtual base::TimeDelta battery_time_to_empty() const = 0;
41
42 // The amount of time until battery is full.
43 virtual base::TimeDelta battery_time_to_full() const = 0;
44 };
45
46
47 // This class handles the interaction with the ChromeOS power library APIs.
48 // Classes can add themselves as observers. Users can get an instance of this
49 // library class like this: PowerLibrary::Get()
50 class PowerLibraryImpl : public PowerLibrary {
51 public:
52 PowerLibraryImpl();
53 virtual ~PowerLibraryImpl();
54
55 // PowerLibrary overrides.
56 virtual void AddObserver(Observer* observer);
57 virtual void RemoveObserver(Observer* observer);
30 58
31 // Whether or not the line power is connected. 59 // Whether or not the line power is connected.
32 bool line_power_on() const; 60 virtual bool line_power_on() const;
33 61
34 // Whether or not the battery is fully charged.. 62 // Whether or not the battery is fully charged..
35 bool battery_fully_charged() const; 63 virtual bool battery_fully_charged() const;
36 64
37 // The percentage (0-100) of remaining battery. 65 // The percentage (0-100) of remaining battery.
38 double battery_percentage() const; 66 virtual double battery_percentage() const;
39 67
40 // Whether there is a battery present. 68 // Whether there is a battery present.
41 bool battery_is_present() const; 69 virtual bool battery_is_present() const;
42 70
43 // The amount of time until battery is empty. 71 // The amount of time until battery is empty.
44 base::TimeDelta battery_time_to_empty() const; 72 virtual base::TimeDelta battery_time_to_empty() const;
45 73
46 // The amount of time until battery is full. 74 // The amount of time until battery is full.
47 base::TimeDelta battery_time_to_full() const; 75 virtual base::TimeDelta battery_time_to_full() const;
48 76
49 private: 77 private:
50 friend struct DefaultSingletonTraits<PowerLibrary>;
51
52 PowerLibrary();
53 ~PowerLibrary();
54 78
55 // This method is called when there's a change in power status. 79 // This method is called when there's a change in power status.
56 // This method is called on a background thread. 80 // This method is called on a background thread.
57 static void PowerStatusChangedHandler(void* object, 81 static void PowerStatusChangedHandler(void* object,
58 const chromeos::PowerStatus& status); 82 const chromeos::PowerStatus& status);
59 83
60 // This methods starts the monitoring of power changes. 84 // This methods starts the monitoring of power changes.
61 void Init(); 85 void Init();
62 86
63 // Called by the handler to update the power status. 87 // Called by the handler to update the power status.
64 // This will notify all the Observers. 88 // This will notify all the Observers.
65 void UpdatePowerStatus(const chromeos::PowerStatus& status); 89 void UpdatePowerStatus(const chromeos::PowerStatus& status);
66 90
67 ObserverList<Observer> observers_; 91 ObserverList<Observer> observers_;
68 92
69 // A reference to the battery power api, to allow callbacks when the battery 93 // A reference to the battery power api, to allow callbacks when the battery
70 // status changes. 94 // status changes.
71 chromeos::PowerStatusConnection power_status_connection_; 95 chromeos::PowerStatusConnection power_status_connection_;
72 96
73 // The latest power status. 97 // The latest power status.
74 chromeos::PowerStatus status_; 98 chromeos::PowerStatus status_;
75 99
76 DISALLOW_COPY_AND_ASSIGN(PowerLibrary); 100 DISALLOW_COPY_AND_ASSIGN(PowerLibraryImpl);
77 }; 101 };
78 102
79 } // namespace chromeos 103 } // namespace chromeos
80 104
81 #endif // CHROME_BROWSER_CHROMEOS_CROS_POWER_LIBRARY_H_ 105 #endif // CHROME_BROWSER_CHROMEOS_CROS_POWER_LIBRARY_H_
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/cros/network_library.cc ('k') | chrome/browser/chromeos/cros/power_library.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698