| 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 #ifndef CONTENT_BROWSER_DEVICE_SENSORS_SENSOR_MANAGER_ANDROID_H_ | 5 #ifndef CONTENT_BROWSER_DEVICE_SENSORS_SENSOR_MANAGER_ANDROID_H_ |
| 6 #define CONTENT_BROWSER_DEVICE_SENSORS_SENSOR_MANAGER_ANDROID_H_ | 6 #define CONTENT_BROWSER_DEVICE_SENSORS_SENSOR_MANAGER_ANDROID_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/android/scoped_java_ref.h" | 10 #include "base/android/scoped_java_ref.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 // Android implementation of Device {Motion|Orientation|Light} API. | 26 // Android implementation of Device {Motion|Orientation|Light} API. |
| 27 // | 27 // |
| 28 // Android's SensorManager has a push API, so when Got*() methods are called | 28 // Android's SensorManager has a push API, so when Got*() methods are called |
| 29 // by the system the browser process puts the received data into a shared | 29 // by the system the browser process puts the received data into a shared |
| 30 // memory buffer, which is read by the renderer processes. | 30 // memory buffer, which is read by the renderer processes. |
| 31 class CONTENT_EXPORT SensorManagerAndroid { | 31 class CONTENT_EXPORT SensorManagerAndroid { |
| 32 public: | 32 public: |
| 33 // Must be called at startup, before GetInstance(). | 33 // Must be called at startup, before GetInstance(). |
| 34 static bool Register(JNIEnv* env); | 34 static bool Register(JNIEnv* env); |
| 35 | 35 |
| 36 // Needs to be thread-safe, because accessed from different threads. | 36 // Should be called only on the UI thread. |
| 37 static SensorManagerAndroid* GetInstance(); | 37 static SensorManagerAndroid* GetInstance(); |
| 38 | 38 |
| 39 // Called from Java via JNI. | 39 // Called from Java via JNI. |
| 40 void GotLight(JNIEnv*, | 40 void GotLight(JNIEnv*, |
| 41 const base::android::JavaParamRef<jobject>&, | 41 const base::android::JavaParamRef<jobject>&, |
| 42 double value); | 42 double value); |
| 43 void GotOrientation(JNIEnv*, | 43 void GotOrientation(JNIEnv*, |
| 44 const base::android::JavaParamRef<jobject>&, | 44 const base::android::JavaParamRef<jobject>&, |
| 45 double alpha, | 45 double alpha, |
| 46 double beta, | 46 double beta, |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 // Returns true if the registration with sensors was successful. | 103 // Returns true if the registration with sensors was successful. |
| 104 virtual bool Start(ConsumerType consumer_type); | 104 virtual bool Start(ConsumerType consumer_type); |
| 105 // Stops listening to the sensors corresponding to the consumer_type. | 105 // Stops listening to the sensors corresponding to the consumer_type. |
| 106 virtual void Stop(ConsumerType consumer_type); | 106 virtual void Stop(ConsumerType consumer_type); |
| 107 // Returns currently used sensor type for device orientation. | 107 // Returns currently used sensor type for device orientation. |
| 108 virtual OrientationSensorType GetOrientationSensorTypeUsed(); | 108 virtual OrientationSensorType GetOrientationSensorTypeUsed(); |
| 109 // Returns the number of active sensors corresponding to | 109 // Returns the number of active sensors corresponding to |
| 110 // ConsumerType.DEVICE_MOTION. | 110 // ConsumerType.DEVICE_MOTION. |
| 111 virtual int GetNumberActiveDeviceMotionSensors(); | 111 virtual int GetNumberActiveDeviceMotionSensors(); |
| 112 | 112 |
| 113 void StartFetchingLightDataOnUI(DeviceLightHardwareBuffer* buffer); | |
| 114 void StopFetchingLightDataOnUI(); | |
| 115 | |
| 116 void StartFetchingMotionDataOnUI(DeviceMotionHardwareBuffer* buffer); | |
| 117 void StopFetchingMotionDataOnUI(); | |
| 118 | |
| 119 void StartFetchingOrientationDataOnUI( | |
| 120 DeviceOrientationHardwareBuffer* buffer); | |
| 121 void StopFetchingOrientationDataOnUI(); | |
| 122 | |
| 123 void StartFetchingOrientationAbsoluteDataOnUI( | |
| 124 DeviceOrientationHardwareBuffer* buffer); | |
| 125 void StopFetchingOrientationAbsoluteDataOnUI(); | |
| 126 | |
| 127 private: | 113 private: |
| 128 friend struct base::DefaultSingletonTraits<SensorManagerAndroid>; | 114 friend struct base::DefaultSingletonTraits<SensorManagerAndroid>; |
| 129 | 115 |
| 130 enum { | 116 enum { |
| 131 RECEIVED_MOTION_DATA_ACCELERATION = 0, | 117 RECEIVED_MOTION_DATA_ACCELERATION = 0, |
| 132 RECEIVED_MOTION_DATA_ACCELERATION_INCL_GRAVITY = 1, | 118 RECEIVED_MOTION_DATA_ACCELERATION_INCL_GRAVITY = 1, |
| 133 RECEIVED_MOTION_DATA_ROTATION_RATE = 2, | 119 RECEIVED_MOTION_DATA_ROTATION_RATE = 2, |
| 134 RECEIVED_MOTION_DATA_MAX = 3, | 120 RECEIVED_MOTION_DATA_MAX = 3, |
| 135 }; | 121 }; |
| 136 | 122 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 161 base::Lock orientation_absolute_buffer_lock_; | 147 base::Lock orientation_absolute_buffer_lock_; |
| 162 | 148 |
| 163 bool is_shutdown_; | 149 bool is_shutdown_; |
| 164 | 150 |
| 165 DISALLOW_COPY_AND_ASSIGN(SensorManagerAndroid); | 151 DISALLOW_COPY_AND_ASSIGN(SensorManagerAndroid); |
| 166 }; | 152 }; |
| 167 | 153 |
| 168 } // namespace content | 154 } // namespace content |
| 169 | 155 |
| 170 #endif // CONTENT_BROWSER_DEVICE_SENSORS_SENSOR_MANAGER_ANDROID_H_ | 156 #endif // CONTENT_BROWSER_DEVICE_SENSORS_SENSOR_MANAGER_ANDROID_H_ |
| OLD | NEW |