| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/browser/device_sensors/data_fetcher_shared_memory_base.h" | 5 #include "content/browser/device_sensors/data_fetcher_shared_memory_base.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" | |
| 9 #include "base/logging.h" | 8 #include "base/logging.h" |
| 10 #include "base/single_thread_task_runner.h" | |
| 11 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 12 #include "base/threading/thread.h" | 10 #include "base/threading/thread.h" |
| 13 #include "base/timer/timer.h" | 11 #include "base/timer/timer.h" |
| 14 #include "content/common/device_sensors/device_light_hardware_buffer.h" | 12 #include "content/common/device_sensors/device_light_hardware_buffer.h" |
| 15 #include "content/common/device_sensors/device_motion_hardware_buffer.h" | 13 #include "content/common/device_sensors/device_motion_hardware_buffer.h" |
| 16 #include "content/common/device_sensors/device_orientation_hardware_buffer.h" | 14 #include "content/common/device_sensors/device_orientation_hardware_buffer.h" |
| 17 | 15 |
| 18 namespace content { | 16 namespace content { |
| 19 | 17 |
| 20 namespace { | 18 namespace { |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 if (started_consumers_ & consumer_type) | 122 if (started_consumers_ & consumer_type) |
| 125 return true; | 123 return true; |
| 126 | 124 |
| 127 void* buffer = GetSharedMemoryBuffer(consumer_type); | 125 void* buffer = GetSharedMemoryBuffer(consumer_type); |
| 128 if (!buffer) | 126 if (!buffer) |
| 129 return false; | 127 return false; |
| 130 | 128 |
| 131 if (GetType() != FETCHER_TYPE_DEFAULT) { | 129 if (GetType() != FETCHER_TYPE_DEFAULT) { |
| 132 if (!InitAndStartPollingThreadIfNecessary()) | 130 if (!InitAndStartPollingThreadIfNecessary()) |
| 133 return false; | 131 return false; |
| 134 polling_thread_->task_runner()->PostTask( | 132 polling_thread_->message_loop()->PostTask( |
| 135 FROM_HERE, base::Bind(&PollingThread::AddConsumer, | 133 FROM_HERE, |
| 136 base::Unretained(polling_thread_.get()), | 134 base::Bind(&PollingThread::AddConsumer, |
| 137 consumer_type, buffer)); | 135 base::Unretained(polling_thread_.get()), |
| 136 consumer_type, buffer)); |
| 138 } else { | 137 } else { |
| 139 if (!Start(consumer_type, buffer)) | 138 if (!Start(consumer_type, buffer)) |
| 140 return false; | 139 return false; |
| 141 } | 140 } |
| 142 | 141 |
| 143 started_consumers_ |= consumer_type; | 142 started_consumers_ |= consumer_type; |
| 144 | 143 |
| 145 return true; | 144 return true; |
| 146 } | 145 } |
| 147 | 146 |
| 148 bool DataFetcherSharedMemoryBase::StopFetchingDeviceData( | 147 bool DataFetcherSharedMemoryBase::StopFetchingDeviceData( |
| 149 ConsumerType consumer_type) { | 148 ConsumerType consumer_type) { |
| 150 if (!(started_consumers_ & consumer_type)) | 149 if (!(started_consumers_ & consumer_type)) |
| 151 return true; | 150 return true; |
| 152 | 151 |
| 153 if (GetType() != FETCHER_TYPE_DEFAULT) { | 152 if (GetType() != FETCHER_TYPE_DEFAULT) { |
| 154 polling_thread_->task_runner()->PostTask( | 153 polling_thread_->message_loop()->PostTask( |
| 155 FROM_HERE, | 154 FROM_HERE, |
| 156 base::Bind(&PollingThread::RemoveConsumer, | 155 base::Bind(&PollingThread::RemoveConsumer, |
| 157 base::Unretained(polling_thread_.get()), consumer_type)); | 156 base::Unretained(polling_thread_.get()), |
| 157 consumer_type)); |
| 158 } else { | 158 } else { |
| 159 if (!Stop(consumer_type)) | 159 if (!Stop(consumer_type)) |
| 160 return false; | 160 return false; |
| 161 } | 161 } |
| 162 | 162 |
| 163 started_consumers_ ^= consumer_type; | 163 started_consumers_ ^= consumer_type; |
| 164 | 164 |
| 165 return true; | 165 return true; |
| 166 } | 166 } |
| 167 | 167 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 | 242 |
| 243 base::MessageLoop* DataFetcherSharedMemoryBase::GetPollingMessageLoop() const { | 243 base::MessageLoop* DataFetcherSharedMemoryBase::GetPollingMessageLoop() const { |
| 244 return polling_thread_ ? polling_thread_->message_loop() : nullptr; | 244 return polling_thread_ ? polling_thread_->message_loop() : nullptr; |
| 245 } | 245 } |
| 246 | 246 |
| 247 bool DataFetcherSharedMemoryBase::IsPollingTimerRunningForTesting() const { | 247 bool DataFetcherSharedMemoryBase::IsPollingTimerRunningForTesting() const { |
| 248 return polling_thread_ ? polling_thread_->IsTimerRunning() : false; | 248 return polling_thread_ ? polling_thread_->IsTimerRunning() : false; |
| 249 } | 249 } |
| 250 | 250 |
| 251 } // namespace content | 251 } // namespace content |
| OLD | NEW |