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

Side by Side Diff: device/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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/device_sensors/data_fetcher_shared_memory.h" 5 #include "device/device_sensors/data_fetcher_shared_memory.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 9
10 namespace { 10 namespace {
11 11
12 bool SetMotionBuffer(content::DeviceMotionHardwareBuffer* buffer, 12 bool SetMotionBuffer(device::DeviceMotionHardwareBuffer* buffer, bool enabled) {
13 bool enabled) {
14 if (!buffer) 13 if (!buffer)
15 return false; 14 return false;
16 buffer->seqlock.WriteBegin(); 15 buffer->seqlock.WriteBegin();
17 buffer->data.allAvailableSensorsAreActive = enabled; 16 buffer->data.allAvailableSensorsAreActive = enabled;
18 buffer->seqlock.WriteEnd(); 17 buffer->seqlock.WriteEnd();
19 return true; 18 return true;
20 } 19 }
21 20
22 bool SetOrientationBuffer( 21 bool SetOrientationBuffer(device::DeviceOrientationHardwareBuffer* buffer,
23 content::DeviceOrientationHardwareBuffer* buffer, bool enabled) { 22 bool enabled) {
24 if (!buffer) 23 if (!buffer)
25 return false; 24 return false;
26 buffer->seqlock.WriteBegin(); 25 buffer->seqlock.WriteBegin();
27 buffer->data.allAvailableSensorsAreActive = enabled; 26 buffer->data.allAvailableSensorsAreActive = enabled;
28 buffer->seqlock.WriteEnd(); 27 buffer->seqlock.WriteEnd();
29 return true; 28 return true;
30 } 29 }
31 30
32 bool SetLightBuffer(content::DeviceLightHardwareBuffer* buffer, 31 bool SetLightBuffer(device::DeviceLightHardwareBuffer* buffer, double lux) {
33 double lux) {
34 if (!buffer) 32 if (!buffer)
35 return false; 33 return false;
36 buffer->seqlock.WriteBegin(); 34 buffer->seqlock.WriteBegin();
37 buffer->data.value = lux; 35 buffer->data.value = lux;
38 buffer->seqlock.WriteEnd(); 36 buffer->seqlock.WriteEnd();
39 return true; 37 return true;
40 } 38 }
41 39
42 } // namespace 40 } // namespace
43 41
44 namespace content { 42 namespace device {
45 43
46 DataFetcherSharedMemory::DataFetcherSharedMemory() 44 DataFetcherSharedMemory::DataFetcherSharedMemory()
47 : motion_buffer_(nullptr), 45 : motion_buffer_(nullptr),
48 orientation_buffer_(nullptr), 46 orientation_buffer_(nullptr),
49 light_buffer_(nullptr) { 47 light_buffer_(nullptr) {
50 } 48 }
51 49
52 DataFetcherSharedMemory::~DataFetcherSharedMemory() { 50 DataFetcherSharedMemory::~DataFetcherSharedMemory() {
53 } 51 }
54 52
55 bool DataFetcherSharedMemory::Start(ConsumerType consumer_type, void* buffer) { 53 bool DataFetcherSharedMemory::Start(ConsumerType consumer_type, void* buffer) {
56 DCHECK(buffer); 54 DCHECK(buffer);
57 55
58 switch (consumer_type) { 56 switch (consumer_type) {
59 case CONSUMER_TYPE_MOTION: 57 case CONSUMER_TYPE_MOTION:
60 motion_buffer_ = static_cast<DeviceMotionHardwareBuffer*>(buffer); 58 motion_buffer_ = static_cast<DeviceMotionHardwareBuffer*>(buffer);
61 UMA_HISTOGRAM_BOOLEAN("InertialSensor.MotionDefaultAvailable", false); 59 UMA_HISTOGRAM_BOOLEAN("InertialSensor.MotionDefaultAvailable", false);
62 return SetMotionBuffer(motion_buffer_, true); 60 return SetMotionBuffer(motion_buffer_, true);
63 case CONSUMER_TYPE_ORIENTATION: 61 case CONSUMER_TYPE_ORIENTATION:
64 orientation_buffer_ = 62 orientation_buffer_ =
65 static_cast<DeviceOrientationHardwareBuffer*>(buffer); 63 static_cast<DeviceOrientationHardwareBuffer*>(buffer);
66 UMA_HISTOGRAM_BOOLEAN("InertialSensor.OrientationDefaultAvailable", 64 UMA_HISTOGRAM_BOOLEAN("InertialSensor.OrientationDefaultAvailable",
67 false); 65 false);
68 return SetOrientationBuffer(orientation_buffer_, true); 66 return SetOrientationBuffer(orientation_buffer_, true);
69 case CONSUMER_TYPE_LIGHT: 67 case CONSUMER_TYPE_LIGHT:
70 light_buffer_ = static_cast<DeviceLightHardwareBuffer*>(buffer); 68 light_buffer_ = static_cast<DeviceLightHardwareBuffer*>(buffer);
71 return SetLightBuffer(light_buffer_, 69 return SetLightBuffer(light_buffer_,
72 std::numeric_limits<double>::infinity()); 70 std::numeric_limits<double>::infinity());
73 default: 71 default:
74 NOTREACHED(); 72 NOTREACHED();
75 } 73 }
76 return false; 74 return false;
77 } 75 }
78 76
79 bool DataFetcherSharedMemory::Stop(ConsumerType consumer_type) { 77 bool DataFetcherSharedMemory::Stop(ConsumerType consumer_type) {
80 switch (consumer_type) { 78 switch (consumer_type) {
81 case CONSUMER_TYPE_MOTION: 79 case CONSUMER_TYPE_MOTION:
82 return SetMotionBuffer(motion_buffer_, false); 80 return SetMotionBuffer(motion_buffer_, false);
83 case CONSUMER_TYPE_ORIENTATION: 81 case CONSUMER_TYPE_ORIENTATION:
84 return SetOrientationBuffer(orientation_buffer_, false); 82 return SetOrientationBuffer(orientation_buffer_, false);
85 case CONSUMER_TYPE_LIGHT: 83 case CONSUMER_TYPE_LIGHT:
86 return SetLightBuffer(light_buffer_, -1); 84 return SetLightBuffer(light_buffer_, -1);
87 default: 85 default:
88 NOTREACHED(); 86 NOTREACHED();
89 } 87 }
90 return false; 88 return false;
91 } 89 }
92 90
93 } // namespace content 91 } // namespace device
OLDNEW
« no previous file with comments | « device/device_sensors/data_fetcher_shared_memory_chromeos.cc ('k') | device/device_sensors/data_fetcher_shared_memory_mac.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698