| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_IMPL_H_ |
| 6 #define CONTENT_BROWSER_POWER_SAVE_BLOCKER_H_ | 6 #define CONTENT_BROWSER_POWER_SAVE_BLOCKER_IMPL_H_ |
| 7 | 7 |
| 8 #include <string> | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "base/basictypes.h" | |
| 12 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 13 #include "content/common/content_export.h" | 9 #include "content/public/browser/power_save_blocker.h" |
| 14 | 10 |
| 15 namespace content { | 11 namespace content { |
| 16 | 12 |
| 17 // A RAII-style class to block the system from entering low-power (sleep) mode. | 13 class PowerSaveBlockerImpl : public PowerSaveBlocker { |
| 18 // This class is thread-safe; it may be constructed and deleted on any thread. | |
| 19 class CONTENT_EXPORT PowerSaveBlocker { | |
| 20 public: | 14 public: |
| 21 enum PowerSaveBlockerType { | 15 PowerSaveBlockerImpl(PowerSaveBlockerType type, const std::string& reason); |
| 22 // Prevent the application from being suspended. On some platforms, apps may | 16 virtual ~PowerSaveBlockerImpl(); |
| 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 | 17 |
| 42 private: | 18 private: |
| 43 class Delegate; | 19 class Delegate; |
| 44 | 20 |
| 45 // Implementations of this class may need a second object with different | 21 // Implementations of this class may need a second object with different |
| 46 // lifetime than the RAII container, or additional storage. This member is | 22 // 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 | 23 // here for that purpose. If not used, just define the class as an empty |
| 48 // RefCounted (or RefCountedThreadSafe) like so to make it compile: | 24 // RefCounted (or RefCountedThreadSafe) like so to make it compile: |
| 49 // class PowerSaveBlocker::Delegate | 25 // class PowerSaveBlocker::Delegate |
| 50 // : public base::RefCounted<PowerSaveBlocker::Delegate> { | 26 // : public base::RefCounted<PowerSaveBlocker::Delegate> { |
| 51 // private: | 27 // private: |
| 52 // friend class base::RefCounted<Delegate>; | 28 // friend class base::RefCounted<Delegate>; |
| 53 // ~Delegate() {} | 29 // ~Delegate() {} |
| 54 // }; | 30 // }; |
| 55 scoped_refptr<Delegate> delegate_; | 31 scoped_refptr<Delegate> delegate_; |
| 56 | 32 |
| 57 DISALLOW_COPY_AND_ASSIGN(PowerSaveBlocker); | 33 DISALLOW_COPY_AND_ASSIGN(PowerSaveBlockerImpl); |
| 58 }; | 34 }; |
| 59 | 35 |
| 60 } // namespace content | 36 } // namespace content |
| 61 | 37 |
| 62 #endif // CONTENT_BROWSER_POWER_SAVE_BLOCKER_H_ | 38 #endif // CONTENT_BROWSER_POWER_SAVE_BLOCKER_IMPL_H_ |
| OLD | NEW |