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 "data_fetcher_shared_memory.h"
7 #include "base/logging.h"
8 #include "base/metrics/histogram.h"
12 static bool SetMotionBuffer(content::DeviceMotionHardwareBuffer* buffer,
16 buffer->seqlock.WriteBegin();
17 buffer->data.allAvailableSensorsAreActive = enabled;
18 buffer->seqlock.WriteEnd();
22 static bool SetOrientationBuffer(
23 content::DeviceOrientationHardwareBuffer* buffer, bool enabled) {
26 buffer->seqlock.WriteBegin();
27 buffer->data.allAvailableSensorsAreActive = enabled;
28 buffer->seqlock.WriteEnd();
36 DataFetcherSharedMemory::DataFetcherSharedMemory()
37 : motion_buffer_(NULL), orientation_buffer_(NULL) {
40 DataFetcherSharedMemory::~DataFetcherSharedMemory() {
43 bool DataFetcherSharedMemory::Start(ConsumerType consumer_type, void* buffer) {
46 switch (consumer_type) {
47 case CONSUMER_TYPE_MOTION:
48 motion_buffer_ = static_cast<DeviceMotionHardwareBuffer*>(buffer);
49 UMA_HISTOGRAM_BOOLEAN("InertialSensor.MotionDefaultAvailable", false);
50 return SetMotionBuffer(motion_buffer_, true);
51 case CONSUMER_TYPE_ORIENTATION:
53 static_cast<DeviceOrientationHardwareBuffer*>(buffer);
54 UMA_HISTOGRAM_BOOLEAN("InertialSensor.OrientationDefaultAvailable",
56 return SetOrientationBuffer(orientation_buffer_, true);
63 bool DataFetcherSharedMemory::Stop(ConsumerType consumer_type) {
64 switch (consumer_type) {
65 case CONSUMER_TYPE_MOTION:
66 return SetMotionBuffer(motion_buffer_, false);
67 case CONSUMER_TYPE_ORIENTATION:
68 return SetOrientationBuffer(orientation_buffer_, false);
75 } // namespace content