| 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" |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 | 158 |
| 159 PowerSaveBlockerType type_; | 159 PowerSaveBlockerType type_; |
| 160 const std::string reason_; | 160 const std::string reason_; |
| 161 base::win::ScopedHandle handle_; | 161 base::win::ScopedHandle handle_; |
| 162 | 162 |
| 163 DISALLOW_COPY_AND_ASSIGN(Delegate); | 163 DISALLOW_COPY_AND_ASSIGN(Delegate); |
| 164 }; | 164 }; |
| 165 | 165 |
| 166 void PowerSaveBlocker::Delegate::ApplyBlock() { | 166 void PowerSaveBlocker::Delegate::ApplyBlock() { |
| 167 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 167 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 168 base::win::Version os_version = base::win::GetVersion(); | 168 if (base::win::GetVersion() < base::win::VERSION_WIN7) |
| 169 if (os_version < base::win::VERSION_WIN7) | |
| 170 return ApplySimpleBlock(type_, 1); | 169 return ApplySimpleBlock(type_, 1); |
| 171 | 170 |
| 172 handle_.Set(CreatePowerRequest(RequestType(), reason_)); | 171 handle_.Set(CreatePowerRequest(RequestType(), reason_)); |
| 173 } | 172 } |
| 174 | 173 |
| 175 void PowerSaveBlocker::Delegate::RemoveBlock() { | 174 void PowerSaveBlocker::Delegate::RemoveBlock() { |
| 176 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 175 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 177 base::win::Version os_version = base::win::GetVersion(); | 176 if (base::win::GetVersion() < base::win::VERSION_WIN7) |
| 178 if (os_version < base::win::VERSION_WIN7) | |
| 179 return ApplySimpleBlock(type_, -1); | 177 return ApplySimpleBlock(type_, -1); |
| 180 | 178 |
| 181 DeletePowerRequest(RequestType(), handle_.Take()); | 179 DeletePowerRequest(RequestType(), handle_.Take()); |
| 182 } | 180 } |
| 183 | 181 |
| 184 POWER_REQUEST_TYPE PowerSaveBlocker::Delegate::RequestType() { | 182 POWER_REQUEST_TYPE PowerSaveBlocker::Delegate::RequestType() { |
| 185 if (type_ == kPowerSaveBlockPreventDisplaySleep) | 183 if (type_ == kPowerSaveBlockPreventDisplaySleep) |
| 186 return PowerRequestDisplayRequired; | 184 return PowerRequestDisplayRequired; |
| 187 | 185 |
| 186 if (base::win::GetVersion() < base::win::VERSION_WIN8) |
| 187 return PowerRequestSystemRequired; |
| 188 |
| 188 return PowerRequestExecutionRequired; | 189 return PowerRequestExecutionRequired; |
| 189 } | 190 } |
| 190 | 191 |
| 191 PowerSaveBlocker::PowerSaveBlocker(PowerSaveBlockerType type, | 192 PowerSaveBlocker::PowerSaveBlocker(PowerSaveBlockerType type, |
| 192 const std::string& reason) | 193 const std::string& reason) |
| 193 : delegate_(new Delegate(type, reason)) { | 194 : delegate_(new Delegate(type, reason)) { |
| 194 BrowserThread::PostTask( | 195 BrowserThread::PostTask( |
| 195 BrowserThread::UI, FROM_HERE, | 196 BrowserThread::UI, FROM_HERE, |
| 196 base::Bind(&Delegate::ApplyBlock, delegate_)); | 197 base::Bind(&Delegate::ApplyBlock, delegate_)); |
| 197 } | 198 } |
| 198 | 199 |
| 199 PowerSaveBlocker::~PowerSaveBlocker() { | 200 PowerSaveBlocker::~PowerSaveBlocker() { |
| 200 BrowserThread::PostTask( | 201 BrowserThread::PostTask( |
| 201 BrowserThread::UI, FROM_HERE, | 202 BrowserThread::UI, FROM_HERE, |
| 202 base::Bind(&Delegate::RemoveBlock, delegate_)); | 203 base::Bind(&Delegate::RemoveBlock, delegate_)); |
| 203 } | 204 } |
| 204 | 205 |
| 205 } // namespace content | 206 } // namespace content |
| OLD | NEW |