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

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

Issue 2802593005: extensions: Add CPU temperatures field to system.cpu.getInfo() function (Closed)
Patch Set: Responded to tbarzic's feedback Created 3 years, 7 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
« no previous file with comments | « no previous file | extensions/browser/api/system_cpu/system_cpu_apitest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 using CPUTemperatureInfo =
49 chromeos::system::CPUTemperatureReader::CPUTemperatureInfo;
50 std::vector<CPUTemperatureInfo> cpu_temp_info =
51 chromeos::system::CPUTemperatureReader().GetCPUTemperatures();
52 info_.temperatures.clear();
53 info_.temperatures.reserve(cpu_temp_info.size());
54 for (const CPUTemperatureInfo& info : cpu_temp_info) {
55 info_.temperatures.push_back(info.temp_celsius);
56 }
57 #endif // defined(OS_CHROMEOS)
58
42 return true; 59 return true;
43 } 60 }
44 61
45 std::vector<std::string> CpuInfoProvider::GetFeatures() const { 62 std::vector<std::string> CpuInfoProvider::GetFeatures() const {
46 std::vector<std::string> features; 63 std::vector<std::string> features;
47 // These are the feature codes used by /proc/cpuinfo on Linux. 64 // These are the feature codes used by /proc/cpuinfo on Linux.
48 if (cpu_.has_mmx()) 65 if (cpu_.has_mmx())
49 features.push_back("mmx"); 66 features.push_back("mmx");
50 if (cpu_.has_sse()) 67 if (cpu_.has_sse())
51 features.push_back("sse"); 68 features.push_back("sse");
(...skipping 13 matching lines...) Expand all
65 } 82 }
66 83
67 // static 84 // static
68 CpuInfoProvider* CpuInfoProvider::Get() { 85 CpuInfoProvider* CpuInfoProvider::Get() {
69 if (provider_.Get().get() == NULL) 86 if (provider_.Get().get() == NULL)
70 provider_.Get() = new CpuInfoProvider(); 87 provider_.Get() = new CpuInfoProvider();
71 return provider_.Get().get(); 88 return provider_.Get().get();
72 } 89 }
73 90
74 } // namespace extensions 91 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | extensions/browser/api/system_cpu/system_cpu_apitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698