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