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_impl.h" | 5 #include "content/browser/power_save_blocker_impl.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/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 if (!PowerCreateRequestFn || !PowerSetRequestFn) { | 32 if (!PowerCreateRequestFn || !PowerSetRequestFn) { |
33 HMODULE module = GetModuleHandle(L"kernel32.dll"); | 33 HMODULE module = GetModuleHandle(L"kernel32.dll"); |
34 PowerCreateRequestFn = reinterpret_cast<PowerCreateRequestPtr>( | 34 PowerCreateRequestFn = reinterpret_cast<PowerCreateRequestPtr>( |
35 GetProcAddress(module, "PowerCreateRequest")); | 35 GetProcAddress(module, "PowerCreateRequest")); |
36 PowerSetRequestFn = reinterpret_cast<PowerSetRequestPtr>( | 36 PowerSetRequestFn = reinterpret_cast<PowerSetRequestPtr>( |
37 GetProcAddress(module, "PowerSetRequest")); | 37 GetProcAddress(module, "PowerSetRequest")); |
38 | 38 |
39 if (!PowerCreateRequestFn || !PowerSetRequestFn) | 39 if (!PowerCreateRequestFn || !PowerSetRequestFn) |
40 return INVALID_HANDLE_VALUE; | 40 return INVALID_HANDLE_VALUE; |
41 } | 41 } |
42 string16 wide_reason = ASCIIToUTF16(reason); | 42 base::string16 wide_reason = ASCIIToUTF16(reason); |
43 REASON_CONTEXT context = {0}; | 43 REASON_CONTEXT context = {0}; |
44 context.Version = POWER_REQUEST_CONTEXT_VERSION; | 44 context.Version = POWER_REQUEST_CONTEXT_VERSION; |
45 context.Flags = POWER_REQUEST_CONTEXT_SIMPLE_STRING; | 45 context.Flags = POWER_REQUEST_CONTEXT_SIMPLE_STRING; |
46 context.Reason.SimpleReasonString = const_cast<wchar_t*>(wide_reason.c_str()); | 46 context.Reason.SimpleReasonString = const_cast<wchar_t*>(wide_reason.c_str()); |
47 | 47 |
48 base::win::ScopedHandle handle(PowerCreateRequestFn(&context)); | 48 base::win::ScopedHandle handle(PowerCreateRequestFn(&context)); |
49 if (!handle.IsValid()) | 49 if (!handle.IsValid()) |
50 return INVALID_HANDLE_VALUE; | 50 return INVALID_HANDLE_VALUE; |
51 | 51 |
52 if (PowerSetRequestFn(handle, type)) | 52 if (PowerSetRequestFn(handle, type)) |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 base::Bind(&Delegate::ApplyBlock, delegate_)); | 165 base::Bind(&Delegate::ApplyBlock, delegate_)); |
166 } | 166 } |
167 | 167 |
168 PowerSaveBlockerImpl::~PowerSaveBlockerImpl() { | 168 PowerSaveBlockerImpl::~PowerSaveBlockerImpl() { |
169 BrowserThread::PostTask( | 169 BrowserThread::PostTask( |
170 BrowserThread::UI, FROM_HERE, | 170 BrowserThread::UI, FROM_HERE, |
171 base::Bind(&Delegate::RemoveBlock, delegate_)); | 171 base::Bind(&Delegate::RemoveBlock, delegate_)); |
172 } | 172 } |
173 | 173 |
174 } // namespace content | 174 } // namespace content |
OLD | NEW |