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

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

Issue 754963006: Windows: Ambient Light API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 9 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
« no previous file with comments | « content/browser/device_sensors/data_fetcher_shared_memory.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "data_fetcher_shared_memory.h" 5 #include "data_fetcher_shared_memory.h"
6 6
7 #include <GuidDef.h> 7 #include <GuidDef.h>
8 #include <InitGuid.h> 8 #include <InitGuid.h>
9 #include <PortableDeviceTypes.h> 9 #include <PortableDeviceTypes.h>
10 #include <Sensors.h> 10 #include <Sensors.h>
11 11
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/metrics/histogram.h" 13 #include "base/metrics/histogram.h"
14 #include "base/win/iunknown_impl.h" 14 #include "base/win/iunknown_impl.h"
15 #include "base/win/windows_version.h" 15 #include "base/win/windows_version.h"
16 16
17 namespace { 17 namespace {
18 18
19 const double kMeanGravity = 9.80665; 19 const double kMeanGravity = 9.80665;
20 20
21 static bool SetLightBuffer(content::DeviceLightHardwareBuffer* buffer,
timvolodine 2015/03/02 17:39:58 no need for static
riju_ 2015/03/03 09:53:55 Done.
22 double lux) {
23 if (!buffer)
24 return false;
25 buffer->seqlock.WriteBegin();
26 buffer->data.value = lux;
27 buffer->seqlock.WriteEnd();
28 return true;
timvolodine 2015/03/02 17:39:58 do you need to return anything at all? the result
riju_ 2015/03/03 09:53:55 Done.
29 }
30
21 } // namespace 31 } // namespace
22 32
23 33
24 namespace content { 34 namespace content {
25 35
26 class DataFetcherSharedMemory::SensorEventSink 36 class DataFetcherSharedMemory::SensorEventSink
27 : public ISensorEvents, public base::win::IUnknownImpl { 37 : public ISensorEvents, public base::win::IUnknownImpl {
28 public: 38 public:
29 SensorEventSink() {} 39 SensorEventSink() {}
30 virtual ~SensorEventSink() {} 40 virtual ~SensorEventSink() {}
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 225
216 return true; 226 return true;
217 } 227 }
218 228
219 private: 229 private:
220 DeviceMotionHardwareBuffer* const buffer_; 230 DeviceMotionHardwareBuffer* const buffer_;
221 231
222 DISALLOW_COPY_AND_ASSIGN(SensorEventSinkMotion); 232 DISALLOW_COPY_AND_ASSIGN(SensorEventSinkMotion);
223 }; 233 };
224 234
235 class DataFetcherSharedMemory::SensorEventSinkLight
236 : public DataFetcherSharedMemory::SensorEventSink {
237 public:
238 explicit SensorEventSinkLight(DeviceLightHardwareBuffer* const buffer)
239 : buffer_(buffer) {}
240 virtual ~SensorEventSinkLight() {}
241
242 protected:
243 virtual bool UpdateSharedMemoryBuffer(ISensor* sensor,
244 ISensorDataReport* new_data) override {
245 double lux;
246 bool has_lux;
247
248 GetSensorValue(SENSOR_DATA_TYPE_LIGHT_LEVEL_LUX, new_data, &lux, &has_lux);
timvolodine 2015/03/02 17:39:58 has_lux does not seem be used after the call. shou
riju_ 2015/03/03 09:53:55 Done. returning early if valid no lux value is fou
249
250 SetLightBuffer(buffer_, lux);
251
252 return true;
253 }
254
255 private:
256 DeviceLightHardwareBuffer* const buffer_;
257
258 DISALLOW_COPY_AND_ASSIGN(SensorEventSinkLight);
259 };
260
225 DataFetcherSharedMemory::DataFetcherSharedMemory() 261 DataFetcherSharedMemory::DataFetcherSharedMemory()
226 : motion_buffer_(nullptr), orientation_buffer_(nullptr) { 262 : motion_buffer_(nullptr),
263 orientation_buffer_(nullptr),
264 light_buffer_(nullptr) {
227 } 265 }
228 266
229 DataFetcherSharedMemory::~DataFetcherSharedMemory() { 267 DataFetcherSharedMemory::~DataFetcherSharedMemory() {
230 } 268 }
231 269
232 DataFetcherSharedMemory::FetcherType DataFetcherSharedMemory::GetType() const { 270 DataFetcherSharedMemory::FetcherType DataFetcherSharedMemory::GetType() const {
233 return FETCHER_TYPE_SEPARATE_THREAD; 271 return FETCHER_TYPE_SEPARATE_THREAD;
234 } 272 }
235 273
236 bool DataFetcherSharedMemory::Start(ConsumerType consumer_type, void* buffer) { 274 bool DataFetcherSharedMemory::Start(ConsumerType consumer_type, void* buffer) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 if (accelerometer_available || gyrometer_available) { 308 if (accelerometer_available || gyrometer_available) {
271 motion_buffer_->seqlock.WriteBegin(); 309 motion_buffer_->seqlock.WriteBegin();
272 motion_buffer_->data.interval = GetInterval().InMilliseconds(); 310 motion_buffer_->data.interval = GetInterval().InMilliseconds();
273 motion_buffer_->seqlock.WriteEnd(); 311 motion_buffer_->seqlock.WriteEnd();
274 return true; 312 return true;
275 } 313 }
276 // if no sensors are available set buffer to ready, to fire null-events. 314 // if no sensors are available set buffer to ready, to fire null-events.
277 SetBufferAvailableState(consumer_type, true); 315 SetBufferAvailableState(consumer_type, true);
278 } 316 }
279 break; 317 break;
318 case CONSUMER_TYPE_LIGHT:
timvolodine 2015/03/02 17:39:58 alignment as with above cases
riju_ 2015/03/03 09:53:55 Done.
319 {
320 light_buffer_ = static_cast<DeviceLightHardwareBuffer*>(buffer);
321 scoped_refptr<SensorEventSink> sink(
322 new SensorEventSinkLight(light_buffer_));
323 bool sensor_light_available = RegisterForSensor(
324 SENSOR_TYPE_AMBIENT_LIGHT, sensor_light_.Receive(), sink);
325 if (sensor_light_available)
timvolodine 2015/03/02 17:39:58 what's the value of the buffer? should it be initi
riju_ 2015/03/03 09:53:55 Done.
326 return true;
327
328 // if no sensors are available, fire an Infinity event.
329 SetLightBuffer(light_buffer_, std::numeric_limits<double>::infinity());
330 }
331 break;
280 default: 332 default:
281 NOTREACHED(); 333 NOTREACHED();
282 } 334 }
283 return false; 335 return false;
284 } 336 }
285 337
286 bool DataFetcherSharedMemory::Stop(ConsumerType consumer_type) { 338 bool DataFetcherSharedMemory::Stop(ConsumerType consumer_type) {
287 DisableSensors(consumer_type); 339 DisableSensors(consumer_type);
288 SetBufferAvailableState(consumer_type, false); 340 SetBufferAvailableState(consumer_type, false);
289 switch (consumer_type) { 341 switch (consumer_type) {
290 case CONSUMER_TYPE_ORIENTATION: 342 case CONSUMER_TYPE_ORIENTATION:
291 orientation_buffer_ = nullptr; 343 orientation_buffer_ = nullptr;
292 return true; 344 return true;
293 case CONSUMER_TYPE_MOTION: 345 case CONSUMER_TYPE_MOTION:
294 motion_buffer_ = nullptr; 346 motion_buffer_ = nullptr;
295 return true; 347 return true;
348 case CONSUMER_TYPE_LIGHT:
349 SetLightBuffer(light_buffer_, -1);
timvolodine 2015/03/02 17:39:58 also light_buffer = nullptr?
riju_ 2015/03/03 09:53:55 Done.
350 return true;
296 default: 351 default:
297 NOTREACHED(); 352 NOTREACHED();
298 } 353 }
299 return false; 354 return false;
300 } 355 }
301 356
302 bool DataFetcherSharedMemory::RegisterForSensor( 357 bool DataFetcherSharedMemory::RegisterForSensor(
303 REFSENSOR_TYPE_ID sensor_type, 358 REFSENSOR_TYPE_ID sensor_type,
304 ISensor** sensor, 359 ISensor** sensor,
305 scoped_refptr<SensorEventSink> event_sink) { 360 scoped_refptr<SensorEventSink> event_sink) {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 case CONSUMER_TYPE_MOTION: 416 case CONSUMER_TYPE_MOTION:
362 if (sensor_accelerometer_.get()) { 417 if (sensor_accelerometer_.get()) {
363 sensor_accelerometer_->SetEventSink(nullptr); 418 sensor_accelerometer_->SetEventSink(nullptr);
364 sensor_accelerometer_.Release(); 419 sensor_accelerometer_.Release();
365 } 420 }
366 if (sensor_gyrometer_.get()) { 421 if (sensor_gyrometer_.get()) {
367 sensor_gyrometer_->SetEventSink(nullptr); 422 sensor_gyrometer_->SetEventSink(nullptr);
368 sensor_gyrometer_.Release(); 423 sensor_gyrometer_.Release();
369 } 424 }
370 break; 425 break;
426 case CONSUMER_TYPE_LIGHT:
427 if (sensor_light_.get()) {
428 sensor_light_->SetEventSink(nullptr);
429 sensor_light_.Release();
430 }
431 break;
371 default: 432 default:
372 NOTREACHED(); 433 NOTREACHED();
373 } 434 }
374 } 435 }
375 436
376 void DataFetcherSharedMemory::SetBufferAvailableState( 437 void DataFetcherSharedMemory::SetBufferAvailableState(
377 ConsumerType consumer_type, bool enabled) { 438 ConsumerType consumer_type, bool enabled) {
378 switch(consumer_type) { 439 switch(consumer_type) {
379 case CONSUMER_TYPE_ORIENTATION: 440 case CONSUMER_TYPE_ORIENTATION:
380 if (orientation_buffer_) { 441 if (orientation_buffer_) {
381 orientation_buffer_->seqlock.WriteBegin(); 442 orientation_buffer_->seqlock.WriteBegin();
382 orientation_buffer_->data.allAvailableSensorsAreActive = enabled; 443 orientation_buffer_->data.allAvailableSensorsAreActive = enabled;
383 orientation_buffer_->seqlock.WriteEnd(); 444 orientation_buffer_->seqlock.WriteEnd();
384 } 445 }
385 break; 446 break;
386 case CONSUMER_TYPE_MOTION: 447 case CONSUMER_TYPE_MOTION:
387 if (motion_buffer_) { 448 if (motion_buffer_) {
388 motion_buffer_->seqlock.WriteBegin(); 449 motion_buffer_->seqlock.WriteBegin();
389 motion_buffer_->data.allAvailableSensorsAreActive = enabled; 450 motion_buffer_->data.allAvailableSensorsAreActive = enabled;
390 motion_buffer_->seqlock.WriteEnd(); 451 motion_buffer_->seqlock.WriteEnd();
391 } 452 }
392 break; 453 break;
393 default: 454 default:
394 NOTREACHED(); 455 NOTREACHED();
395 } 456 }
396 } 457 }
397 458
398 } // namespace content 459 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/device_sensors/data_fetcher_shared_memory.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698