Index: device/generic_sensor/platform_sensor_linux.cc |
diff --git a/device/generic_sensor/platform_sensor_linux.cc b/device/generic_sensor/platform_sensor_linux.cc |
index 55aa1398d1499c7bd61bfc4ec10b1199b5087c85..2f133ca99b9b9700815704c25e56e328ceade41f 100644 |
--- a/device/generic_sensor/platform_sensor_linux.cc |
+++ b/device/generic_sensor/platform_sensor_linux.cc |
@@ -29,12 +29,23 @@ PlatformSensorLinux::PlatformSensorLinux( |
default_configuration_( |
PlatformSensorConfiguration(sensor_device->device_frequency)), |
reporting_mode_(sensor_device->reporting_mode), |
+ polling_thread_task_runner_(std::move(polling_thread_task_runner)), |
weak_factory_(this) { |
- sensor_reader_ = |
- SensorReader::Create(sensor_device, this, polling_thread_task_runner); |
+ SensorReader::UpdateSensorReadingCallback update_reading_cb = |
+ base::Bind(&PlatformSensorLinux::UpdatePlatformSensorReading, |
+ weak_factory_.GetWeakPtr()); |
+ SensorReader::NotifyReadErrorCallback notify_read_error_cb = |
+ base::Bind(&PlatformSensorLinux::NotifyPlatformSensorError, |
+ weak_factory_.GetWeakPtr()); |
+ |
+ sensor_reader_ = SensorReader::Create( |
+ sensor_device, task_runner_, update_reading_cb, notify_read_error_cb); |
Reilly Grant (use Gerrit)
2016/12/16 21:34:42
Now you've negated the benefit of passing callback
maksims (do not use this acc)
2016/12/19 09:46:22
Done.
|
} |
-PlatformSensorLinux::~PlatformSensorLinux() = default; |
+PlatformSensorLinux::~PlatformSensorLinux() { |
+ DCHECK(task_runner_->BelongsToCurrentThread()); |
+ polling_thread_task_runner_->DeleteSoon(FROM_HERE, sensor_reader_.release()); |
+} |
mojom::ReportingMode PlatformSensorLinux::GetReportingMode() { |
DCHECK(task_runner_->BelongsToCurrentThread()); |
@@ -62,15 +73,18 @@ void PlatformSensorLinux::NotifyPlatformSensorError() { |
bool PlatformSensorLinux::StartSensor( |
const PlatformSensorConfiguration& configuration) { |
DCHECK(task_runner_->BelongsToCurrentThread()); |
- if (!sensor_reader_) |
- return false; |
- return sensor_reader_->StartFetchingData(configuration); |
+ polling_thread_task_runner_->PostTask( |
+ FROM_HERE, |
+ base::Bind(&SensorReader::StartFetchingData, |
+ base::Unretained(sensor_reader_.get()), configuration)); |
+ return true; |
} |
void PlatformSensorLinux::StopSensor() { |
DCHECK(task_runner_->BelongsToCurrentThread()); |
- DCHECK(sensor_reader_); |
- sensor_reader_->StopFetchingData(); |
+ polling_thread_task_runner_->PostTask( |
+ FROM_HERE, base::Bind(&SensorReader::StopFetchingData, |
+ base::Unretained(sensor_reader_.get()))); |
} |
bool PlatformSensorLinux::CheckSensorConfiguration( |