| 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 <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 static int blocker_count_[]; | 53 static int blocker_count_[]; |
| 54 | 54 |
| 55 DISALLOW_COPY_AND_ASSIGN(PowerSaveBlocker); | 55 DISALLOW_COPY_AND_ASSIGN(PowerSaveBlocker); |
| 56 }; | 56 }; |
| 57 | 57 |
| 58 namespace content { | 58 namespace content { |
| 59 | 59 |
| 60 // NOT READY YET. PowerSaveBlocker above is soon to be replaced by this class, | 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. | 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. | 62 // A RAII-style class to block the system from entering low-power (sleep) mode. |
| 63 // This class is thread-safe; it may be constructed and deleted on any thread. |
| 63 class CONTENT_EXPORT PowerSaveBlocker2 { | 64 class CONTENT_EXPORT PowerSaveBlocker2 { |
| 64 public: | 65 public: |
| 65 enum PowerSaveBlockerType { | 66 enum PowerSaveBlockerType { |
| 66 // Prevent the application from being suspended. On some platforms, apps may | 67 // 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 // 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 // requests that the app continue to run in that case, and on all platforms |
| 69 // prevents the system from sleeping. | 70 // prevents the system from sleeping. |
| 70 // Example use cases: downloading a file, playing audio. | 71 // Example use cases: downloading a file, playing audio. |
| 71 kPowerSaveBlockPreventAppSuspension, | 72 kPowerSaveBlockPreventAppSuspension, |
| 72 | 73 |
| 73 // Prevent the display from going to sleep. This also has the side effect of | 74 // 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 // 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 // app from being suspended on some platforms if the user hides it. |
| 76 // Example use case: playing video. | 77 // Example use case: playing video. |
| 77 kPowerSaveBlockPreventDisplaySleep, | 78 kPowerSaveBlockPreventDisplaySleep, |
| 78 }; | 79 }; |
| 79 | 80 |
| 80 // Pass in the type of power save blocking desired. If multiple types of | 81 // Pass in the type of power save blocking desired. If multiple types of |
| 81 // blocking are desired, instantiate one PowerSaveBlocker for each type. | 82 // blocking are desired, instantiate one PowerSaveBlocker for each type. |
| 82 // |reason| may be provided to the underlying system APIs on some platforms. | 83 // |reason| may be provided to the underlying system APIs on some platforms. |
| 83 PowerSaveBlocker2(PowerSaveBlockerType type, const std::string& reason); | 84 PowerSaveBlocker2(PowerSaveBlockerType type, const std::string& reason); |
| 84 ~PowerSaveBlocker2(); | 85 ~PowerSaveBlocker2(); |
| 85 | 86 |
| 86 private: | 87 private: |
| 87 class Delegate; | 88 class Delegate; |
| 88 | 89 |
| 89 // Implementations of this class may need a second object with different | 90 // Implementations of this class may need a second object with different |
| 90 // lifetime than the RAII container, or additional storage. This member is | 91 // 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 // here for that purpose. If not used, just define the class as an empty |
| 92 // RefCounted like so to make it compile: | 93 // RefCounted (or RefCountedThreadSafe) like so to make it compile: |
| 93 // class PowerSaveBlocker2::Delegate | 94 // class PowerSaveBlocker2::Delegate |
| 94 // : public RefCounted<PowerSaveBlocker2::Delegate> { | 95 // : public base::RefCounted<PowerSaveBlocker2::Delegate> { |
| 96 // private: |
| 97 // friend class base::RefCounted<Delegate>; |
| 98 // ~Delegate() {} |
| 95 // }; | 99 // }; |
| 96 scoped_refptr<Delegate> delegate_; | 100 scoped_refptr<Delegate> delegate_; |
| 97 | 101 |
| 98 DISALLOW_COPY_AND_ASSIGN(PowerSaveBlocker2); | 102 DISALLOW_COPY_AND_ASSIGN(PowerSaveBlocker2); |
| 99 }; | 103 }; |
| 100 | 104 |
| 101 } // namespace content | 105 } // namespace content |
| 102 | 106 |
| 103 #endif // CONTENT_BROWSER_POWER_SAVE_BLOCKER_H_ | 107 #endif // CONTENT_BROWSER_POWER_SAVE_BLOCKER_H_ |
| OLD | NEW |