Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: extensions/browser/api/system_cpu/cpu_info_provider_win.cc

Issue 1842953002: [Extensions] Convert APIs to use movable types [13] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/sys_info.h" 10 #include "base/sys_info.h"
11 11
12 namespace extensions { 12 namespace extensions {
13 13
14 namespace { 14 namespace {
15 15
16 const wchar_t kNtdll[] = L"ntdll.dll"; 16 const wchar_t kNtdll[] = L"ntdll.dll";
17 const char kNtQuerySystemInformationName[] = "NtQuerySystemInformation"; 17 const char kNtQuerySystemInformationName[] = "NtQuerySystemInformation";
18 18
19 // See MSDN about NtQuerySystemInformation definition. 19 // See MSDN about NtQuerySystemInformation definition.
20 typedef DWORD(WINAPI* NtQuerySystemInformationPF)(DWORD system_info_class, 20 typedef DWORD(WINAPI* NtQuerySystemInformationPF)(DWORD system_info_class,
21 PVOID system_info, 21 PVOID system_info,
22 ULONG system_info_length, 22 ULONG system_info_length,
23 PULONG return_length); 23 PULONG return_length);
24 24
25 } // namespace 25 } // namespace
26 26
27 bool CpuInfoProvider::QueryCpuTimePerProcessor( 27 bool CpuInfoProvider::QueryCpuTimePerProcessor(
28 std::vector<linked_ptr<api::system_cpu::ProcessorInfo>>* infos) { 28 std::vector<api::system_cpu::ProcessorInfo>* infos) {
29 DCHECK(infos); 29 DCHECK(infos);
30 30
31 HMODULE ntdll = GetModuleHandle(kNtdll); 31 HMODULE ntdll = GetModuleHandle(kNtdll);
32 CHECK(ntdll != NULL); 32 CHECK(ntdll != NULL);
33 NtQuerySystemInformationPF NtQuerySystemInformation = 33 NtQuerySystemInformationPF NtQuerySystemInformation =
34 reinterpret_cast<NtQuerySystemInformationPF>( 34 reinterpret_cast<NtQuerySystemInformationPF>(
35 ::GetProcAddress(ntdll, kNtQuerySystemInformationName)); 35 ::GetProcAddress(ntdll, kNtQuerySystemInformationName));
36 36
37 CHECK(NtQuerySystemInformation != NULL); 37 CHECK(NtQuerySystemInformation != NULL);
38 38
(...skipping 18 matching lines...) Expand all
57 return false; 57 return false;
58 58
59 DCHECK_EQ(num_of_processors, static_cast<int>(infos->size())); 59 DCHECK_EQ(num_of_processors, static_cast<int>(infos->size()));
60 for (int i = 0; i < returned_num_of_processors; ++i) { 60 for (int i = 0; i < returned_num_of_processors; ++i) {
61 double kernel = static_cast<double>(processor_info[i].KernelTime.QuadPart), 61 double kernel = static_cast<double>(processor_info[i].KernelTime.QuadPart),
62 user = static_cast<double>(processor_info[i].UserTime.QuadPart), 62 user = static_cast<double>(processor_info[i].UserTime.QuadPart),
63 idle = static_cast<double>(processor_info[i].IdleTime.QuadPart); 63 idle = static_cast<double>(processor_info[i].IdleTime.QuadPart);
64 64
65 // KernelTime needs to be fixed-up, because it includes both idle time and 65 // KernelTime needs to be fixed-up, because it includes both idle time and
66 // real kernel time. 66 // real kernel time.
67 infos->at(i)->usage.kernel = kernel - idle; 67 infos->at(i).usage.kernel = kernel - idle;
68 infos->at(i)->usage.user = user; 68 infos->at(i).usage.user = user;
69 infos->at(i)->usage.idle = idle; 69 infos->at(i).usage.idle = idle;
70 infos->at(i)->usage.total = kernel + user; 70 infos->at(i).usage.total = kernel + user;
71 } 71 }
72 72
73 return true; 73 return true;
74 } 74 }
75 75
76 } // namespace extensions 76 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/api/system_cpu/cpu_info_provider_mac.cc ('k') | extensions/browser/api/system_cpu/system_cpu_apitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698