| 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 <windows.h> | 5 #include <windows.h> |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/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/browser/power_save_blocker_impl.h" | 13 #include "device/power_save_blocker/power_save_blocker_impl.h" |
| 14 | 14 |
| 15 namespace content { | 15 namespace device { |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 int g_blocker_count[2]; | 18 int g_blocker_count[2]; |
| 19 | 19 |
| 20 HANDLE CreatePowerRequest(POWER_REQUEST_TYPE type, | 20 HANDLE CreatePowerRequest(POWER_REQUEST_TYPE type, |
| 21 const std::string& description) { | 21 const std::string& description) { |
| 22 if (type == PowerRequestExecutionRequired && | 22 if (type == PowerRequestExecutionRequired && |
| 23 base::win::GetVersion() < base::win::VERSION_WIN8) { | 23 base::win::GetVersion() < base::win::VERSION_WIN8) { |
| 24 return INVALID_HANDLE_VALUE; | 24 return INVALID_HANDLE_VALUE; |
| 25 } | 25 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 50 | 50 |
| 51 if (type == PowerRequestExecutionRequired && | 51 if (type == PowerRequestExecutionRequired && |
| 52 base::win::GetVersion() < base::win::VERSION_WIN8) { | 52 base::win::GetVersion() < base::win::VERSION_WIN8) { |
| 53 return; | 53 return; |
| 54 } | 54 } |
| 55 | 55 |
| 56 BOOL success = ::PowerClearRequest(request_handle.Get(), type); | 56 BOOL success = ::PowerClearRequest(request_handle.Get(), type); |
| 57 DCHECK(success); | 57 DCHECK(success); |
| 58 } | 58 } |
| 59 | 59 |
| 60 void ApplySimpleBlock(PowerSaveBlocker::PowerSaveBlockerType type, | 60 void ApplySimpleBlock(PowerSaveBlocker::PowerSaveBlockerType type, int delta) { |
| 61 int delta) { | |
| 62 g_blocker_count[type] += delta; | 61 g_blocker_count[type] += delta; |
| 63 DCHECK_GE(g_blocker_count[type], 0); | 62 DCHECK_GE(g_blocker_count[type], 0); |
| 64 | 63 |
| 65 if (g_blocker_count[type] > 1) | 64 if (g_blocker_count[type] > 1) |
| 66 return; | 65 return; |
| 67 | 66 |
| 68 DWORD this_flag = 0; | 67 DWORD this_flag = 0; |
| 69 if (type == PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension) | 68 if (type == PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension) |
| 70 this_flag |= ES_SYSTEM_REQUIRED; | 69 this_flag |= ES_SYSTEM_REQUIRED; |
| 71 else | 70 else |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 blocking_task_runner_(blocking_task_runner) { | 149 blocking_task_runner_(blocking_task_runner) { |
| 151 ui_task_runner_->PostTask(FROM_HERE, | 150 ui_task_runner_->PostTask(FROM_HERE, |
| 152 base::Bind(&Delegate::ApplyBlock, delegate_)); | 151 base::Bind(&Delegate::ApplyBlock, delegate_)); |
| 153 } | 152 } |
| 154 | 153 |
| 155 PowerSaveBlockerImpl::~PowerSaveBlockerImpl() { | 154 PowerSaveBlockerImpl::~PowerSaveBlockerImpl() { |
| 156 ui_task_runner_->PostTask(FROM_HERE, | 155 ui_task_runner_->PostTask(FROM_HERE, |
| 157 base::Bind(&Delegate::RemoveBlock, delegate_)); | 156 base::Bind(&Delegate::RemoveBlock, delegate_)); |
| 158 } | 157 } |
| 159 | 158 |
| 160 } // namespace content | 159 } // namespace device |
| OLD | NEW |