| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/browser/api/system_cpu/cpu_info_provider.h" | 5 #include "extensions/browser/api/system_cpu/cpu_info_provider.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 #include <winternl.h> | 8 #include <winternl.h> |
| 9 | 9 |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include <memory> |
| 11 |
| 11 #include "base/sys_info.h" | 12 #include "base/sys_info.h" |
| 12 | 13 |
| 13 namespace extensions { | 14 namespace extensions { |
| 14 | 15 |
| 15 namespace { | 16 namespace { |
| 16 | 17 |
| 17 const wchar_t kNtdll[] = L"ntdll.dll"; | 18 const wchar_t kNtdll[] = L"ntdll.dll"; |
| 18 const char kNtQuerySystemInformationName[] = "NtQuerySystemInformation"; | 19 const char kNtQuerySystemInformationName[] = "NtQuerySystemInformation"; |
| 19 | 20 |
| 20 // See MSDN about NtQuerySystemInformation definition. | 21 // See MSDN about NtQuerySystemInformation definition. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 31 | 32 |
| 32 HMODULE ntdll = GetModuleHandle(kNtdll); | 33 HMODULE ntdll = GetModuleHandle(kNtdll); |
| 33 CHECK(ntdll != NULL); | 34 CHECK(ntdll != NULL); |
| 34 NtQuerySystemInformationPF NtQuerySystemInformation = | 35 NtQuerySystemInformationPF NtQuerySystemInformation = |
| 35 reinterpret_cast<NtQuerySystemInformationPF>( | 36 reinterpret_cast<NtQuerySystemInformationPF>( |
| 36 ::GetProcAddress(ntdll, kNtQuerySystemInformationName)); | 37 ::GetProcAddress(ntdll, kNtQuerySystemInformationName)); |
| 37 | 38 |
| 38 CHECK(NtQuerySystemInformation != NULL); | 39 CHECK(NtQuerySystemInformation != NULL); |
| 39 | 40 |
| 40 int num_of_processors = base::SysInfo::NumberOfProcessors(); | 41 int num_of_processors = base::SysInfo::NumberOfProcessors(); |
| 41 scoped_ptr<SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION[]> processor_info( | 42 std::unique_ptr<SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION[]> processor_info( |
| 42 new SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION[num_of_processors]); | 43 new SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION[num_of_processors]); |
| 43 | 44 |
| 44 ULONG returned_bytes = 0, | 45 ULONG returned_bytes = 0, |
| 45 bytes = sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION) * | 46 bytes = sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION) * |
| 46 num_of_processors; | 47 num_of_processors; |
| 47 if (!NT_SUCCESS( | 48 if (!NT_SUCCESS( |
| 48 NtQuerySystemInformation(SystemProcessorPerformanceInformation, | 49 NtQuerySystemInformation(SystemProcessorPerformanceInformation, |
| 49 processor_info.get(), | 50 processor_info.get(), |
| 50 bytes, | 51 bytes, |
| 51 &returned_bytes))) | 52 &returned_bytes))) |
| (...skipping 16 matching lines...) Expand all Loading... |
| 68 infos->at(i).usage.kernel = kernel - idle; | 69 infos->at(i).usage.kernel = kernel - idle; |
| 69 infos->at(i).usage.user = user; | 70 infos->at(i).usage.user = user; |
| 70 infos->at(i).usage.idle = idle; | 71 infos->at(i).usage.idle = idle; |
| 71 infos->at(i).usage.total = kernel + user; | 72 infos->at(i).usage.total = kernel + user; |
| 72 } | 73 } |
| 73 | 74 |
| 74 return true; | 75 return true; |
| 75 } | 76 } |
| 76 | 77 |
| 77 } // namespace extensions | 78 } // namespace extensions |
| OLD | NEW |