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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
160 // temp*_input contains CPU temperature in millidegree Celsius | 160 // temp*_input contains CPU temperature in millidegree Celsius |
161 // temp*_label contains appropriate temperature channel label. | 161 // temp*_label contains appropriate temperature channel label. |
162 std::vector<em::CPUTempInfo> ReadCPUTempInfo() { | 162 std::vector<em::CPUTempInfo> ReadCPUTempInfo() { |
163 std::vector<em::CPUTempInfo> contents; | 163 std::vector<em::CPUTempInfo> contents; |
164 // Get directories /sys/class/hwmon/hwmon* | 164 // Get directories /sys/class/hwmon/hwmon* |
165 base::FileEnumerator hwmon_enumerator(base::FilePath(kHwmonDir), false, | 165 base::FileEnumerator hwmon_enumerator(base::FilePath(kHwmonDir), false, |
166 base::FileEnumerator::DIRECTORIES, | 166 base::FileEnumerator::DIRECTORIES, |
167 kHwmonDirectoryPattern); | 167 kHwmonDirectoryPattern); |
168 | 168 |
169 for (base::FilePath hwmon_path = hwmon_enumerator.Next(); !hwmon_path.empty(); | 169 for (base::FilePath hwmon_path = hwmon_enumerator.Next(); !hwmon_path.empty(); |
170 hwmon_path = hwmon_enumerator.Next()) { | 170 hwmon_path = hwmon_enumerator.Next()) { |
Polina Bondarenko
2016/07/01 15:22:26
s/devices/device
| |
171 // Get files /sys/class/hwmon/hwmon*/device/temp*_input | 171 // Get temp*_input files in hwmon*/ and hwmon*/devices/ |
172 const base::FilePath hwmon_device_dir = hwmon_path.Append(kDeviceDir); | 172 if (base::PathExists(hwmon_path.Append(kDeviceDir))) { |
173 base::FileEnumerator enumerator(hwmon_device_dir, false, | 173 hwmon_path = hwmon_path.Append(kDeviceDir); |
174 base::FileEnumerator::FILES, | 174 } |
175 kCPUTempFilePattern); | 175 base::FileEnumerator enumerator( |
176 hwmon_path, false, base::FileEnumerator::FILES, kCPUTempFilePattern); | |
176 for (base::FilePath temperature_path = enumerator.Next(); | 177 for (base::FilePath temperature_path = enumerator.Next(); |
177 !temperature_path.empty(); temperature_path = enumerator.Next()) { | 178 !temperature_path.empty(); temperature_path = enumerator.Next()) { |
178 // Get appropriate temp*_label file. | 179 // Get appropriate temp*_label file. |
179 std::string label_path = temperature_path.MaybeAsASCII(); | 180 std::string label_path = temperature_path.MaybeAsASCII(); |
180 if (label_path.empty()) { | 181 if (label_path.empty()) { |
181 LOG(WARNING) << "Unable to parse a path to temp*_input file as ASCII"; | 182 LOG(WARNING) << "Unable to parse a path to temp*_input file as ASCII"; |
182 continue; | 183 continue; |
183 } | 184 } |
184 base::ReplaceSubstringsAfterOffset(&label_path, 0, "input", "label"); | 185 base::ReplaceSubstringsAfterOffset(&label_path, 0, "input", "label"); |
186 base::FilePath name_path = hwmon_path.Append("name"); | |
185 | 187 |
186 // Read label. | 188 // Get the label describing this temperature. Use temp*_label |
189 // if present, fall back on name file or blank. | |
187 std::string label; | 190 std::string label; |
188 if (!base::PathExists(base::FilePath(label_path)) || | 191 if (base::PathExists(base::FilePath(label_path))) { |
189 !base::ReadFileToString(base::FilePath(label_path), &label)) { | 192 base::ReadFileToString(base::FilePath(label_path), &label); |
193 } else if (base::PathExists(base::FilePath(name_path))) { | |
194 base::ReadFileToString(name_path, &label); | |
195 } else { | |
190 label = std::string(); | 196 label = std::string(); |
191 } | 197 } |
192 | 198 |
193 // Read temperature in millidegree Celsius. | 199 // Read temperature in millidegree Celsius. |
194 std::string temperature_string; | 200 std::string temperature_string; |
195 int32_t temperature = 0; | 201 int32_t temperature = 0; |
196 if (base::ReadFileToString(temperature_path, &temperature_string) && | 202 if (base::ReadFileToString(temperature_path, &temperature_string) && |
197 sscanf(temperature_string.c_str(), "%d", &temperature) == 1) { | 203 sscanf(temperature_string.c_str(), "%d", &temperature) == 1) { |
198 // CPU temp in millidegree Celsius to Celsius | 204 // CPU temp in millidegree Celsius to Celsius |
Polina Bondarenko
2016/07/01 15:22:26
Are added temperatures still in Millicelsius e.g.f
| |
199 temperature /= 1000; | 205 temperature /= 1000; |
200 | 206 |
201 em::CPUTempInfo info; | 207 em::CPUTempInfo info; |
202 info.set_cpu_label(label); | 208 info.set_cpu_label(label); |
203 info.set_cpu_temp(temperature); | 209 info.set_cpu_temp(temperature); |
204 contents.push_back(info); | 210 contents.push_back(info); |
205 } else { | 211 } else { |
206 LOG(WARNING) << "Unable to read CPU temp from " | 212 LOG(WARNING) << "Unable to read CPU temp from " |
207 << temperature_path.MaybeAsASCII(); | 213 << temperature_path.MaybeAsASCII(); |
208 } | 214 } |
(...skipping 842 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1051 ScheduleGeolocationUpdateRequest(); | 1057 ScheduleGeolocationUpdateRequest(); |
1052 } | 1058 } |
1053 | 1059 |
1054 void DeviceStatusCollector::ReceiveVolumeInfo( | 1060 void DeviceStatusCollector::ReceiveVolumeInfo( |
1055 const std::vector<em::VolumeInfo>& info) { | 1061 const std::vector<em::VolumeInfo>& info) { |
1056 if (report_hardware_status_) | 1062 if (report_hardware_status_) |
1057 volume_info_ = info; | 1063 volume_info_ = info; |
1058 } | 1064 } |
1059 | 1065 |
1060 } // namespace policy | 1066 } // namespace policy |
OLD | NEW |