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

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

Issue 1164563003: Extract device_sensors to /device via Mojofication (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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
OLDNEW
(Empty)
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 "content/browser/device_sensors/data_fetcher_shared_memory.h"
6
7 #include "base/logging.h"
8 #include "base/metrics/histogram.h"
9
10 namespace {
11
12 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 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 bool SetLightBuffer(content::DeviceLightHardwareBuffer* buffer,
33 double lux) {
34 if (!buffer)
35 return false;
36 buffer->seqlock.WriteBegin();
37 buffer->data.value = lux;
38 buffer->seqlock.WriteEnd();
39 return true;
40 }
41
42 } // namespace
43
44 namespace content {
45
46 DataFetcherSharedMemory::DataFetcherSharedMemory()
47 : motion_buffer_(nullptr),
48 orientation_buffer_(nullptr),
49 light_buffer_(nullptr) {
50 }
51
52 DataFetcherSharedMemory::~DataFetcherSharedMemory() {
53 }
54
55 bool DataFetcherSharedMemory::Start(ConsumerType consumer_type, void* buffer) {
56 DCHECK(buffer);
57
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:
64 orientation_buffer_ =
65 static_cast<DeviceOrientationHardwareBuffer*>(buffer);
66 UMA_HISTOGRAM_BOOLEAN("InertialSensor.OrientationDefaultAvailable",
67 false);
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());
73 default:
74 NOTREACHED();
75 }
76 return false;
77 }
78
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);
87 default:
88 NOTREACHED();
89 }
90 return false;
91 }
92
93 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698