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.h" | 5 #include "content/browser/device_sensors/data_fetcher_shared_memory.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
11 #include "base/single_thread_task_runner.h" | |
12 #include "content/browser/device_sensors/ambient_light_mac.h" | 11 #include "content/browser/device_sensors/ambient_light_mac.h" |
13 #include "third_party/sudden_motion_sensor/sudden_motion_sensor_mac.h" | 12 #include "third_party/sudden_motion_sensor/sudden_motion_sensor_mac.h" |
14 | 13 |
15 namespace { | 14 namespace { |
16 | 15 |
17 const double kMeanGravity = 9.80665; | 16 const double kMeanGravity = 9.80665; |
18 | 17 |
19 double LMUvalueToLux(uint64_t raw_value) { | 18 double LMUvalueToLux(uint64_t raw_value) { |
20 // Conversion formula from regression. | 19 // Conversion formula from regression. |
21 // https://bugzilla.mozilla.org/show_bug.cgi?id=793728 | 20 // https://bugzilla.mozilla.org/show_bug.cgi?id=793728 |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 | 134 |
136 namespace content { | 135 namespace content { |
137 | 136 |
138 DataFetcherSharedMemory::DataFetcherSharedMemory() { | 137 DataFetcherSharedMemory::DataFetcherSharedMemory() { |
139 } | 138 } |
140 | 139 |
141 DataFetcherSharedMemory::~DataFetcherSharedMemory() { | 140 DataFetcherSharedMemory::~DataFetcherSharedMemory() { |
142 } | 141 } |
143 | 142 |
144 void DataFetcherSharedMemory::Fetch(unsigned consumer_bitmask) { | 143 void DataFetcherSharedMemory::Fetch(unsigned consumer_bitmask) { |
145 DCHECK(GetPollingMessageLoop()->task_runner()->BelongsToCurrentThread()); | 144 DCHECK(base::MessageLoop::current() == GetPollingMessageLoop()); |
146 DCHECK(consumer_bitmask & CONSUMER_TYPE_ORIENTATION || | 145 DCHECK(consumer_bitmask & CONSUMER_TYPE_ORIENTATION || |
147 consumer_bitmask & CONSUMER_TYPE_MOTION || | 146 consumer_bitmask & CONSUMER_TYPE_MOTION || |
148 consumer_bitmask & CONSUMER_TYPE_LIGHT); | 147 consumer_bitmask & CONSUMER_TYPE_LIGHT); |
149 | 148 |
150 if (consumer_bitmask & CONSUMER_TYPE_ORIENTATION) | 149 if (consumer_bitmask & CONSUMER_TYPE_ORIENTATION) |
151 FetchOrientation(sudden_motion_sensor_.get(), orientation_buffer_); | 150 FetchOrientation(sudden_motion_sensor_.get(), orientation_buffer_); |
152 if (consumer_bitmask & CONSUMER_TYPE_MOTION) | 151 if (consumer_bitmask & CONSUMER_TYPE_MOTION) |
153 FetchMotion(sudden_motion_sensor_.get(), motion_buffer_); | 152 FetchMotion(sudden_motion_sensor_.get(), motion_buffer_); |
154 if (consumer_bitmask & CONSUMER_TYPE_LIGHT) | 153 if (consumer_bitmask & CONSUMER_TYPE_LIGHT) |
155 FetchLight(ambient_light_sensor_.get(), light_buffer_); | 154 FetchLight(ambient_light_sensor_.get(), light_buffer_); |
156 } | 155 } |
157 | 156 |
158 DataFetcherSharedMemory::FetcherType DataFetcherSharedMemory::GetType() const { | 157 DataFetcherSharedMemory::FetcherType DataFetcherSharedMemory::GetType() const { |
159 return FETCHER_TYPE_POLLING_CALLBACK; | 158 return FETCHER_TYPE_POLLING_CALLBACK; |
160 } | 159 } |
161 | 160 |
162 bool DataFetcherSharedMemory::Start(ConsumerType consumer_type, void* buffer) { | 161 bool DataFetcherSharedMemory::Start(ConsumerType consumer_type, void* buffer) { |
163 DCHECK(GetPollingMessageLoop()->task_runner()->BelongsToCurrentThread()); | 162 DCHECK(base::MessageLoop::current() == GetPollingMessageLoop()); |
164 DCHECK(buffer); | 163 DCHECK(buffer); |
165 | 164 |
166 switch (consumer_type) { | 165 switch (consumer_type) { |
167 case CONSUMER_TYPE_MOTION: { | 166 case CONSUMER_TYPE_MOTION: { |
168 if (!sudden_motion_sensor_) | 167 if (!sudden_motion_sensor_) |
169 sudden_motion_sensor_.reset(SuddenMotionSensor::Create()); | 168 sudden_motion_sensor_.reset(SuddenMotionSensor::Create()); |
170 bool sudden_motion_sensor_available = | 169 bool sudden_motion_sensor_available = |
171 sudden_motion_sensor_.get() != nullptr; | 170 sudden_motion_sensor_.get() != nullptr; |
172 | 171 |
173 motion_buffer_ = static_cast<DeviceMotionHardwareBuffer*>(buffer); | 172 motion_buffer_ = static_cast<DeviceMotionHardwareBuffer*>(buffer); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 } | 228 } |
230 return ambient_light_sensor_available; | 229 return ambient_light_sensor_available; |
231 } | 230 } |
232 default: | 231 default: |
233 NOTREACHED(); | 232 NOTREACHED(); |
234 } | 233 } |
235 return false; | 234 return false; |
236 } | 235 } |
237 | 236 |
238 bool DataFetcherSharedMemory::Stop(ConsumerType consumer_type) { | 237 bool DataFetcherSharedMemory::Stop(ConsumerType consumer_type) { |
239 DCHECK(GetPollingMessageLoop()->task_runner()->BelongsToCurrentThread()); | 238 DCHECK(base::MessageLoop::current() == GetPollingMessageLoop()); |
240 | 239 |
241 switch (consumer_type) { | 240 switch (consumer_type) { |
242 case CONSUMER_TYPE_MOTION: | 241 case CONSUMER_TYPE_MOTION: |
243 if (motion_buffer_) { | 242 if (motion_buffer_) { |
244 motion_buffer_->seqlock.WriteBegin(); | 243 motion_buffer_->seqlock.WriteBegin(); |
245 motion_buffer_->data.allAvailableSensorsAreActive = false; | 244 motion_buffer_->data.allAvailableSensorsAreActive = false; |
246 motion_buffer_->seqlock.WriteEnd(); | 245 motion_buffer_->seqlock.WriteEnd(); |
247 motion_buffer_ = nullptr; | 246 motion_buffer_ = nullptr; |
248 } | 247 } |
249 return true; | 248 return true; |
(...skipping 21 matching lines...) Expand all Loading... |
271 light_buffer_ = nullptr; | 270 light_buffer_ = nullptr; |
272 } | 271 } |
273 return true; | 272 return true; |
274 default: | 273 default: |
275 NOTREACHED(); | 274 NOTREACHED(); |
276 } | 275 } |
277 return false; | 276 return false; |
278 } | 277 } |
279 | 278 |
280 } // namespace content | 279 } // namespace content |
OLD | NEW |