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
3 // found in the LICENSE file.
5 #include "content/browser/device_sensors/data_fetcher_shared_memory.h"
7 #include "base/logging.h"
8 #include "base/metrics/histogram.h"
12 bool SetMotionBuffer(content::DeviceMotionHardwareBuffer
* buffer
,
16 buffer
->seqlock
.WriteBegin();
17 buffer
->data
.allAvailableSensorsAreActive
= enabled
;
18 buffer
->seqlock
.WriteEnd();
22 bool SetOrientationBuffer(
23 content::DeviceOrientationHardwareBuffer
* buffer
, bool enabled
) {
26 buffer
->seqlock
.WriteBegin();
27 buffer
->data
.allAvailableSensorsAreActive
= enabled
;
28 buffer
->seqlock
.WriteEnd();
32 bool SetLightBuffer(content::DeviceLightHardwareBuffer
* buffer
,
36 buffer
->seqlock
.WriteBegin();
37 buffer
->data
.value
= lux
;
38 buffer
->seqlock
.WriteEnd();
46 DataFetcherSharedMemory::DataFetcherSharedMemory()
47 : motion_buffer_(nullptr),
48 orientation_buffer_(nullptr),
49 light_buffer_(nullptr) {
52 DataFetcherSharedMemory::~DataFetcherSharedMemory() {
55 bool DataFetcherSharedMemory::Start(ConsumerType consumer_type
, void* buffer
) {
58 switch (consumer_type
) {
59 case CONSUMER_TYPE_MOTION
:
60 motion_buffer_
= static_cast<DeviceMotionHardwareBuffer
*>(buffer
);
61 UMA_HISTOGRAM_BOOLEAN("InertialSensor.MotionDefaultAvailable", false);
62 return SetMotionBuffer(motion_buffer_
, true);
63 case CONSUMER_TYPE_ORIENTATION
:
65 static_cast<DeviceOrientationHardwareBuffer
*>(buffer
);
66 UMA_HISTOGRAM_BOOLEAN("InertialSensor.OrientationDefaultAvailable",
68 return SetOrientationBuffer(orientation_buffer_
, true);
69 case CONSUMER_TYPE_LIGHT
:
70 light_buffer_
= static_cast<DeviceLightHardwareBuffer
*>(buffer
);
71 return SetLightBuffer(light_buffer_
,
72 std::numeric_limits
<double>::infinity());
79 bool DataFetcherSharedMemory::Stop(ConsumerType consumer_type
) {
80 switch (consumer_type
) {
81 case CONSUMER_TYPE_MOTION
:
82 return SetMotionBuffer(motion_buffer_
, false);
83 case CONSUMER_TYPE_ORIENTATION
:
84 return SetOrientationBuffer(orientation_buffer_
, false);
85 case CONSUMER_TYPE_LIGHT
:
86 return SetLightBuffer(light_buffer_
, -1);
93 } // namespace content