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

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

Issue 226263008: Revert of Attempting to resolve a race condition with PowerMonitor (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 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
« no previous file with comments | « no previous file | base/power_monitor/power_monitor.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 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 BASE_POWER_MONITOR_POWER_MONITOR_H_ 5 #ifndef BASE_POWER_MONITOR_POWER_MONITOR_H_
6 #define BASE_POWER_MONITOR_POWER_MONITOR_H_ 6 #define BASE_POWER_MONITOR_POWER_MONITOR_H_
7 7
8 #include "base/base_export.h" 8 #include "base/base_export.h"
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
11 #include "base/observer_list_threadsafe.h" 11 #include "base/observer_list_threadsafe.h"
12 #include "base/power_monitor/power_observer.h" 12 #include "base/power_monitor/power_observer.h"
13 #include "base/synchronization/lock.h"
14 13
15 namespace base { 14 namespace base {
16 15
17 class PowerMonitorSource; 16 class PowerMonitorSource;
18 17
19 // A class used to monitor the power state change and notify the observers about 18 // A class used to monitor the power state change and notify the observers about
20 // the change event. 19 // the change event.
21 class BASE_EXPORT PowerMonitor { 20 class BASE_EXPORT PowerMonitor {
22 public: 21 public:
23 // Takes ownership of |source|. 22 // Takes ownership of |source|.
24 static void Initialize(scoped_ptr<PowerMonitorSource> source); 23 explicit PowerMonitor(scoped_ptr<PowerMonitorSource> source);
25 static void ShutdownForTesting(); 24 ~PowerMonitor();
26 25
27 // Has the PowerMonitor already been initialized? 26 // Get the process-wide PowerMonitor (if not present, returns NULL).
28 static bool IsInitialized(); 27 static PowerMonitor* Get();
29 28
30 // Add and remove an observer. 29 // Add and remove an observer.
31 // Can be called from any thread. 30 // Can be called from any thread.
32 // Must not be called from within a notification callback. 31 // Must not be called from within a notification callback.
33 static bool AddObserver(PowerObserver* observer); 32 void AddObserver(PowerObserver* observer);
34 static bool RemoveObserver(PowerObserver* observer); 33 void RemoveObserver(PowerObserver* observer);
35 34
36 // Is the computer currently on battery power. 35 // Is the computer currently on battery power.
37 static bool IsOnBatteryPower(); 36 bool IsOnBatteryPower();
38 37
39 private: 38 private:
40 friend class PowerMonitorSource; 39 friend class PowerMonitorSource;
41 40
42 static Lock* GetLock(); 41 PowerMonitorSource* Source();
43 // Must manually acquire lock before calling any of the following functions. 42
44 static bool IsInitializedLocked(); 43 void NotifyPowerStateChange(bool battery_in_use);
45 static PowerMonitorSource* GetSource(); 44 void NotifySuspend();
46 static void NotifyPowerStateChange(bool battery_in_use); 45 void NotifyResume();
47 static void NotifySuspend(); 46
48 static void NotifyResume(); 47 scoped_refptr<ObserverListThreadSafe<PowerObserver> > observers_;
48 scoped_ptr<PowerMonitorSource> source_;
49 49
50 DISALLOW_COPY_AND_ASSIGN(PowerMonitor); 50 DISALLOW_COPY_AND_ASSIGN(PowerMonitor);
51 }; 51 };
52 52
53 } // namespace base 53 } // namespace base
54 54
55 #endif // BASE_POWER_MONITOR_POWER_MONITOR_H_ 55 #endif // BASE_POWER_MONITOR_POWER_MONITOR_H_
OLDNEW
« no previous file with comments | « no previous file | base/power_monitor/power_monitor.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698