OLD | NEW |
---|---|
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 <vector> | 10 #include <vector> |
10 | 11 |
11 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/memory/ref_counted.h" | |
12 #include "content/common/content_export.h" | 14 #include "content/common/content_export.h" |
13 | 15 |
14 // A RAII-style class to block the system from entering low-power (sleep) mode. | 16 // A RAII-style class to block the system from entering low-power (sleep) mode. |
15 class CONTENT_EXPORT PowerSaveBlocker { | 17 class CONTENT_EXPORT PowerSaveBlocker { |
16 public: | 18 public: |
17 enum PowerSaveBlockerType { | 19 enum PowerSaveBlockerType { |
18 kPowerSaveBlockPreventNone = -1, | 20 kPowerSaveBlockPreventNone = -1, |
19 | 21 |
20 // Prevent the system from going to sleep; allow display sleep. | 22 // Prevent the system from going to sleep; allow display sleep. |
21 kPowerSaveBlockPreventSystemSleep, | 23 kPowerSaveBlockPreventSystemSleep, |
(...skipping 24 matching lines...) Expand all Loading... | |
46 // Returns the highest-severity block type in use. | 48 // Returns the highest-severity block type in use. |
47 static PowerSaveBlockerType HighestBlockType(); | 49 static PowerSaveBlockerType HighestBlockType(); |
48 | 50 |
49 PowerSaveBlockerType type_; | 51 PowerSaveBlockerType type_; |
50 | 52 |
51 static int blocker_count_[]; | 53 static int blocker_count_[]; |
52 | 54 |
53 DISALLOW_COPY_AND_ASSIGN(PowerSaveBlocker); | 55 DISALLOW_COPY_AND_ASSIGN(PowerSaveBlocker); |
54 }; | 56 }; |
55 | 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 class CONTENT_EXPORT PowerSaveBlocker2 { | |
64 public: | |
65 enum PowerSaveBlockerType { | |
66 // Prevent the application from being suspended. On some platforms, apps may | |
67 // be suspended when they are not visible to the user. This type of block | |
68 // requests that the app continue to run in that case, and on all platforms | |
69 // prevents the system from sleeping. | |
70 // Example use cases: downloading a file, playing audio. | |
71 kPowerSaveBlockPreventAppSuspension, | |
72 | |
73 // Prevent the display from going to sleep. This also has the side effect of | |
74 // preventing the system from sleeping, but does not necessarily prevent the | |
75 // app from being suspended on some platforms if the user hides it. | |
76 // Example use case: playing video. | |
77 kPowerSaveBlockPreventDisplaySleep, | |
78 }; | |
79 | |
80 // Pass in the type of power save blocking desired. If multiple types of | |
81 // blocking are desired, instantiate one PowerSaveBlocker for each type. | |
82 // |reason| may be provided to the underlying system APIs on some platforms. | |
83 PowerSaveBlocker2(PowerSaveBlockerType type, const std::string& reason); | |
84 ~PowerSaveBlocker2(); | |
85 | |
86 private: | |
87 class Delegate; | |
88 | |
89 // Implementations of this class may need a second object with different | |
90 // lifetime than the RAII container, or additional storage. This member is | |
91 // here for that purpose. If not used, just define the class as an empty | |
92 // RefCounted like so to make it compile: | |
93 // class PowerSaveBlocker2::Delegate | |
94 // : public RefCounted<PowerSaveBlocker2::Delegate> { | |
95 // }; | |
96 scoped_refptr<Delegate> delegate; | |
rvargas (doing something else)
2012/06/05 00:48:50
nit: this should be delegate_
Mike Mammarella
2012/06/05 01:02:13
Ah yes, so it should. I'll wait for the bots to fi
| |
97 | |
98 DISALLOW_COPY_AND_ASSIGN(PowerSaveBlocker2); | |
99 }; | |
100 | |
101 } // namespace content | |
102 | |
56 #endif // CONTENT_BROWSER_POWER_SAVE_BLOCKER_H_ | 103 #endif // CONTENT_BROWSER_POWER_SAVE_BLOCKER_H_ |
OLD | NEW |