| 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 #include "content/browser/power_save_blocker.h" | 5 #include "content/browser/power_save_blocker.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 11 #include "base/win/scoped_handle.h" | 11 #include "base/win/scoped_handle.h" |
| 12 #include "base/win/windows_version.h" | 12 #include "base/win/windows_version.h" |
| 13 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
| 14 | 14 |
| 15 using content::BrowserThread; | |
| 16 | |
| 17 // Called only from UI thread. | |
| 18 // static | |
| 19 void PowerSaveBlocker::ApplyBlock(PowerSaveBlockerType type) { | |
| 20 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 21 | |
| 22 DWORD flags = ES_CONTINUOUS; | |
| 23 | |
| 24 switch (type) { | |
| 25 case kPowerSaveBlockPreventSystemSleep: | |
| 26 flags |= ES_SYSTEM_REQUIRED; | |
| 27 break; | |
| 28 case kPowerSaveBlockPreventDisplaySleep: | |
| 29 flags |= ES_DISPLAY_REQUIRED; | |
| 30 break; | |
| 31 default: | |
| 32 break; | |
| 33 } | |
| 34 | |
| 35 SetThreadExecutionState(flags); | |
| 36 } | |
| 37 | |
| 38 // TODO(rvargas): Remove after the old interface goes away. | |
| 39 #define PowerSaveBlocker PowerSaveBlocker2 | |
| 40 | |
| 41 namespace { | 15 namespace { |
| 42 | 16 |
| 43 int g_blocker_count[2]; | 17 int g_blocker_count[2]; |
| 44 | 18 |
| 45 #if _WIN32_WINNT <= _WIN32_WINNT_WIN7 | 19 #if _WIN32_WINNT <= _WIN32_WINNT_WIN7 |
| 46 POWER_REQUEST_TYPE PowerRequestExecutionRequired = | 20 POWER_REQUEST_TYPE PowerRequestExecutionRequired = |
| 47 static_cast<POWER_REQUEST_TYPE>(PowerRequestAwayModeRequired + 1); | 21 static_cast<POWER_REQUEST_TYPE>(PowerRequestAwayModeRequired + 1); |
| 48 #endif | 22 #endif |
| 49 | 23 |
| 50 HANDLE CreatePowerRequest(POWER_REQUEST_TYPE type, const std::string& reason) { | 24 HANDLE CreatePowerRequest(POWER_REQUEST_TYPE type, const std::string& reason) { |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 : type_(type), reason_(reason) {} | 120 : type_(type), reason_(reason) {} |
| 147 | 121 |
| 148 // Does the actual work to apply or remove the desired power save block. | 122 // Does the actual work to apply or remove the desired power save block. |
| 149 void ApplyBlock(); | 123 void ApplyBlock(); |
| 150 void RemoveBlock(); | 124 void RemoveBlock(); |
| 151 | 125 |
| 152 // Returns the equivalent POWER_REQUEST_TYPE for this request. | 126 // Returns the equivalent POWER_REQUEST_TYPE for this request. |
| 153 POWER_REQUEST_TYPE RequestType(); | 127 POWER_REQUEST_TYPE RequestType(); |
| 154 | 128 |
| 155 private: | 129 private: |
| 156 friend class base::RefCountedThreadSafe<PowerSaveBlocker::Delegate>; | 130 friend class base::RefCountedThreadSafe<Delegate>; |
| 157 ~Delegate() {} | 131 ~Delegate() {} |
| 158 | 132 |
| 159 PowerSaveBlockerType type_; | 133 PowerSaveBlockerType type_; |
| 160 const std::string reason_; | 134 const std::string reason_; |
| 161 base::win::ScopedHandle handle_; | 135 base::win::ScopedHandle handle_; |
| 162 | 136 |
| 163 DISALLOW_COPY_AND_ASSIGN(Delegate); | 137 DISALLOW_COPY_AND_ASSIGN(Delegate); |
| 164 }; | 138 }; |
| 165 | 139 |
| 166 void PowerSaveBlocker::Delegate::ApplyBlock() { | 140 void PowerSaveBlocker::Delegate::ApplyBlock() { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 197 base::Bind(&Delegate::ApplyBlock, delegate_)); | 171 base::Bind(&Delegate::ApplyBlock, delegate_)); |
| 198 } | 172 } |
| 199 | 173 |
| 200 PowerSaveBlocker::~PowerSaveBlocker() { | 174 PowerSaveBlocker::~PowerSaveBlocker() { |
| 201 BrowserThread::PostTask( | 175 BrowserThread::PostTask( |
| 202 BrowserThread::UI, FROM_HERE, | 176 BrowserThread::UI, FROM_HERE, |
| 203 base::Bind(&Delegate::RemoveBlock, delegate_)); | 177 base::Bind(&Delegate::RemoveBlock, delegate_)); |
| 204 } | 178 } |
| 205 | 179 |
| 206 } // namespace content | 180 } // namespace content |
| OLD | NEW |