OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "base/sys_info.h" | 7 #include "base/sys_info.h" |
8 | 8 |
9 #if defined(OS_CHROMEOS) | |
10 #include "chromeos/system/cpu_temperature_reader.h" | |
11 #endif // defined(OS_CHROMEOS) | |
12 | |
9 namespace extensions { | 13 namespace extensions { |
10 | 14 |
11 using api::system_cpu::CpuInfo; | 15 using api::system_cpu::CpuInfo; |
12 | 16 |
13 // Static member intialization. | 17 // Static member intialization. |
14 base::LazyInstance<scoped_refptr<CpuInfoProvider>>::DestructorAtExit | 18 base::LazyInstance<scoped_refptr<CpuInfoProvider>>::DestructorAtExit |
15 CpuInfoProvider::provider_ = LAZY_INSTANCE_INITIALIZER; | 19 CpuInfoProvider::provider_ = LAZY_INSTANCE_INITIALIZER; |
16 | 20 |
17 CpuInfoProvider::CpuInfoProvider() { | 21 CpuInfoProvider::CpuInfoProvider() { |
18 } | 22 } |
(...skipping 13 matching lines...) Expand all Loading... | |
32 info_.model_name = base::SysInfo::CPUModelName(); | 36 info_.model_name = base::SysInfo::CPUModelName(); |
33 info_.features = GetFeatures(); | 37 info_.features = GetFeatures(); |
34 | 38 |
35 info_.processors.clear(); | 39 info_.processors.clear(); |
36 // Fill in the correct number of uninitialized ProcessorInfos. | 40 // Fill in the correct number of uninitialized ProcessorInfos. |
37 for (int i = 0; i < info_.num_of_processors; ++i) | 41 for (int i = 0; i < info_.num_of_processors; ++i) |
38 info_.processors.push_back(api::system_cpu::ProcessorInfo()); | 42 info_.processors.push_back(api::system_cpu::ProcessorInfo()); |
39 // Initialize the ProcessorInfos, or return an empty array if that fails. | 43 // Initialize the ProcessorInfos, or return an empty array if that fails. |
40 if (!QueryCpuTimePerProcessor(&info_.processors)) | 44 if (!QueryCpuTimePerProcessor(&info_.processors)) |
41 info_.processors.clear(); | 45 info_.processors.clear(); |
46 | |
47 #if defined(OS_CHROMEOS) | |
48 info_.temperatures.clear(); | |
Devlin
2017/04/26 02:04:59
what is this clear()ing?
Simon Que
2017/04/26 02:27:21
CpuInfoProvider is a singleton class. |info_| reta
| |
49 auto cpu_temp_info = | |
50 chromeos::system::CPUTemperatureReader().GetCPUTemperatures(); | |
Devlin
2017/04/26 02:04:58
GetCPUTemperatures() doesn't make it clear what th
Simon Que
2017/04/26 02:27:21
Done.
| |
51 for (const auto& info : cpu_temp_info) { | |
Devlin
2017/04/26 02:04:59
info_.temperatures.reserve(cpu_temp_info.size())
Simon Que
2017/04/26 02:27:21
Done.
| |
52 info_.temperatures.push_back(info.temp_celsius); | |
53 } | |
54 #endif // defined(OS_CHROMEOS) | |
55 | |
42 return true; | 56 return true; |
43 } | 57 } |
44 | 58 |
45 std::vector<std::string> CpuInfoProvider::GetFeatures() const { | 59 std::vector<std::string> CpuInfoProvider::GetFeatures() const { |
46 std::vector<std::string> features; | 60 std::vector<std::string> features; |
47 // These are the feature codes used by /proc/cpuinfo on Linux. | 61 // These are the feature codes used by /proc/cpuinfo on Linux. |
48 if (cpu_.has_mmx()) | 62 if (cpu_.has_mmx()) |
49 features.push_back("mmx"); | 63 features.push_back("mmx"); |
50 if (cpu_.has_sse()) | 64 if (cpu_.has_sse()) |
51 features.push_back("sse"); | 65 features.push_back("sse"); |
(...skipping 13 matching lines...) Expand all Loading... | |
65 } | 79 } |
66 | 80 |
67 // static | 81 // static |
68 CpuInfoProvider* CpuInfoProvider::Get() { | 82 CpuInfoProvider* CpuInfoProvider::Get() { |
69 if (provider_.Get().get() == NULL) | 83 if (provider_.Get().get() == NULL) |
70 provider_.Get() = new CpuInfoProvider(); | 84 provider_.Get() = new CpuInfoProvider(); |
71 return provider_.Get().get(); | 85 return provider_.Get().get(); |
72 } | 86 } |
73 | 87 |
74 } // namespace extensions | 88 } // namespace extensions |
OLD | NEW |