| OLD | NEW |
| 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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 if (line.compare(0, 4, "cpu ") == 0) | 152 if (line.compare(0, 4, "cpu ") == 0) |
| 153 return line; | 153 return line; |
| 154 } | 154 } |
| 155 // First line should always start with "cpu ". | 155 // First line should always start with "cpu ". |
| 156 NOTREACHED() << "Could not parse /proc/stat contents: " << contents; | 156 NOTREACHED() << "Could not parse /proc/stat contents: " << contents; |
| 157 } | 157 } |
| 158 LOG(WARNING) << "Unable to read CPU statistics from " << kProcStat; | 158 LOG(WARNING) << "Unable to read CPU statistics from " << kProcStat; |
| 159 return std::string(); | 159 return std::string(); |
| 160 } | 160 } |
| 161 | 161 |
| 162 // Reads the CPU temperature info from | 162 // Read system temperature sensors from |
| 163 // /sys/class/hwmon/hwmon*/device/temp*_input and | |
| 164 // /sys/class/hwmon/hwmon*/device/temp*_label files. | |
| 165 // | 163 // |
| 166 // temp*_input contains CPU temperature in millidegree Celsius | 164 // /sys/class/hwmon/hwmon*/(device/)?temp*_input |
| 167 // temp*_label contains appropriate temperature channel label. | 165 // |
| 166 // which contains millidegree Celsius temperature and |
| 167 // |
| 168 // /sys/class/hwmon/hwmon*/(device/)?temp*_label or |
| 169 // /sys/class/hwmon/hwmon*/name |
| 170 // |
| 171 // which contains an appropriate label name for the given sensor. |
| 168 std::vector<em::CPUTempInfo> ReadCPUTempInfo() { | 172 std::vector<em::CPUTempInfo> ReadCPUTempInfo() { |
| 169 std::vector<em::CPUTempInfo> contents; | 173 std::vector<em::CPUTempInfo> contents; |
| 170 // Get directories /sys/class/hwmon/hwmon* | 174 // Get directories /sys/class/hwmon/hwmon* |
| 171 base::FileEnumerator hwmon_enumerator(base::FilePath(kHwmonDir), false, | 175 base::FileEnumerator hwmon_enumerator(base::FilePath(kHwmonDir), false, |
| 172 base::FileEnumerator::DIRECTORIES, | 176 base::FileEnumerator::DIRECTORIES, |
| 173 kHwmonDirectoryPattern); | 177 kHwmonDirectoryPattern); |
| 174 | 178 |
| 175 for (base::FilePath hwmon_path = hwmon_enumerator.Next(); !hwmon_path.empty(); | 179 for (base::FilePath hwmon_path = hwmon_enumerator.Next(); !hwmon_path.empty(); |
| 176 hwmon_path = hwmon_enumerator.Next()) { | 180 hwmon_path = hwmon_enumerator.Next()) { |
| 177 // Get files /sys/class/hwmon/hwmon*/device/temp*_input | 181 // Get temp*_input files in hwmon*/ and hwmon*/device/ |
| 178 const base::FilePath hwmon_device_dir = hwmon_path.Append(kDeviceDir); | 182 if (base::PathExists(hwmon_path.Append(kDeviceDir))) { |
| 179 base::FileEnumerator enumerator(hwmon_device_dir, false, | 183 hwmon_path = hwmon_path.Append(kDeviceDir); |
| 180 base::FileEnumerator::FILES, | 184 } |
| 181 kCPUTempFilePattern); | 185 base::FileEnumerator enumerator( |
| 186 hwmon_path, false, base::FileEnumerator::FILES, kCPUTempFilePattern); |
| 182 for (base::FilePath temperature_path = enumerator.Next(); | 187 for (base::FilePath temperature_path = enumerator.Next(); |
| 183 !temperature_path.empty(); temperature_path = enumerator.Next()) { | 188 !temperature_path.empty(); temperature_path = enumerator.Next()) { |
| 184 // Get appropriate temp*_label file. | 189 // Get appropriate temp*_label file. |
| 185 std::string label_path = temperature_path.MaybeAsASCII(); | 190 std::string label_path = temperature_path.MaybeAsASCII(); |
| 186 if (label_path.empty()) { | 191 if (label_path.empty()) { |
| 187 LOG(WARNING) << "Unable to parse a path to temp*_input file as ASCII"; | 192 LOG(WARNING) << "Unable to parse a path to temp*_input file as ASCII"; |
| 188 continue; | 193 continue; |
| 189 } | 194 } |
| 190 base::ReplaceSubstringsAfterOffset(&label_path, 0, "input", "label"); | 195 base::ReplaceSubstringsAfterOffset(&label_path, 0, "input", "label"); |
| 196 base::FilePath name_path = hwmon_path.Append("name"); |
| 191 | 197 |
| 192 // Read label. | 198 // Get the label describing this temperature. Use temp*_label |
| 199 // if present, fall back on name file or blank. |
| 193 std::string label; | 200 std::string label; |
| 194 if (!base::PathExists(base::FilePath(label_path)) || | 201 if (base::PathExists(base::FilePath(label_path))) { |
| 195 !base::ReadFileToString(base::FilePath(label_path), &label)) { | 202 base::ReadFileToString(base::FilePath(label_path), &label); |
| 203 } else if (base::PathExists(base::FilePath(name_path))) { |
| 204 base::ReadFileToString(name_path, &label); |
| 205 } else { |
| 196 label = std::string(); | 206 label = std::string(); |
| 197 } | 207 } |
| 198 | 208 |
| 199 // Read temperature in millidegree Celsius. | 209 // Read temperature in millidegree Celsius. |
| 200 std::string temperature_string; | 210 std::string temperature_string; |
| 201 int32_t temperature = 0; | 211 int32_t temperature = 0; |
| 202 if (base::ReadFileToString(temperature_path, &temperature_string) && | 212 if (base::ReadFileToString(temperature_path, &temperature_string) && |
| 203 sscanf(temperature_string.c_str(), "%d", &temperature) == 1) { | 213 sscanf(temperature_string.c_str(), "%d", &temperature) == 1) { |
| 204 // CPU temp in millidegree Celsius to Celsius | 214 // CPU temp in millidegree Celsius to Celsius |
| 205 temperature /= 1000; | 215 temperature /= 1000; |
| (...skipping 994 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1200 ScheduleGeolocationUpdateRequest(); | 1210 ScheduleGeolocationUpdateRequest(); |
| 1201 } | 1211 } |
| 1202 | 1212 |
| 1203 void DeviceStatusCollector::ReceiveVolumeInfo( | 1213 void DeviceStatusCollector::ReceiveVolumeInfo( |
| 1204 const std::vector<em::VolumeInfo>& info) { | 1214 const std::vector<em::VolumeInfo>& info) { |
| 1205 if (report_hardware_status_) | 1215 if (report_hardware_status_) |
| 1206 volume_info_ = info; | 1216 volume_info_ = info; |
| 1207 } | 1217 } |
| 1208 | 1218 |
| 1209 } // namespace policy | 1219 } // namespace policy |
| OLD | NEW |