power: Rename AmbientLightSensorFile as AmbientLightSensorDelegateFile
BUG=b:172408337
TEST=unit tests and run on kohaku
Change-Id: I30ba785b044e7e18997ec35e16afa1a1f683dc52
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform2/+/2593505
Commit-Queue: Cheng-Hao Yang <chenghaoyang@chromium.org>
Tested-by: Cheng-Hao Yang <chenghaoyang@chromium.org>
Reviewed-by: Cheng-Hao Yang <chenghaoyang@chromium.org>
Reviewed-by: Eric Caruso <ejcaruso@chromium.org>
diff --git a/power_manager/BUILD.gn b/power_manager/BUILD.gn
index 9a93775..5a13c78 100644
--- a/power_manager/BUILD.gn
+++ b/power_manager/BUILD.gn
@@ -132,7 +132,7 @@
sources = [
"powerd/system/acpi_wakeup_helper.cc",
"powerd/system/ambient_light_sensor.cc",
- "powerd/system/ambient_light_sensor_file.cc",
+ "powerd/system/ambient_light_sensor_delegate_file.cc",
"powerd/system/ambient_light_sensor_manager.cc",
"powerd/system/arc_timer_manager.cc",
"powerd/system/async_file_reader.cc",
@@ -421,7 +421,7 @@
sources = [
"common/testrunner.cc",
"powerd/system/acpi_wakeup_helper_test.cc",
- "powerd/system/ambient_light_sensor_file_test.cc",
+ "powerd/system/ambient_light_sensor_delegate_file_test.cc",
"powerd/system/ambient_light_sensor_manager_test.cc",
"powerd/system/ambient_light_sensor_test.cc",
"powerd/system/arc_timer_manager_test.cc",
diff --git a/power_manager/powerd/system/ambient_light_sensor_file.cc b/power_manager/powerd/system/ambient_light_sensor_delegate_file.cc
similarity index 83%
rename from power_manager/powerd/system/ambient_light_sensor_file.cc
rename to power_manager/powerd/system/ambient_light_sensor_delegate_file.cc
index 3db6ba7..35d3455 100644
--- a/power_manager/powerd/system/ambient_light_sensor_file.cc
+++ b/power_manager/powerd/system/ambient_light_sensor_delegate_file.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "power_manager/powerd/system/ambient_light_sensor_file.h"
+#include "power_manager/powerd/system/ambient_light_sensor_delegate_file.h"
#include <fcntl.h>
@@ -87,10 +87,10 @@
{ChannelType::Z, "blue", "z", false},
};
-const int AmbientLightSensorFile::kNumInitAttemptsBeforeLogging = 5;
-const int AmbientLightSensorFile::kNumInitAttemptsBeforeGivingUp = 20;
+const int AmbientLightSensorDelegateFile::kNumInitAttemptsBeforeLogging = 5;
+const int AmbientLightSensorDelegateFile::kNumInitAttemptsBeforeGivingUp = 20;
-AmbientLightSensorFile::AmbientLightSensorFile(
+AmbientLightSensorDelegateFile::AmbientLightSensorDelegateFile(
SensorLocation expected_sensor_location, bool enable_color_support)
: device_list_path_(kDefaultDeviceListPath),
poll_interval_ms_(kDefaultPollIntervalMs),
@@ -98,15 +98,15 @@
num_init_attempts_(0),
expected_sensor_location_(expected_sensor_location) {}
-AmbientLightSensorFile::~AmbientLightSensorFile() {}
+AmbientLightSensorDelegateFile::~AmbientLightSensorDelegateFile() {}
-void AmbientLightSensorFile::Init(bool read_immediately) {
+void AmbientLightSensorDelegateFile::Init(bool read_immediately) {
if (read_immediately)
ReadAls();
StartTimer();
}
-bool AmbientLightSensorFile::TriggerPollTimerForTesting() {
+bool AmbientLightSensorDelegateFile::TriggerPollTimerForTesting() {
if (!poll_timer_.IsRunning())
return false;
@@ -114,11 +114,11 @@
return true;
}
-bool AmbientLightSensorFile::IsColorSensor() const {
+bool AmbientLightSensorDelegateFile::IsColorSensor() const {
return !color_als_files_.empty();
}
-base::FilePath AmbientLightSensorFile::GetIlluminancePath() const {
+base::FilePath AmbientLightSensorDelegateFile::GetIlluminancePath() const {
if (IsColorSensor()) {
for (const ColorChannelInfo& channel : kColorChannelConfig) {
if (!channel.is_lux_channel)
@@ -133,13 +133,13 @@
return base::FilePath();
}
-void AmbientLightSensorFile::StartTimer() {
+void AmbientLightSensorDelegateFile::StartTimer() {
poll_timer_.Start(FROM_HERE,
base::TimeDelta::FromMilliseconds(poll_interval_ms_), this,
- &AmbientLightSensorFile::ReadAls);
+ &AmbientLightSensorDelegateFile::ReadAls);
}
-void AmbientLightSensorFile::ReadAls() {
+void AmbientLightSensorDelegateFile::ReadAls() {
// We really want to read the ambient light level.
// Complete the deferred lux file open if necessary.
if (!als_file_.HasOpenedFile() && !InitAlsFile()) {
@@ -153,24 +153,25 @@
// The timer will be restarted after the read finishes.
poll_timer_.Stop();
if (!IsColorSensor()) {
- als_file_.StartRead(base::Bind(&AmbientLightSensorFile::ReadCallback,
- base::Unretained(this)),
- base::Bind(&AmbientLightSensorFile::ErrorCallback,
- base::Unretained(this)));
+ als_file_.StartRead(
+ base::Bind(&AmbientLightSensorDelegateFile::ReadCallback,
+ base::Unretained(this)),
+ base::Bind(&AmbientLightSensorDelegateFile::ErrorCallback,
+ base::Unretained(this)));
return;
}
color_readings_.clear();
for (const ColorChannelInfo& channel : kColorChannelConfig) {
color_als_files_[&channel].StartRead(
- base::Bind(&AmbientLightSensorFile::ReadColorChannelCallback,
+ base::Bind(&AmbientLightSensorDelegateFile::ReadColorChannelCallback,
base::Unretained(this), &channel),
- base::Bind(&AmbientLightSensorFile::ErrorColorChannelCallback,
+ base::Bind(&AmbientLightSensorDelegateFile::ErrorColorChannelCallback,
base::Unretained(this), &channel));
}
}
-void AmbientLightSensorFile::ReadCallback(const std::string& data) {
+void AmbientLightSensorDelegateFile::ReadCallback(const std::string& data) {
if (!set_lux_callback_)
return;
@@ -181,12 +182,12 @@
StartTimer();
}
-void AmbientLightSensorFile::ErrorCallback() {
+void AmbientLightSensorDelegateFile::ErrorCallback() {
LOG(ERROR) << "Error reading ALS file";
StartTimer();
}
-void AmbientLightSensorFile::ReadColorChannelCallback(
+void AmbientLightSensorDelegateFile::ReadColorChannelCallback(
const ColorChannelInfo* channel, const std::string& data) {
int value = -1;
ParseLuxData(data, &value);
@@ -194,14 +195,14 @@
CollectChannelReadings();
}
-void AmbientLightSensorFile::ErrorColorChannelCallback(
+void AmbientLightSensorDelegateFile::ErrorColorChannelCallback(
const ColorChannelInfo* channel) {
LOG(ERROR) << "Error reading ALS file for " << channel->xyz_name << "channel";
color_readings_[channel] = -1;
CollectChannelReadings();
}
-void AmbientLightSensorFile::CollectChannelReadings() {
+void AmbientLightSensorDelegateFile::CollectChannelReadings() {
if (!set_lux_callback_ ||
color_readings_.size() != base::size(kColorChannelConfig)) {
return;
@@ -251,7 +252,7 @@
StartTimer();
}
-void AmbientLightSensorFile::InitColorAlsFiles(
+void AmbientLightSensorDelegateFile::InitColorAlsFiles(
const base::FilePath& device_dir) {
color_als_files_.clear();
std::map<const ColorChannelInfo*, AsyncFileReader> channel_map;
@@ -271,7 +272,7 @@
LOG(INFO) << "ALS at path " << device_dir.value() << " has color support";
}
-bool AmbientLightSensorFile::InitAlsFile() {
+bool AmbientLightSensorDelegateFile::InitAlsFile() {
CHECK(!als_file_.HasOpenedFile());
// Search the iio/devices directory for a subdirectory (eg "device0" or
diff --git a/power_manager/powerd/system/ambient_light_sensor_file.h b/power_manager/powerd/system/ambient_light_sensor_delegate_file.h
similarity index 82%
rename from power_manager/powerd/system/ambient_light_sensor_file.h
rename to power_manager/powerd/system/ambient_light_sensor_delegate_file.h
index ddda2f7..efead3a 100644
--- a/power_manager/powerd/system/ambient_light_sensor_file.h
+++ b/power_manager/powerd/system/ambient_light_sensor_delegate_file.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef POWER_MANAGER_POWERD_SYSTEM_AMBIENT_LIGHT_SENSOR_FILE_H_
-#define POWER_MANAGER_POWERD_SYSTEM_AMBIENT_LIGHT_SENSOR_FILE_H_
+#ifndef POWER_MANAGER_POWERD_SYSTEM_AMBIENT_LIGHT_SENSOR_DELEGATE_FILE_H_
+#define POWER_MANAGER_POWERD_SYSTEM_AMBIENT_LIGHT_SENSOR_DELEGATE_FILE_H_
#include <list>
#include <map>
@@ -30,18 +30,20 @@
LID,
};
-class AmbientLightSensorFile : public AmbientLightSensorDelegate {
+class AmbientLightSensorDelegateFile : public AmbientLightSensorDelegate {
public:
- // Number of failed init attempts before AmbientLightSensorFile will start
- // logging warnings or stop trying entirely.
+ // Number of failed init attempts before AmbientLightSensorDelegateFile will
+ // start logging warnings or stop trying entirely.
static const int kNumInitAttemptsBeforeLogging;
static const int kNumInitAttemptsBeforeGivingUp;
- AmbientLightSensorFile(SensorLocation expected_sensor_location,
- bool allow_ambient_eq);
- AmbientLightSensorFile(const AmbientLightSensorFile&) = delete;
- AmbientLightSensorFile& operator=(const AmbientLightSensorFile&) = delete;
- ~AmbientLightSensorFile() override;
+ AmbientLightSensorDelegateFile(SensorLocation expected_sensor_location,
+ bool allow_ambient_eq);
+ AmbientLightSensorDelegateFile(const AmbientLightSensorDelegateFile&) =
+ delete;
+ AmbientLightSensorDelegateFile& operator=(
+ const AmbientLightSensorDelegateFile&) = delete;
+ ~AmbientLightSensorDelegateFile() override;
void set_device_list_path_for_testing(const base::FilePath& path) {
device_list_path_ = path;
@@ -125,4 +127,4 @@
} // namespace system
} // namespace power_manager
-#endif // POWER_MANAGER_POWERD_SYSTEM_AMBIENT_LIGHT_SENSOR_FILE_H_
+#endif // POWER_MANAGER_POWERD_SYSTEM_AMBIENT_LIGHT_SENSOR_DELEGATE_FILE_H_
diff --git a/power_manager/powerd/system/ambient_light_sensor_file_test.cc b/power_manager/powerd/system/ambient_light_sensor_delegate_file_test.cc
similarity index 84%
rename from power_manager/powerd/system/ambient_light_sensor_file_test.cc
rename to power_manager/powerd/system/ambient_light_sensor_delegate_file_test.cc
index 046e7eb..5b78fd9 100644
--- a/power_manager/powerd/system/ambient_light_sensor_file_test.cc
+++ b/power_manager/powerd/system/ambient_light_sensor_delegate_file_test.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "power_manager/powerd/system/ambient_light_sensor_file.h"
+#include "power_manager/powerd/system/ambient_light_sensor_delegate_file.h"
#include <memory>
#include <utility>
@@ -56,13 +56,14 @@
} // namespace
-class AmbientLightSensorFileTest : public ::testing::Test {
+class AmbientLightSensorDelegateFileTest : public ::testing::Test {
public:
- AmbientLightSensorFileTest() {}
- AmbientLightSensorFileTest(const AmbientLightSensorFileTest&) = delete;
- AmbientLightSensorFileTest& operator=(const AmbientLightSensorFileTest&) =
- delete;
- ~AmbientLightSensorFileTest() override {}
+ AmbientLightSensorDelegateFileTest() {}
+ AmbientLightSensorDelegateFileTest(
+ const AmbientLightSensorDelegateFileTest&) = delete;
+ AmbientLightSensorDelegateFileTest& operator=(
+ const AmbientLightSensorDelegateFileTest&) = delete;
+ ~AmbientLightSensorDelegateFileTest() override {}
protected:
void SetUp() override {
@@ -78,7 +79,7 @@
void TearDown() override { sensor_->RemoveObserver(&observer_); }
void CreateSensor(SensorLocation location, bool allow_ambient_eq) {
- auto als = std::make_unique<system::AmbientLightSensorFile>(
+ auto als = std::make_unique<system::AmbientLightSensorDelegateFile>(
location, allow_ambient_eq);
als_ = als.get();
sensor_->SetDelegate(std::move(als));
@@ -106,10 +107,10 @@
TestObserver observer_;
std::unique_ptr<AmbientLightSensor> sensor_;
- AmbientLightSensorFile* als_;
+ AmbientLightSensorDelegateFile* als_;
};
-TEST_F(AmbientLightSensorFileTest, Basic) {
+TEST_F(AmbientLightSensorDelegateFileTest, Basic) {
CreateSensor(SensorLocation::UNKNOWN, false);
WriteLux(100);
@@ -126,12 +127,13 @@
EXPECT_EQ(200, sensor_->GetAmbientLightLux());
}
-TEST_F(AmbientLightSensorFileTest, GiveUpAfterTooManyFailures) {
+TEST_F(AmbientLightSensorDelegateFileTest, GiveUpAfterTooManyFailures) {
CreateSensor(SensorLocation::UNKNOWN, false);
// Test that the timer is eventually stopped after many failures.
base::DeleteFile(data_file_, false);
- for (int i = 0; i < AmbientLightSensorFile::kNumInitAttemptsBeforeGivingUp;
+ for (int i = 0;
+ i < AmbientLightSensorDelegateFile::kNumInitAttemptsBeforeGivingUp;
++i) {
EXPECT_TRUE(als_->TriggerPollTimerForTesting());
EXPECT_LT(sensor_->GetAmbientLightLux(), 0);
@@ -141,12 +143,13 @@
EXPECT_LT(sensor_->GetAmbientLightLux(), 0);
}
-TEST_F(AmbientLightSensorFileTest, FailToFindSensorAtLid) {
+TEST_F(AmbientLightSensorDelegateFileTest, FailToFindSensorAtLid) {
// Test that the timer is eventually stopped after many failures if |sensor_|
// is unable to find the sensor at the expected location.
CreateSensor(SensorLocation::LID, false);
- for (int i = 0; i < AmbientLightSensorFile::kNumInitAttemptsBeforeGivingUp;
+ for (int i = 0;
+ i < AmbientLightSensorDelegateFile::kNumInitAttemptsBeforeGivingUp;
++i) {
EXPECT_TRUE(als_->TriggerPollTimerForTesting());
EXPECT_LT(sensor_->GetAmbientLightLux(), 0);
@@ -156,7 +159,7 @@
EXPECT_LT(sensor_->GetAmbientLightLux(), 0);
}
-TEST_F(AmbientLightSensorFileTest, FindSensorAtBase) {
+TEST_F(AmbientLightSensorDelegateFileTest, FindSensorAtBase) {
// Test that |sensor_| is able to find the correct sensor at the expected
// location.
base::FilePath loc_file = device_dir_.Append("location");
@@ -169,7 +172,7 @@
EXPECT_EQ(100, sensor_->GetAmbientLightLux());
}
-TEST_F(AmbientLightSensorFileTest, IsColorSensor) {
+TEST_F(AmbientLightSensorDelegateFileTest, IsColorSensor) {
CreateSensor(SensorLocation::UNKNOWN, false);
// Default sensor does not have color support.
diff --git a/power_manager/powerd/system/ambient_light_sensor_manager.cc b/power_manager/powerd/system/ambient_light_sensor_manager.cc
index 04e2f09..9b7619e 100644
--- a/power_manager/powerd/system/ambient_light_sensor_manager.cc
+++ b/power_manager/powerd/system/ambient_light_sensor_manager.cc
@@ -78,8 +78,8 @@
std::unique_ptr<AmbientLightSensor> AmbientLightSensorManager::CreateSensor(
SensorLocation location, bool allow_ambient_eq) {
auto sensor = std::make_unique<system::AmbientLightSensor>();
- auto als = std::make_unique<system::AmbientLightSensorFile>(location,
- allow_ambient_eq);
+ auto als = std::make_unique<system::AmbientLightSensorDelegateFile>(
+ location, allow_ambient_eq);
als_list_.push_back(als.get());
sensor->SetDelegate(std::move(als));
diff --git a/power_manager/powerd/system/ambient_light_sensor_manager.h b/power_manager/powerd/system/ambient_light_sensor_manager.h
index 433d636..1869eb9 100644
--- a/power_manager/powerd/system/ambient_light_sensor_manager.h
+++ b/power_manager/powerd/system/ambient_light_sensor_manager.h
@@ -10,7 +10,7 @@
#include "power_manager/common/power_constants.h"
#include "power_manager/powerd/system/ambient_light_sensor.h"
-#include "power_manager/powerd/system/ambient_light_sensor_file.h"
+#include "power_manager/powerd/system/ambient_light_sensor_delegate_file.h"
#include "power_manager/powerd/system/ambient_light_sensor_manager_interface.h"
namespace power_manager {
@@ -52,7 +52,7 @@
system::AmbientLightSensor* lid_sensor_ = nullptr;
system::AmbientLightSensor* base_sensor_ = nullptr;
- std::vector<AmbientLightSensorFile*> als_list_;
+ std::vector<AmbientLightSensorDelegateFile*> als_list_;
};
} // namespace system
diff --git a/power_manager/powerd/system/fuzzers/powerd_als_fuzzer.cc b/power_manager/powerd/system/fuzzers/powerd_als_fuzzer.cc
index b826ac9..005b2af 100644
--- a/power_manager/powerd/system/fuzzers/powerd_als_fuzzer.cc
+++ b/power_manager/powerd/system/fuzzers/powerd_als_fuzzer.cc
@@ -3,7 +3,7 @@
// found in the LICENSE file.
#include "power_manager/powerd/system/ambient_light_sensor.h"
-#include "power_manager/powerd/system/ambient_light_sensor_file.h"
+#include "power_manager/powerd/system/ambient_light_sensor_delegate_file.h"
#include <base/files/file_path.h>
#include <base/files/file_util.h>
@@ -60,7 +60,7 @@
sensor_ = std::make_unique<system::AmbientLightSensor>();
- auto als = std::make_unique<system::AmbientLightSensorFile>(
+ auto als = std::make_unique<system::AmbientLightSensorDelegateFile>(
SensorLocation::LID, false);
als_ = als.get();
@@ -69,7 +69,7 @@
}
std::unique_ptr<AmbientLightSensor> sensor_;
- AmbientLightSensorFile* als_;
+ AmbientLightSensorDelegateFile* als_;
protected:
base::ScopedTempDir temp_dir_;