OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <vector> | |
10 | |
9 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
10 | 12 |
11 // A RAII-style class to block the system from entering low-power (sleep) mode. | 13 // A RAII-style class to block the system from entering low-power (sleep) mode. |
12 class PowerSaveBlocker { | 14 class PowerSaveBlocker { |
13 public: | 15 public: |
14 explicit PowerSaveBlocker(bool enabled); | 16 enum PowerSaveBlockerType { |
17 kPowerSaveBlockPreventNone = -1, | |
18 | |
19 // Prevent the system from going to sleep; allow display sleep. | |
20 kPowerSaveBlockPreventSystemSleep, | |
21 | |
22 // Prevent the system or display from going to sleep. | |
23 kPowerSaveBlockPreventDisplaySleep, | |
24 | |
25 kPowerSaveBlockPreventStateCount | |
Mark Mentovai
2011/10/13 04:29:18
Can you make this be a constant that’s not part of
| |
26 }; | |
27 | |
28 explicit PowerSaveBlocker(PowerSaveBlockerType type); | |
15 ~PowerSaveBlocker(); | 29 ~PowerSaveBlocker(); |
16 | 30 |
17 bool enabled() const { return enabled_; } | |
18 | |
19 // Puts the sleep mode block into effect. | |
20 void Enable(); | |
21 // Disables the sleep block. | |
22 void Disable(); | |
23 | |
24 private: | 31 private: |
25 // Platform-specific function called when enable state is changed. | 32 // Platform-specific function called when enable state is changed. |
26 // Guaranteed to be called only from the UI thread. | 33 // Guaranteed to be called only from the UI thread. |
27 static void ApplyBlock(bool blocked); | 34 static void ApplyBlock(PowerSaveBlockerType type); |
28 | 35 |
29 // Called only from UI thread. | 36 // Called only from UI thread. |
30 static void AdjustBlockCount(int delta); | 37 static void AdjustBlockCount(std::vector<int> deltas); |
jam
2011/10/13 16:40:29
const ref
Avi (use Gerrit)
2011/10/13 17:52:44
The reason I didn't was because I have a question.
jam
2011/10/13 18:38:35
yep it makes a copy
| |
31 | 38 |
32 // Invokes AdjustBlockCount on the UI thread. | 39 // Invokes AdjustBlockCount on the UI thread. |
33 static void PostAdjustBlockCount(int delta); | 40 static void PostAdjustBlockCount(const std::vector<int>& deltas); |
34 | 41 |
35 bool enabled_; | 42 // Returns the highest-severity block type in use. |
43 static PowerSaveBlockerType HighestBlockType(); | |
36 | 44 |
37 static int blocker_count_; | 45 PowerSaveBlockerType type_; |
46 | |
47 static int blocker_count_[]; | |
38 | 48 |
39 DISALLOW_COPY_AND_ASSIGN(PowerSaveBlocker); | 49 DISALLOW_COPY_AND_ASSIGN(PowerSaveBlocker); |
40 }; | 50 }; |
41 | 51 |
42 #endif // CONTENT_BROWSER_POWER_SAVE_BLOCKER_H_ | 52 #endif // CONTENT_BROWSER_POWER_SAVE_BLOCKER_H_ |
OLD | NEW |