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

Side by Side Diff: content/browser/power_save_blocker.h

Issue 10542089: Power save blocker: switch to new implementation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 6 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 CONTENT_BROWSER_POWER_SAVE_BLOCKER_H_ 5 #ifndef CONTENT_BROWSER_POWER_SAVE_BLOCKER_H_
6 #define CONTENT_BROWSER_POWER_SAVE_BLOCKER_H_ 6 #define CONTENT_BROWSER_POWER_SAVE_BLOCKER_H_
7 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "content/common/content_export.h" 14 #include "content/common/content_export.h"
15 15
16 namespace content {
17
16 // A RAII-style class to block the system from entering low-power (sleep) mode. 18 // A RAII-style class to block the system from entering low-power (sleep) mode.
19 // This class is thread-safe; it may be constructed and deleted on any thread.
17 class CONTENT_EXPORT PowerSaveBlocker { 20 class CONTENT_EXPORT PowerSaveBlocker {
18 public: 21 public:
19 enum PowerSaveBlockerType { 22 enum PowerSaveBlockerType {
20 kPowerSaveBlockPreventNone = -1,
21
22 // Prevent the system from going to sleep; allow display sleep.
23 kPowerSaveBlockPreventSystemSleep,
24
25 // Prevent the system or display from going to sleep.
26 kPowerSaveBlockPreventDisplaySleep,
27
28 // Count of the values; not valid as a parameter.
29 kPowerSaveBlockPreventStateCount
30 };
31
32 // Pass in the level of sleep prevention desired. kPowerSaveBlockPreventNone
33 // is not a valid option.
34 explicit PowerSaveBlocker(PowerSaveBlockerType type);
35 ~PowerSaveBlocker();
36
37 private:
38 // Platform-specific function called when enable state is changed.
39 // Guaranteed to be called only from the UI thread.
40 static void ApplyBlock(PowerSaveBlockerType type);
41
42 // Called only from UI thread.
43 static void AdjustBlockCount(const std::vector<int>& deltas);
44
45 // Invokes AdjustBlockCount on the UI thread.
46 static void PostAdjustBlockCount(const std::vector<int>& deltas);
47
48 // Returns the highest-severity block type in use.
49 static PowerSaveBlockerType HighestBlockType();
50
51 PowerSaveBlockerType type_;
52
53 static int blocker_count_[];
54
55 DISALLOW_COPY_AND_ASSIGN(PowerSaveBlocker);
56 };
57
58 namespace content {
59
60 // NOT READY YET. PowerSaveBlocker above is soon to be replaced by this class,
61 // but it's not done yet so client code should use the one above for now.
62 // A RAII-style class to block the system from entering low-power (sleep) mode.
63 // This class is thread-safe; it may be constructed and deleted on any thread.
64 class CONTENT_EXPORT PowerSaveBlocker2 {
65 public:
66 enum PowerSaveBlockerType {
67 // Prevent the application from being suspended. On some platforms, apps may 23 // Prevent the application from being suspended. On some platforms, apps may
68 // be suspended when they are not visible to the user. This type of block 24 // be suspended when they are not visible to the user. This type of block
69 // requests that the app continue to run in that case, and on all platforms 25 // requests that the app continue to run in that case, and on all platforms
70 // prevents the system from sleeping. 26 // prevents the system from sleeping.
71 // Example use cases: downloading a file, playing audio. 27 // Example use cases: downloading a file, playing audio.
72 kPowerSaveBlockPreventAppSuspension, 28 kPowerSaveBlockPreventAppSuspension,
73 29
74 // Prevent the display from going to sleep. This also has the side effect of 30 // Prevent the display from going to sleep. This also has the side effect of
75 // preventing the system from sleeping, but does not necessarily prevent the 31 // preventing the system from sleeping, but does not necessarily prevent the
76 // app from being suspended on some platforms if the user hides it. 32 // app from being suspended on some platforms if the user hides it.
77 // Example use case: playing video. 33 // Example use case: playing video.
78 kPowerSaveBlockPreventDisplaySleep, 34 kPowerSaveBlockPreventDisplaySleep,
79 }; 35 };
80 36
81 // Pass in the type of power save blocking desired. If multiple types of 37 // Pass in the type of power save blocking desired. If multiple types of
82 // blocking are desired, instantiate one PowerSaveBlocker for each type. 38 // blocking are desired, instantiate one PowerSaveBlocker for each type.
83 // |reason| may be provided to the underlying system APIs on some platforms. 39 // |reason| may be provided to the underlying system APIs on some platforms.
84 PowerSaveBlocker2(PowerSaveBlockerType type, const std::string& reason); 40 PowerSaveBlocker(PowerSaveBlockerType type, const std::string& reason);
85 ~PowerSaveBlocker2(); 41 ~PowerSaveBlocker();
86 42
87 private: 43 private:
88 class Delegate; 44 class Delegate;
89 45
90 // Implementations of this class may need a second object with different 46 // Implementations of this class may need a second object with different
91 // lifetime than the RAII container, or additional storage. This member is 47 // lifetime than the RAII container, or additional storage. This member is
92 // here for that purpose. If not used, just define the class as an empty 48 // here for that purpose. If not used, just define the class as an empty
93 // RefCounted (or RefCountedThreadSafe) like so to make it compile: 49 // RefCounted (or RefCountedThreadSafe) like so to make it compile:
94 // class PowerSaveBlocker2::Delegate 50 // class PowerSaveBlocker::Delegate
95 // : public base::RefCounted<PowerSaveBlocker2::Delegate> { 51 // : public base::RefCounted<PowerSaveBlocker::Delegate> {
96 // private: 52 // private:
97 // friend class base::RefCounted<Delegate>; 53 // friend class base::RefCounted<Delegate>;
98 // ~Delegate() {} 54 // ~Delegate() {}
99 // }; 55 // };
100 scoped_refptr<Delegate> delegate_; 56 scoped_refptr<Delegate> delegate_;
101 57
102 DISALLOW_COPY_AND_ASSIGN(PowerSaveBlocker2); 58 DISALLOW_COPY_AND_ASSIGN(PowerSaveBlocker);
103 }; 59 };
104 60
105 } // namespace content 61 } // namespace content
106 62
107 #endif // CONTENT_BROWSER_POWER_SAVE_BLOCKER_H_ 63 #endif // CONTENT_BROWSER_POWER_SAVE_BLOCKER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698