Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(84)

Side by Side Diff: content/browser/device_sensors/data_fetcher_shared_memory_mac.cc

Issue 2123653003: Remove calls to MessageLoop::current() in content. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "content/browser/device_sensors/ambient_light_mac.h" 12 #include "content/browser/device_sensors/ambient_light_mac.h"
12 #include "third_party/sudden_motion_sensor/sudden_motion_sensor_mac.h" 13 #include "third_party/sudden_motion_sensor/sudden_motion_sensor_mac.h"
13 14
14 namespace { 15 namespace {
15 16
16 const double kMeanGravity = 9.80665; 17 const double kMeanGravity = 9.80665;
17 18
18 double LMUvalueToLux(uint64_t raw_value) { 19 double LMUvalueToLux(uint64_t raw_value) {
19 // Conversion formula from regression. 20 // Conversion formula from regression.
20 // https://bugzilla.mozilla.org/show_bug.cgi?id=793728 21 // https://bugzilla.mozilla.org/show_bug.cgi?id=793728
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 135
135 namespace content { 136 namespace content {
136 137
137 DataFetcherSharedMemory::DataFetcherSharedMemory() { 138 DataFetcherSharedMemory::DataFetcherSharedMemory() {
138 } 139 }
139 140
140 DataFetcherSharedMemory::~DataFetcherSharedMemory() { 141 DataFetcherSharedMemory::~DataFetcherSharedMemory() {
141 } 142 }
142 143
143 void DataFetcherSharedMemory::Fetch(unsigned consumer_bitmask) { 144 void DataFetcherSharedMemory::Fetch(unsigned consumer_bitmask) {
144 DCHECK(base::MessageLoop::current() == GetPollingMessageLoop()); 145 DCHECK(GetPollingMessageLoop()->task_runner()->BelongsToCurrentThread());
145 DCHECK(consumer_bitmask & CONSUMER_TYPE_ORIENTATION || 146 DCHECK(consumer_bitmask & CONSUMER_TYPE_ORIENTATION ||
146 consumer_bitmask & CONSUMER_TYPE_MOTION || 147 consumer_bitmask & CONSUMER_TYPE_MOTION ||
147 consumer_bitmask & CONSUMER_TYPE_LIGHT); 148 consumer_bitmask & CONSUMER_TYPE_LIGHT);
148 149
149 if (consumer_bitmask & CONSUMER_TYPE_ORIENTATION) 150 if (consumer_bitmask & CONSUMER_TYPE_ORIENTATION)
150 FetchOrientation(sudden_motion_sensor_.get(), orientation_buffer_); 151 FetchOrientation(sudden_motion_sensor_.get(), orientation_buffer_);
151 if (consumer_bitmask & CONSUMER_TYPE_MOTION) 152 if (consumer_bitmask & CONSUMER_TYPE_MOTION)
152 FetchMotion(sudden_motion_sensor_.get(), motion_buffer_); 153 FetchMotion(sudden_motion_sensor_.get(), motion_buffer_);
153 if (consumer_bitmask & CONSUMER_TYPE_LIGHT) 154 if (consumer_bitmask & CONSUMER_TYPE_LIGHT)
154 FetchLight(ambient_light_sensor_.get(), light_buffer_); 155 FetchLight(ambient_light_sensor_.get(), light_buffer_);
155 } 156 }
156 157
157 DataFetcherSharedMemory::FetcherType DataFetcherSharedMemory::GetType() const { 158 DataFetcherSharedMemory::FetcherType DataFetcherSharedMemory::GetType() const {
158 return FETCHER_TYPE_POLLING_CALLBACK; 159 return FETCHER_TYPE_POLLING_CALLBACK;
159 } 160 }
160 161
161 bool DataFetcherSharedMemory::Start(ConsumerType consumer_type, void* buffer) { 162 bool DataFetcherSharedMemory::Start(ConsumerType consumer_type, void* buffer) {
162 DCHECK(base::MessageLoop::current() == GetPollingMessageLoop()); 163 DCHECK(GetPollingMessageLoop()->task_runner()->BelongsToCurrentThread());
163 DCHECK(buffer); 164 DCHECK(buffer);
164 165
165 switch (consumer_type) { 166 switch (consumer_type) {
166 case CONSUMER_TYPE_MOTION: { 167 case CONSUMER_TYPE_MOTION: {
167 if (!sudden_motion_sensor_) 168 if (!sudden_motion_sensor_)
168 sudden_motion_sensor_.reset(SuddenMotionSensor::Create()); 169 sudden_motion_sensor_.reset(SuddenMotionSensor::Create());
169 bool sudden_motion_sensor_available = 170 bool sudden_motion_sensor_available =
170 sudden_motion_sensor_.get() != nullptr; 171 sudden_motion_sensor_.get() != nullptr;
171 172
172 motion_buffer_ = static_cast<DeviceMotionHardwareBuffer*>(buffer); 173 motion_buffer_ = static_cast<DeviceMotionHardwareBuffer*>(buffer);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 } 229 }
229 return ambient_light_sensor_available; 230 return ambient_light_sensor_available;
230 } 231 }
231 default: 232 default:
232 NOTREACHED(); 233 NOTREACHED();
233 } 234 }
234 return false; 235 return false;
235 } 236 }
236 237
237 bool DataFetcherSharedMemory::Stop(ConsumerType consumer_type) { 238 bool DataFetcherSharedMemory::Stop(ConsumerType consumer_type) {
238 DCHECK(base::MessageLoop::current() == GetPollingMessageLoop()); 239 DCHECK(GetPollingMessageLoop()->task_runner()->BelongsToCurrentThread());
239 240
240 switch (consumer_type) { 241 switch (consumer_type) {
241 case CONSUMER_TYPE_MOTION: 242 case CONSUMER_TYPE_MOTION:
242 if (motion_buffer_) { 243 if (motion_buffer_) {
243 motion_buffer_->seqlock.WriteBegin(); 244 motion_buffer_->seqlock.WriteBegin();
244 motion_buffer_->data.allAvailableSensorsAreActive = false; 245 motion_buffer_->data.allAvailableSensorsAreActive = false;
245 motion_buffer_->seqlock.WriteEnd(); 246 motion_buffer_->seqlock.WriteEnd();
246 motion_buffer_ = nullptr; 247 motion_buffer_ = nullptr;
247 } 248 }
248 return true; 249 return true;
(...skipping 21 matching lines...) Expand all
270 light_buffer_ = nullptr; 271 light_buffer_ = nullptr;
271 } 272 }
272 return true; 273 return true;
273 default: 274 default:
274 NOTREACHED(); 275 NOTREACHED();
275 } 276 }
276 return false; 277 return false;
277 } 278 }
278 279
279 } // namespace content 280 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698