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 "device/sensors/data_fetcher_shared_memory_base.h" | 5 #include "device/sensors/data_fetcher_shared_memory_base.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <string.h> | 8 #include <string.h> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/location.h" | 11 #include "base/location.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
15 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
16 #include "base/threading/thread.h" | 16 #include "base/threading/thread.h" |
17 #include "base/timer/timer.h" | 17 #include "base/timer/timer.h" |
18 #include "device/sensors/public/cpp/device_light_hardware_buffer.h" | |
19 #include "device/sensors/public/cpp/device_motion_hardware_buffer.h" | 18 #include "device/sensors/public/cpp/device_motion_hardware_buffer.h" |
20 #include "device/sensors/public/cpp/device_orientation_hardware_buffer.h" | 19 #include "device/sensors/public/cpp/device_orientation_hardware_buffer.h" |
21 | 20 |
22 namespace device { | 21 namespace device { |
23 | 22 |
24 namespace { | 23 namespace { |
25 | 24 |
26 size_t GetConsumerSharedMemoryBufferSize(ConsumerType consumer_type) { | 25 size_t GetConsumerSharedMemoryBufferSize(ConsumerType consumer_type) { |
27 switch (consumer_type) { | 26 switch (consumer_type) { |
28 case CONSUMER_TYPE_MOTION: | 27 case CONSUMER_TYPE_MOTION: |
29 return sizeof(DeviceMotionHardwareBuffer); | 28 return sizeof(DeviceMotionHardwareBuffer); |
30 case CONSUMER_TYPE_ORIENTATION: | 29 case CONSUMER_TYPE_ORIENTATION: |
31 case CONSUMER_TYPE_ORIENTATION_ABSOLUTE: | 30 case CONSUMER_TYPE_ORIENTATION_ABSOLUTE: |
32 return sizeof(DeviceOrientationHardwareBuffer); | 31 return sizeof(DeviceOrientationHardwareBuffer); |
33 case CONSUMER_TYPE_LIGHT: | |
34 return sizeof(DeviceLightHardwareBuffer); | |
35 default: | 32 default: |
36 NOTREACHED(); | 33 NOTREACHED(); |
37 } | 34 } |
38 return 0; | 35 return 0; |
39 } | 36 } |
40 | 37 |
41 } // namespace | 38 } // namespace |
42 | 39 |
43 class DataFetcherSharedMemoryBase::PollingThread : public base::Thread { | 40 class DataFetcherSharedMemoryBase::PollingThread : public base::Thread { |
44 public: | 41 public: |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 | 164 |
168 started_consumers_ ^= consumer_type; | 165 started_consumers_ ^= consumer_type; |
169 | 166 |
170 return true; | 167 return true; |
171 } | 168 } |
172 | 169 |
173 void DataFetcherSharedMemoryBase::Shutdown() { | 170 void DataFetcherSharedMemoryBase::Shutdown() { |
174 StopFetchingDeviceData(CONSUMER_TYPE_MOTION); | 171 StopFetchingDeviceData(CONSUMER_TYPE_MOTION); |
175 StopFetchingDeviceData(CONSUMER_TYPE_ORIENTATION); | 172 StopFetchingDeviceData(CONSUMER_TYPE_ORIENTATION); |
176 StopFetchingDeviceData(CONSUMER_TYPE_ORIENTATION_ABSOLUTE); | 173 StopFetchingDeviceData(CONSUMER_TYPE_ORIENTATION_ABSOLUTE); |
177 StopFetchingDeviceData(CONSUMER_TYPE_LIGHT); | |
178 | 174 |
179 // Ensure that the polling thread stops before entering the destructor of the | 175 // Ensure that the polling thread stops before entering the destructor of the |
180 // subclass, as the stopping of the polling thread causes tasks to execute | 176 // subclass, as the stopping of the polling thread causes tasks to execute |
181 // that call virtual methods of this class, which can cause crashes if they | 177 // that call virtual methods of this class, which can cause crashes if they |
182 // execute while (or after) the subclass is being torn down. | 178 // execute while (or after) the subclass is being torn down. |
183 if (polling_thread_) | 179 if (polling_thread_) |
184 polling_thread_->Stop(); | 180 polling_thread_->Stop(); |
185 } | 181 } |
186 | 182 |
187 mojo::ScopedSharedBufferHandle | 183 mojo::ScopedSharedBufferHandle |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 | 237 |
242 base::MessageLoop* DataFetcherSharedMemoryBase::GetPollingMessageLoop() const { | 238 base::MessageLoop* DataFetcherSharedMemoryBase::GetPollingMessageLoop() const { |
243 return polling_thread_ ? polling_thread_->message_loop() : nullptr; | 239 return polling_thread_ ? polling_thread_->message_loop() : nullptr; |
244 } | 240 } |
245 | 241 |
246 bool DataFetcherSharedMemoryBase::IsPollingTimerRunningForTesting() const { | 242 bool DataFetcherSharedMemoryBase::IsPollingTimerRunningForTesting() const { |
247 return polling_thread_ ? polling_thread_->IsTimerRunning() : false; | 243 return polling_thread_ ? polling_thread_->IsTimerRunning() : false; |
248 } | 244 } |
249 | 245 |
250 } // namespace device | 246 } // namespace device |
OLD | NEW |