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

Side by Side Diff: base/power_monitor/power_monitor_source.h

Issue 17074009: Created multi-process-friendly PowerMonitor interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed message export for unit tests Created 7 years, 5 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
(Empty)
1 // Copyright 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 BASE_POWER_MONITOR_POWER_MONITOR_SOURCE_H_
6 #define BASE_POWER_MONITOR_POWER_MONITOR_SOURCE_H_
7
8 #include "base/base_export.h"
9 #include "base/basictypes.h"
10 #include "base/memory/ref_counted.h"
11 #include "base/observer_list_threadsafe.h"
12 #include "base/synchronization/lock.h"
13
14 namespace base {
15
16 class PowerMonitor;
17
18 // Communicates power state changes to the power monitor.
19 class BASE_EXPORT PowerMonitorSource {
20 public:
21 PowerMonitorSource();
22 virtual ~PowerMonitorSource();
23
24 // Normalized list of power events.
25 enum PowerEvent {
26 POWER_STATE_EVENT, // The Power status of the system has changed.
27 SUSPEND_EVENT, // The system is being suspended.
28 RESUME_EVENT // The system is being resumed.
29 };
30
31 // Is the computer currently on battery power. Can be called on any thread.
32 bool IsOnBatteryPower();
33
34 protected:
35 friend class PowerMonitorTest;
36
37 // Friend function that is allowed to access the protected ProcessPowerEvent.
38 friend void ProcessPowerEventHelper(PowerEvent);
39
40 // Get the process-wide PowerMonitorSource (if not present, returns NULL).
41 static PowerMonitorSource* Get();
42
43 static void ProcessPowerEvent(PowerEvent event_id);
44
45 // Updates the cached battery power state. Returns true if state has changed.
46 bool UpdateOnBatteryPower();
47
48 // Platform-specific method to check whether the system is currently
49 // running on battery power. Returns true if running on batteries,
50 // false otherwise.
51 virtual bool IsOnBatteryPowerImpl() = 0;
52
53 private:
54 bool on_battery_power_;
55 bool suspended_;
56 Lock lock_;
piman 2013/07/12 21:09:58 What does the lock protect? Can you document that?
bajones 2013/07/13 00:33:20 IsOnBatteryPowerImpl is now called outside of the
piman 2013/07/15 20:51:30 ping.
57
58 DISALLOW_COPY_AND_ASSIGN(PowerMonitorSource);
59 };
60
61 } // namespace base
62
63 #endif // BASE_POWER_MONITOR_POWER_MONITOR_SOURCE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698