OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CONTENT_BROWSER_POWER_SAVE_BLOCKER_H_ | |
6 #define CONTENT_BROWSER_POWER_SAVE_BLOCKER_H_ | |
7 | |
8 #include <string> | |
9 #include <vector> | |
10 | |
11 #include "base/basictypes.h" | |
12 #include "base/memory/ref_counted.h" | |
13 #include "content/common/content_export.h" | |
14 | |
15 namespace content { | |
16 | |
17 // 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. | |
19 class CONTENT_EXPORT PowerSaveBlocker { | |
20 public: | |
21 enum PowerSaveBlockerType { | |
22 // 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 | |
24 // requests that the app continue to run in that case, and on all platforms | |
25 // prevents the system from sleeping. | |
26 // Example use cases: downloading a file, playing audio. | |
27 kPowerSaveBlockPreventAppSuspension, | |
28 | |
29 // 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 | |
31 // app from being suspended on some platforms if the user hides it. | |
32 // Example use case: playing video. | |
33 kPowerSaveBlockPreventDisplaySleep, | |
34 }; | |
35 | |
36 // Pass in the type of power save blocking desired. If multiple types of | |
37 // blocking are desired, instantiate one PowerSaveBlocker for each type. | |
38 // |reason| may be provided to the underlying system APIs on some platforms. | |
39 PowerSaveBlocker(PowerSaveBlockerType type, const std::string& reason); | |
40 ~PowerSaveBlocker(); | |
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 }; | |
59 | |
60 } // namespace content | |
61 | |
62 #endif // CONTENT_BROWSER_POWER_SAVE_BLOCKER_H_ | |
OLD | NEW |