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

Side by Side Diff: chrome/browser/chromeos/policy/device_status_collector.cc

Issue 2115723003: Report all system temperatures, not just CPU (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 5 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 | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "chrome/browser/chromeos/policy/device_status_collector.h" 5 #include "chrome/browser/chromeos/policy/device_status_collector.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 if (line.compare(0, 4, "cpu ") == 0) 149 if (line.compare(0, 4, "cpu ") == 0)
150 return line; 150 return line;
151 } 151 }
152 // First line should always start with "cpu ". 152 // First line should always start with "cpu ".
153 NOTREACHED() << "Could not parse /proc/stat contents: " << contents; 153 NOTREACHED() << "Could not parse /proc/stat contents: " << contents;
154 } 154 }
155 LOG(WARNING) << "Unable to read CPU statistics from " << kProcStat; 155 LOG(WARNING) << "Unable to read CPU statistics from " << kProcStat;
156 return std::string(); 156 return std::string();
157 } 157 }
158 158
159 // Reads the CPU temperature info from 159 // Reads the CPU temperature info from
pastarmovj 2016/09/23 09:28:11 Please update this comment to reflect the new logi
160 // /sys/class/hwmon/hwmon*/device/temp*_input and 160 // /sys/class/hwmon/hwmon*/device/temp*_input and
161 // /sys/class/hwmon/hwmon*/device/temp*_label files. 161 // /sys/class/hwmon/hwmon*/device/temp*_label files.
162 // 162 //
163 // temp*_input contains CPU temperature in millidegree Celsius 163 // temp*_input contains CPU temperature in millidegree Celsius
164 // temp*_label contains appropriate temperature channel label. 164 // temp*_label contains appropriate temperature channel label.
165 std::vector<em::CPUTempInfo> ReadCPUTempInfo() { 165 std::vector<em::CPUTempInfo> ReadCPUTempInfo() {
166 std::vector<em::CPUTempInfo> contents; 166 std::vector<em::CPUTempInfo> contents;
167 // Get directories /sys/class/hwmon/hwmon* 167 // Get directories /sys/class/hwmon/hwmon*
168 base::FileEnumerator hwmon_enumerator(base::FilePath(kHwmonDir), false, 168 base::FileEnumerator hwmon_enumerator(base::FilePath(kHwmonDir), false,
169 base::FileEnumerator::DIRECTORIES, 169 base::FileEnumerator::DIRECTORIES,
170 kHwmonDirectoryPattern); 170 kHwmonDirectoryPattern);
171 171
172 for (base::FilePath hwmon_path = hwmon_enumerator.Next(); !hwmon_path.empty(); 172 for (base::FilePath hwmon_path = hwmon_enumerator.Next(); !hwmon_path.empty();
173 hwmon_path = hwmon_enumerator.Next()) { 173 hwmon_path = hwmon_enumerator.Next()) {
174 // Get files /sys/class/hwmon/hwmon*/device/temp*_input 174 // Get temp*_input files in hwmon*/ and hwmon*/device/
175 const base::FilePath hwmon_device_dir = hwmon_path.Append(kDeviceDir); 175 if (base::PathExists(hwmon_path.Append(kDeviceDir))) {
176 base::FileEnumerator enumerator(hwmon_device_dir, false, 176 hwmon_path = hwmon_path.Append(kDeviceDir);
177 base::FileEnumerator::FILES, 177 }
178 kCPUTempFilePattern); 178 base::FileEnumerator enumerator(
179 hwmon_path, false, base::FileEnumerator::FILES, kCPUTempFilePattern);
179 for (base::FilePath temperature_path = enumerator.Next(); 180 for (base::FilePath temperature_path = enumerator.Next();
180 !temperature_path.empty(); temperature_path = enumerator.Next()) { 181 !temperature_path.empty(); temperature_path = enumerator.Next()) {
181 // Get appropriate temp*_label file. 182 // Get appropriate temp*_label file.
182 std::string label_path = temperature_path.MaybeAsASCII(); 183 std::string label_path = temperature_path.MaybeAsASCII();
183 if (label_path.empty()) { 184 if (label_path.empty()) {
184 LOG(WARNING) << "Unable to parse a path to temp*_input file as ASCII"; 185 LOG(WARNING) << "Unable to parse a path to temp*_input file as ASCII";
185 continue; 186 continue;
186 } 187 }
187 base::ReplaceSubstringsAfterOffset(&label_path, 0, "input", "label"); 188 base::ReplaceSubstringsAfterOffset(&label_path, 0, "input", "label");
189 base::FilePath name_path = hwmon_path.Append("name");
188 190
189 // Read label. 191 // Get the label describing this temperature. Use temp*_label
192 // if present, fall back on name file or blank.
190 std::string label; 193 std::string label;
191 if (!base::PathExists(base::FilePath(label_path)) || 194 if (base::PathExists(base::FilePath(label_path))) {
192 !base::ReadFileToString(base::FilePath(label_path), &label)) { 195 base::ReadFileToString(base::FilePath(label_path), &label);
Andrew T Wilson (Slow) 2016/09/06 18:10:45 I'm concerned that if ReadFileToString() returns a
Jay Lee 2016/09/14 15:24:54 As far as I can see at: https://chromium.googleso
196 } else if (base::PathExists(base::FilePath(name_path))) {
197 base::ReadFileToString(name_path, &label);
198 } else {
193 label = std::string(); 199 label = std::string();
194 } 200 }
195 201
196 // Read temperature in millidegree Celsius. 202 // Read temperature in millidegree Celsius.
197 std::string temperature_string; 203 std::string temperature_string;
198 int32_t temperature = 0; 204 int32_t temperature = 0;
199 if (base::ReadFileToString(temperature_path, &temperature_string) && 205 if (base::ReadFileToString(temperature_path, &temperature_string) &&
200 sscanf(temperature_string.c_str(), "%d", &temperature) == 1) { 206 sscanf(temperature_string.c_str(), "%d", &temperature) == 1) {
201 // CPU temp in millidegree Celsius to Celsius 207 // CPU temp in millidegree Celsius to Celsius
202 temperature /= 1000; 208 temperature /= 1000;
(...skipping 851 matching lines...) Expand 10 before | Expand all | Expand 10 after
1054 ScheduleGeolocationUpdateRequest(); 1060 ScheduleGeolocationUpdateRequest();
1055 } 1061 }
1056 1062
1057 void DeviceStatusCollector::ReceiveVolumeInfo( 1063 void DeviceStatusCollector::ReceiveVolumeInfo(
1058 const std::vector<em::VolumeInfo>& info) { 1064 const std::vector<em::VolumeInfo>& info) {
1059 if (report_hardware_status_) 1065 if (report_hardware_status_)
1060 volume_info_ = info; 1066 volume_info_ = info;
1061 } 1067 }
1062 1068
1063 } // namespace policy 1069 } // namespace policy
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698