Change layout of app list items in experimental app list.
[chromium-blink-merge.git] / content / browser / device_sensors / data_fetcher_shared_memory_default.cc
blob457fd8d5b474eeebdeb985cd91ac114b5dfdc258
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"
10 namespace {
12 static bool SetMotionBuffer(content::DeviceMotionHardwareBuffer* buffer,
13 bool enabled) {
14 if (!buffer)
15 return false;
16 buffer->seqlock.WriteBegin();
17 buffer->data.allAvailableSensorsAreActive = enabled;
18 buffer->seqlock.WriteEnd();
19 return true;
22 static bool SetOrientationBuffer(
23 content::DeviceOrientationHardwareBuffer* buffer, bool enabled) {
24 if (!buffer)
25 return false;
26 buffer->seqlock.WriteBegin();
27 buffer->data.allAvailableSensorsAreActive = enabled;
28 buffer->seqlock.WriteEnd();
29 return true;
32 } // namespace
34 namespace content {
36 DataFetcherSharedMemory::DataFetcherSharedMemory()
37 : motion_buffer_(NULL), orientation_buffer_(NULL) {
40 DataFetcherSharedMemory::~DataFetcherSharedMemory() {
43 bool DataFetcherSharedMemory::Start(ConsumerType consumer_type, void* buffer) {
44 DCHECK(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:
52 orientation_buffer_ =
53 static_cast<DeviceOrientationHardwareBuffer*>(buffer);
54 UMA_HISTOGRAM_BOOLEAN("InertialSensor.OrientationDefaultAvailable",
55 false);
56 return SetOrientationBuffer(orientation_buffer_, true);
57 default:
58 NOTREACHED();
60 return false;
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);
69 default:
70 NOTREACHED();
72 return false;
75 } // namespace content