Chromium Code Reviews| 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..a5f553421a6b7b590b0f71d79367baaa185630b6 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/10 16:59:41
nit: LeakySingletonTraits
timvolodine
2013/07/11 14:31:34
apparently this needs to be DefaultSingletonTraits
|
| +namespace content { |
| class Orientation; |
| // Android implementation of DeviceOrientation API. |
| @@ -23,16 +25,21 @@ class Orientation; |
| // previous value if any). Chrome calls GetDeviceData() which reads the most |
| // recent value. Repeated calls to GetDeviceData() will return the same value. |
| +// TODO(timvolodine): Move this class implementation to |
| +// data_fetcher_shared_memory_android.cc, once Device Orientation switches to |
| +// shared memory implementation. |
| class DataFetcherImplAndroid : public DataFetcher { |
| public: |
| // Must be called at startup, before Create(). |
| - static void Init(JNIEnv* env); |
| + static void Register(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 a thread in provider_impl.cc |
|
bulach
2013/07/10 16:59:41
nit: s/a thread/different threads/
timvolodine
2013/07/11 14:31:34
Done.
|
| + // and device_motion_provider.cc. |
| + static DataFetcherImplAndroid* GetInstance(); |
| // Called from Java via JNI. |
| void GotOrientation(JNIEnv*, jobject, |
| @@ -47,18 +54,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. |
| - bool Start(DeviceData::Type event_type, int rate_in_milliseconds); |
| - void Stop(DeviceData::Type event_type); |
| + virtual bool Start(DeviceData::Type event_type, int rate_in_milliseconds); |
| + 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(); |
| + |
| + 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 +96,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); |
| }; |