OLD | NEW |
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 "data_fetcher_shared_memory.h" | 5 #include "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 { |
(...skipping 11 matching lines...) Expand all Loading... |
22 static bool SetOrientationBuffer( | 22 static bool SetOrientationBuffer( |
23 content::DeviceOrientationHardwareBuffer* buffer, bool enabled) { | 23 content::DeviceOrientationHardwareBuffer* buffer, bool enabled) { |
24 if (!buffer) | 24 if (!buffer) |
25 return false; | 25 return false; |
26 buffer->seqlock.WriteBegin(); | 26 buffer->seqlock.WriteBegin(); |
27 buffer->data.allAvailableSensorsAreActive = enabled; | 27 buffer->data.allAvailableSensorsAreActive = enabled; |
28 buffer->seqlock.WriteEnd(); | 28 buffer->seqlock.WriteEnd(); |
29 return true; | 29 return true; |
30 } | 30 } |
31 | 31 |
| 32 static 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 |
32 } // namespace | 42 } // namespace |
33 | 43 |
34 namespace content { | 44 namespace content { |
35 | 45 |
36 DataFetcherSharedMemory::DataFetcherSharedMemory() | 46 DataFetcherSharedMemory::DataFetcherSharedMemory() |
37 : motion_buffer_(NULL), orientation_buffer_(NULL) { | 47 : motion_buffer_(NULL), orientation_buffer_(NULL), light_buffer_(NULL) { |
38 } | 48 } |
39 | 49 |
40 DataFetcherSharedMemory::~DataFetcherSharedMemory() { | 50 DataFetcherSharedMemory::~DataFetcherSharedMemory() { |
41 } | 51 } |
42 | 52 |
43 bool DataFetcherSharedMemory::Start(ConsumerType consumer_type, void* buffer) { | 53 bool DataFetcherSharedMemory::Start(ConsumerType consumer_type, void* buffer) { |
44 DCHECK(buffer); | 54 DCHECK(buffer); |
45 | 55 |
46 switch (consumer_type) { | 56 switch (consumer_type) { |
47 case CONSUMER_TYPE_MOTION: | 57 case CONSUMER_TYPE_MOTION: |
48 motion_buffer_ = static_cast<DeviceMotionHardwareBuffer*>(buffer); | 58 motion_buffer_ = static_cast<DeviceMotionHardwareBuffer*>(buffer); |
49 UMA_HISTOGRAM_BOOLEAN("InertialSensor.MotionDefaultAvailable", false); | 59 UMA_HISTOGRAM_BOOLEAN("InertialSensor.MotionDefaultAvailable", false); |
50 return SetMotionBuffer(motion_buffer_, true); | 60 return SetMotionBuffer(motion_buffer_, true); |
51 case CONSUMER_TYPE_ORIENTATION: | 61 case CONSUMER_TYPE_ORIENTATION: |
52 orientation_buffer_ = | 62 orientation_buffer_ = |
53 static_cast<DeviceOrientationHardwareBuffer*>(buffer); | 63 static_cast<DeviceOrientationHardwareBuffer*>(buffer); |
54 UMA_HISTOGRAM_BOOLEAN("InertialSensor.OrientationDefaultAvailable", | 64 UMA_HISTOGRAM_BOOLEAN("InertialSensor.OrientationDefaultAvailable", |
55 false); | 65 false); |
56 return SetOrientationBuffer(orientation_buffer_, true); | 66 return SetOrientationBuffer(orientation_buffer_, true); |
| 67 case CONSUMER_TYPE_LIGHT: |
| 68 light_buffer_ = static_cast<DeviceLightHardwareBuffer*>(buffer); |
| 69 return SetLightBuffer(light_buffer_, |
| 70 std::numeric_limits<double>::infinity()); |
57 default: | 71 default: |
58 NOTREACHED(); | 72 NOTREACHED(); |
59 } | 73 } |
60 return false; | 74 return false; |
61 } | 75 } |
62 | 76 |
63 bool DataFetcherSharedMemory::Stop(ConsumerType consumer_type) { | 77 bool DataFetcherSharedMemory::Stop(ConsumerType consumer_type) { |
64 switch (consumer_type) { | 78 switch (consumer_type) { |
65 case CONSUMER_TYPE_MOTION: | 79 case CONSUMER_TYPE_MOTION: |
66 return SetMotionBuffer(motion_buffer_, false); | 80 return SetMotionBuffer(motion_buffer_, false); |
67 case CONSUMER_TYPE_ORIENTATION: | 81 case CONSUMER_TYPE_ORIENTATION: |
68 return SetOrientationBuffer(orientation_buffer_, false); | 82 return SetOrientationBuffer(orientation_buffer_, false); |
| 83 case CONSUMER_TYPE_LIGHT: |
| 84 return SetLightBuffer(light_buffer_, -1); |
69 default: | 85 default: |
70 NOTREACHED(); | 86 NOTREACHED(); |
71 } | 87 } |
72 return false; | 88 return false; |
73 } | 89 } |
74 | 90 |
75 } // namespace content | 91 } // namespace content |
OLD | NEW |