Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / content / browser / device_sensors / data_fetcher_shared_memory_default.cc
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.
4
5 #include "data_fetcher_shared_memory.h"
6
7 #include "base/logging.h"
8 #include "base/metrics/histogram.h"
9
10 namespace {
11
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;
20 }
21
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;
30 }
31
32 }  // namespace
33
34 namespace content {
35
36 DataFetcherSharedMemory::DataFetcherSharedMemory()
37     : motion_buffer_(NULL), orientation_buffer_(NULL) {
38 }
39
40 DataFetcherSharedMemory::~DataFetcherSharedMemory() {
41 }
42
43 bool DataFetcherSharedMemory::Start(ConsumerType consumer_type, void* buffer) {
44   DCHECK(buffer);
45
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();
59   }
60   return false;
61 }
62
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();
71   }
72   return false;
73 }
74
75 }  // namespace content