Chromium Code Reviews| Index: device/generic_sensor/platform_sensor_reader_linux.cc |
| diff --git a/device/generic_sensor/platform_sensor_reader_linux.cc b/device/generic_sensor/platform_sensor_reader_linux.cc |
| index 5c014a4b200b43b9f8697bcfa8c5ee1cfc457fb9..143b1987a455374e925c9ef8e8eef4f74b1d5373 100644 |
| --- a/device/generic_sensor/platform_sensor_reader_linux.cc |
| +++ b/device/generic_sensor/platform_sensor_reader_linux.cc |
| @@ -74,6 +74,7 @@ PollingSensorReader::~PollingSensorReader() { |
| bool PollingSensorReader::StartFetchingData( |
| const PlatformSensorConfiguration& configuration) { |
| + DCHECK(task_runner_->BelongsToCurrentThread()); |
| if (is_reading_active_) |
| StopFetchingData(); |
| @@ -83,6 +84,7 @@ bool PollingSensorReader::StartFetchingData( |
| } |
| void PollingSensorReader::StopFetchingData() { |
| + DCHECK(task_runner_->BelongsToCurrentThread()); |
| is_reading_active_ = false; |
| timer_->Stop(); |
| } |
| @@ -108,7 +110,9 @@ void PollingSensorReader::PollForData() { |
| std::string new_read_value; |
| if (!base::ReadFileToString(path, &new_read_value)) { |
| NotifyReadError(); |
| - StopFetchingData(); |
| + task_runner_->PostTask(FROM_HERE, |
| + base::Bind(&PollingSensorReader::StopFetchingData, |
| + weak_factory_.GetWeakPtr())); |
| return; |
| } |
| @@ -116,7 +120,9 @@ void PollingSensorReader::PollForData() { |
| base::TrimWhitespaceASCII(new_read_value, base::TRIM_ALL, &new_read_value); |
| if (!base::StringToDouble(new_read_value, &new_value)) { |
| NotifyReadError(); |
| - StopFetchingData(); |
| + task_runner_->PostTask(FROM_HERE, |
| + base::Bind(&PollingSensorReader::StopFetchingData, |
| + weak_factory_.GetWeakPtr())); |
|
gab
2016/12/13 18:12:45
WeakPtr is also not thread-safe (can't obtain it o
maksims (do not use this acc)
2016/12/13 18:18:19
Do you mean I need 2 to create two different weak
gab
2016/12/13 18:23:02
classes in Chromium are typically bound to a singl
|
| return; |
| } |
| readings.values[i++] = new_value; |