| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 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 "device/sensors/data_fetcher_shared_memory.h" | |
| 6 | |
| 7 #include "device/sensors/sensor_manager_chromeos.h" | |
| 8 | |
| 9 namespace device { | |
| 10 | |
| 11 DataFetcherSharedMemory::DataFetcherSharedMemory() {} | |
| 12 | |
| 13 DataFetcherSharedMemory::~DataFetcherSharedMemory() {} | |
| 14 | |
| 15 bool DataFetcherSharedMemory::Start(ConsumerType consumer_type, void* buffer) { | |
| 16 DCHECK(buffer); | |
| 17 if (!sensor_manager_) | |
| 18 sensor_manager_.reset(new SensorManagerChromeOS); | |
| 19 | |
| 20 switch (consumer_type) { | |
| 21 case CONSUMER_TYPE_MOTION: | |
| 22 sensor_manager_->StartFetchingDeviceMotionData( | |
| 23 static_cast<DeviceMotionHardwareBuffer*>(buffer)); | |
| 24 return true; | |
| 25 case CONSUMER_TYPE_ORIENTATION: | |
| 26 sensor_manager_->StartFetchingDeviceOrientationData( | |
| 27 static_cast<DeviceOrientationHardwareBuffer*>(buffer)); | |
| 28 return true; | |
| 29 case CONSUMER_TYPE_ORIENTATION_ABSOLUTE: { | |
| 30 orientation_absolute_buffer_ = | |
| 31 static_cast<DeviceOrientationHardwareBuffer*>(buffer); | |
| 32 // Absolute device orientation not available on Chrome OS, let the | |
| 33 // implementation fire an all-null event to signal this to blink. | |
| 34 orientation_absolute_buffer_->seqlock.WriteBegin(); | |
| 35 orientation_absolute_buffer_->data.absolute = true; | |
| 36 orientation_absolute_buffer_->data.all_available_sensors_are_active = | |
| 37 true; | |
| 38 orientation_absolute_buffer_->seqlock.WriteEnd(); | |
| 39 return false; | |
| 40 } | |
| 41 } | |
| 42 NOTREACHED(); | |
| 43 return false; | |
| 44 } | |
| 45 | |
| 46 bool DataFetcherSharedMemory::Stop(ConsumerType consumer_type) { | |
| 47 switch (consumer_type) { | |
| 48 case CONSUMER_TYPE_MOTION: | |
| 49 return sensor_manager_->StopFetchingDeviceMotionData(); | |
| 50 case CONSUMER_TYPE_ORIENTATION: | |
| 51 return sensor_manager_->StopFetchingDeviceOrientationData(); | |
| 52 case CONSUMER_TYPE_ORIENTATION_ABSOLUTE: | |
| 53 if (orientation_absolute_buffer_) { | |
| 54 orientation_absolute_buffer_->seqlock.WriteBegin(); | |
| 55 orientation_absolute_buffer_->data.all_available_sensors_are_active = | |
| 56 false; | |
| 57 orientation_absolute_buffer_->seqlock.WriteEnd(); | |
| 58 orientation_absolute_buffer_ = nullptr; | |
| 59 } | |
| 60 return true; | |
| 61 } | |
| 62 NOTREACHED(); | |
| 63 return false; | |
| 64 } | |
| 65 | |
| 66 } // namespace device | |
| OLD | NEW |