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

Unified Diff: device/generic_sensor/linux/platform_sensor_utils_linux.cc

Issue 2506973003: [sensors](CrOS/Linux) Fix: create sensors when no scaling file is specified (Closed)
Patch Set: use the first version Created 4 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/generic_sensor/linux/platform_sensor_utils_linux.cc
diff --git a/device/generic_sensor/linux/platform_sensor_utils_linux.cc b/device/generic_sensor/linux/platform_sensor_utils_linux.cc
index add5d479cb9b6118d2d4a717a880020afb1e8db3..6f81ca74c2c7b2aedcc469cd54f785109015d4f2 100644
--- a/device/generic_sensor/linux/platform_sensor_utils_linux.cc
+++ b/device/generic_sensor/linux/platform_sensor_utils_linux.cc
@@ -51,12 +51,9 @@ bool GetSensorFilePaths(const SensorDataLinux& data,
return true;
}
-// Returns -1 if unable to read a scaling value, 1 if scaling value is not
-// found. Otherwise, returns a scaling value read from a file.
-double GetSensorScalingValue(const base::FilePath& scale_file_path) {
- if (!base::PathExists(scale_file_path))
- return 1;
-
+// Returns -1 if unable to read a scaling value.
+// Otherwise, returns a scaling value read from a file.
+double ReadSensorScalingValue(const base::FilePath& scale_file_path) {
std::string value;
if (!base::ReadFileToString(scale_file_path, &value))
return -1;
@@ -79,9 +76,15 @@ std::unique_ptr<SensorReader> SensorReader::Create(
return nullptr;
DCHECK(!sensor_paths.empty());
- const base::FilePath scale_file_path =
- sensor_paths.back().DirName().Append(data.sensor_scale_name);
- double scaling_value = GetSensorScalingValue(scale_file_path);
+ // Scaling value is 1 if scaling file is not specified is |data| or scaling
+ // file is not found.
+ double scaling_value = 1;
+ if (!data.sensor_scale_name.empty()) {
+ const base::FilePath scale_file_path =
+ sensor_paths.back().DirName().Append(data.sensor_scale_name);
+ if (base::PathExists(scale_file_path))
+ scaling_value = ReadSensorScalingValue(scale_file_path);
+ }
// A file with a scaling value is found, but couldn't be read.
if (scaling_value == -1)
« 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