| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef CONTENT_BROWSER_DEVICE_SENSORS_SENSOR_MANAGER_CHROMEOS_H_ | 5 #ifndef CONTENT_BROWSER_DEVICE_SENSORS_SENSOR_MANAGER_CHROMEOS_H_ |
| 6 #define CONTENT_BROWSER_DEVICE_SENSORS_SENSOR_MANAGER_CHROMEOS_H_ | 6 #define CONTENT_BROWSER_DEVICE_SENSORS_SENSOR_MANAGER_CHROMEOS_H_ |
| 7 | 7 |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/synchronization/lock.h" | 9 #include "base/threading/thread_checker.h" |
| 10 #include "chromeos/accelerometer/accelerometer_reader.h" | 10 #include "chromeos/accelerometer/accelerometer_reader.h" |
| 11 #include "chromeos/accelerometer/accelerometer_types.h" | 11 #include "chromeos/accelerometer/accelerometer_types.h" |
| 12 #include "content/common/content_export.h" | 12 #include "content/common/content_export.h" |
| 13 #include "content/common/device_sensors/device_motion_hardware_buffer.h" |
| 13 #include "content/common/device_sensors/device_orientation_hardware_buffer.h" | 14 #include "content/common/device_sensors/device_orientation_hardware_buffer.h" |
| 14 | 15 |
| 15 namespace content { | 16 namespace content { |
| 16 | 17 |
| 17 // Observes Chrome OS accelerometer sensors, and provides updated device | 18 // Observes Chrome OS accelerometer sensors, and provides updated device |
| 18 // orientation information. | 19 // orientation information. |
| 19 class CONTENT_EXPORT SensorManagerChromeOS | 20 class CONTENT_EXPORT SensorManagerChromeOS |
| 20 : public chromeos::AccelerometerReader::Observer { | 21 : public chromeos::AccelerometerReader::Observer { |
| 21 public: | 22 public: |
| 22 SensorManagerChromeOS(); | 23 SensorManagerChromeOS(); |
| 23 ~SensorManagerChromeOS() override; | 24 ~SensorManagerChromeOS() override; |
| 24 | 25 |
| 26 // Begins monitoring of motion events, the shared memory of |buffer| will be |
| 27 // updated upon subsequent events. |
| 28 void StartFetchingDeviceMotionData(DeviceMotionHardwareBuffer* buffer); |
| 29 |
| 30 // Stops monitoring motion events. Returns true if there is an active |
| 31 // |motion_buffer_| and fetching stops. Otherwise returns false. |
| 32 bool StopFetchingDeviceMotionData(); |
| 33 |
| 25 // Begins monitoring of orientation events, the shared memory of |buffer| will | 34 // Begins monitoring of orientation events, the shared memory of |buffer| will |
| 26 // be updated upon subsequent events. | 35 // be updated upon subsequent events. |
| 27 bool StartFetchingDeviceOrientationData( | 36 void StartFetchingDeviceOrientationData( |
| 28 DeviceOrientationHardwareBuffer* buffer); | 37 DeviceOrientationHardwareBuffer* buffer); |
| 29 | 38 |
| 30 // Stops monitoring orientation events. Returns true if there is an active | 39 // Stops monitoring orientation events. Returns true if there is an active |
| 31 // |orientation_buffer_| and fetching stops. Otherwise returns false. | 40 // |orientation_buffer_| and fetching stops. Otherwise returns false. |
| 32 bool StopFetchingDeviceOrientationData(); | 41 bool StopFetchingDeviceOrientationData(); |
| 33 | 42 |
| 34 // chromeos::AccelerometerReader::Observer: | 43 // chromeos::AccelerometerReader::Observer: |
| 35 void OnAccelerometerUpdated( | 44 void OnAccelerometerUpdated( |
| 36 const chromeos::AccelerometerUpdate& update) override; | 45 scoped_refptr<const chromeos::AccelerometerUpdate> update) override; |
| 37 | 46 |
| 38 protected: | 47 protected: |
| 39 // Begins/ends the observation of accelerometer events. | 48 // Begins/ends the observation of accelerometer events. |
| 40 virtual void StartObservingAccelerometer(); | 49 virtual void StartObservingAccelerometer(); |
| 41 virtual void StopObservingAccelerometer(); | 50 virtual void StopObservingAccelerometer(); |
| 42 | 51 |
| 43 private: | 52 private: |
| 53 // Updates |motion_buffer_| or |orientation_buffer_| accordingly. |
| 54 void GenerateMotionEvent(double x, double y, double z); |
| 55 void GenerateOrientationEvent(double x, double y, double z); |
| 56 |
| 44 // Shared memory to update. | 57 // Shared memory to update. |
| 58 DeviceMotionHardwareBuffer* motion_buffer_; |
| 45 DeviceOrientationHardwareBuffer* orientation_buffer_; | 59 DeviceOrientationHardwareBuffer* orientation_buffer_; |
| 46 | 60 |
| 47 // Synchronize orientation_buffer_ across threads. | 61 // Verify all work is done on the same thread. |
| 48 base::Lock orientation_buffer_lock_; | 62 base::ThreadChecker thread_checker_; |
| 49 | 63 |
| 50 DISALLOW_COPY_AND_ASSIGN(SensorManagerChromeOS); | 64 DISALLOW_COPY_AND_ASSIGN(SensorManagerChromeOS); |
| 51 }; | 65 }; |
| 52 | 66 |
| 53 } // namespace content | 67 } // namespace content |
| 54 | 68 |
| 55 #endif // CONTENT_BROWSER_DEVICE_SENSORS_SENSOR_MANAGER_CHROMEOS_H_ | 69 #endif // CONTENT_BROWSER_DEVICE_SENSORS_SENSOR_MANAGER_CHROMEOS_H_ |
| OLD | NEW |