Index: content/browser/device_orientation/data_fetcher_impl_android.h |
diff --git a/content/browser/device_orientation/data_fetcher_impl_android.h b/content/browser/device_orientation/data_fetcher_impl_android.h |
index 4f431e0da117ab2b64d52c7b1c038dad3c86fba4..880c06cd4044373ae558543617d23c628fdcd916 100644 |
--- a/content/browser/device_orientation/data_fetcher_impl_android.h |
+++ b/content/browser/device_orientation/data_fetcher_impl_android.h |
@@ -10,9 +10,11 @@ |
#include "base/synchronization/lock.h" |
#include "content/browser/device_orientation/data_fetcher.h" |
#include "content/browser/device_orientation/device_data.h" |
+#include "content/common/device_motion_hardware_buffer.h" |
-namespace content { |
+template<typename T> struct DefaultSingletonTraits; |
bulach
2013/07/12 14:00:41
I don't quite understand why the Leaky version wou
timvolodine
2013/07/12 15:22:18
If I change this to Leaky the below friend declara
|
+namespace content { |
class Orientation; |
// Android implementation of DeviceOrientation API. |
@@ -23,16 +25,16 @@ class Orientation; |
// previous value if any). Chrome calls GetDeviceData() which reads the most |
// recent value. Repeated calls to GetDeviceData() will return the same value. |
-class DataFetcherImplAndroid : public DataFetcher { |
+// TODO(timvolodine): Move this class implementation to |
+// data_fetcher_shared_memory_android.cc, once Device Orientation switches to |
+// shared memory implementation. |
bulach
2013/07/12 14:00:41
would this be the case? I think this class will re
timvolodine
2013/07/12 15:22:18
yes, but the class can be simplified once device o
|
+class DataFetcherImplAndroid { |
public: |
- // Must be called at startup, before Create(). |
+ // Must be called at startup, before GetInstance(). |
static void Init(JNIEnv* env); |
- // Factory function. We'll listen for events for the lifetime of this object. |
- // Returns NULL on error. |
- static DataFetcher* Create(); |
- |
- virtual ~DataFetcherImplAndroid(); |
+ // Needs to be thread-safe, because accessed from different threads. |
+ static DataFetcherImplAndroid* GetInstance(); |
// Called from Java via JNI. |
void GotOrientation(JNIEnv*, jobject, |
@@ -47,18 +49,39 @@ class DataFetcherImplAndroid : public DataFetcher { |
// Implementation of DataFetcher. |
virtual const DeviceData* GetDeviceData(DeviceData::Type type) OVERRIDE; |
- private: |
- DataFetcherImplAndroid(); |
- const Orientation* GetOrientation(); |
- |
// Wrappers for JNI methods. |
// TODO(timvolodine): move the DeviceData::Type enum to the service class |
// once it is implemented. |
bulach
2013/07/12 14:00:41
I think 52-54 can be dropped? :)
timvolodine
2013/07/12 15:22:18
Done.
|
- bool Start(DeviceData::Type event_type, int rate_in_milliseconds); |
- void Stop(DeviceData::Type event_type); |
+ virtual bool Start(DeviceData::Type event_type); |
+ virtual void Stop(DeviceData::Type event_type); |
+ |
+ // Shared memory related methods. |
+ virtual bool NeedsPolling(); |
+ virtual bool FetchDeviceMotionDataIntoBuffer(); |
+ virtual bool StartFetchingDeviceMotionData( |
+ DeviceMotionHardwareBuffer* buffer); |
+ virtual void StopFetchingDeviceMotionData(); |
bulach
2013/07/12 14:00:41
hmm... is "NeedsPolling()" necessary, since this c
timvolodine
2013/07/12 15:22:18
Done.
|
+ |
+ protected: |
+ DataFetcherImplAndroid(); |
+ virtual ~DataFetcherImplAndroid(); |
+ |
+ const Orientation* GetOrientation(); |
virtual int GetNumberActiveDeviceMotionSensors(); |
+ void CheckBufferReadyToRead(); |
+ void SetBufferReadyStatus(bool ready); |
+ void ClearInternalBuffers(); |
+ private: |
+ friend struct DefaultSingletonTraits<DataFetcherImplAndroid>; |
+ |
+ enum { |
+ RECEIVED_MOTION_DATA_ACCELERATION = 0, |
+ RECEIVED_MOTION_DATA_ACCELERATION_INCL_GRAVITY = 1, |
+ RECEIVED_MOTION_DATA_ROTATION_RATE = 2, |
+ RECEIVED_MOTION_DATA_MAX = 3, |
+ }; |
// Value returned by GetDeviceData. |
scoped_refptr<Orientation> current_orientation_; |
@@ -68,6 +91,10 @@ class DataFetcherImplAndroid : public DataFetcher { |
// The Java provider of orientation info. |
base::android::ScopedJavaGlobalRef<jobject> device_orientation_; |
+ int number_active_device_motion_sensors_; |
+ int received_motion_data_[RECEIVED_MOTION_DATA_MAX]; |
+ DeviceMotionHardwareBuffer* device_motion_buffer_; |
+ bool is_buffer_ready_; |
DISALLOW_COPY_AND_ASSIGN(DataFetcherImplAndroid); |
}; |