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_PUBLIC_BROWSER_POWER_SAVE_BLOCKER_H_ |
6 #define CONTENT_BROWSER_POWER_SAVE_BLOCKER_H_ | 6 #define CONTENT_PUBLIC_BROWSER_POWER_SAVE_BLOCKER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | |
10 | 9 |
11 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
12 #include "base/memory/ref_counted.h" | 11 #include "base/memory/scoped_ptr.h" |
13 #include "content/common/content_export.h" | 12 #include "content/common/content_export.h" |
14 | 13 |
15 namespace content { | 14 namespace content { |
16 | 15 |
17 // 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. |
18 // This class is thread-safe; it may be constructed and deleted on any thread. | 17 // This class is thread-safe; it may be constructed and deleted on any thread. |
19 class CONTENT_EXPORT PowerSaveBlocker { | 18 class CONTENT_EXPORT PowerSaveBlocker { |
20 public: | 19 public: |
21 enum PowerSaveBlockerType { | 20 enum PowerSaveBlockerType { |
22 // Prevent the application from being suspended. On some platforms, apps may | 21 // Prevent the application from being suspended. On some platforms, apps may |
23 // be suspended when they are not visible to the user. This type of block | 22 // be suspended when they are not visible to the user. This type of block |
24 // requests that the app continue to run in that case, and on all platforms | 23 // requests that the app continue to run in that case, and on all platforms |
25 // prevents the system from sleeping. | 24 // prevents the system from sleeping. |
26 // Example use cases: downloading a file, playing audio. | 25 // Example use cases: downloading a file, playing audio. |
27 kPowerSaveBlockPreventAppSuspension, | 26 kPowerSaveBlockPreventAppSuspension, |
28 | 27 |
29 // Prevent the display from going to sleep. This also has the side effect of | 28 // Prevent the display from going to sleep. This also has the side effect of |
30 // preventing the system from sleeping, but does not necessarily prevent the | 29 // preventing the system from sleeping, but does not necessarily prevent the |
31 // app from being suspended on some platforms if the user hides it. | 30 // app from being suspended on some platforms if the user hides it. |
32 // Example use case: playing video. | 31 // Example use case: playing video. |
33 kPowerSaveBlockPreventDisplaySleep, | 32 kPowerSaveBlockPreventDisplaySleep, |
34 }; | 33 }; |
35 | 34 |
| 35 virtual ~PowerSaveBlocker() = 0; |
| 36 |
36 // 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 |
37 // blocking are desired, instantiate one PowerSaveBlocker for each type. | 38 // blocking are desired, instantiate one PowerSaveBlocker for each type. |
38 // |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. |
39 PowerSaveBlocker(PowerSaveBlockerType type, const std::string& reason); | 40 static scoped_ptr<PowerSaveBlocker> Create(PowerSaveBlockerType type, |
40 ~PowerSaveBlocker(); | 41 const std::string& reason); |
41 | |
42 private: | |
43 class Delegate; | |
44 | |
45 // Implementations of this class may need a second object with different | |
46 // lifetime than the RAII container, or additional storage. This member is | |
47 // here for that purpose. If not used, just define the class as an empty | |
48 // RefCounted (or RefCountedThreadSafe) like so to make it compile: | |
49 // class PowerSaveBlocker::Delegate | |
50 // : public base::RefCounted<PowerSaveBlocker::Delegate> { | |
51 // private: | |
52 // friend class base::RefCounted<Delegate>; | |
53 // ~Delegate() {} | |
54 // }; | |
55 scoped_refptr<Delegate> delegate_; | |
56 | |
57 DISALLOW_COPY_AND_ASSIGN(PowerSaveBlocker); | |
58 }; | 42 }; |
59 | 43 |
60 } // namespace content | 44 } // namespace content |
61 | 45 |
62 #endif // CONTENT_BROWSER_POWER_SAVE_BLOCKER_H_ | 46 #endif // CONTENT_PUBLIC_BROWSER_POWER_SAVE_BLOCKER_H_ |
OLD | NEW |