Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: content/browser/device_orientation/sensor_manager_android.h

Issue 137853006: Android: rename DataFetcherImplAndroid -> SensorManagerAndroid. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 CHROME_BROWSER_DEVICE_ORIENTATION_DATA_FETCHER_IMPL_ANDROID_H_ 5 #ifndef CHROME_BROWSER_DEVICE_ORIENTATION_SENSOR_MANAGER_ANDROID_H_
6 #define CHROME_BROWSER_DEVICE_ORIENTATION_DATA_FETCHER_IMPL_ANDROID_H_ 6 #define CHROME_BROWSER_DEVICE_ORIENTATION_SENSOR_MANAGER_ANDROID_H_
7 7
8 #include "base/android/scoped_java_ref.h" 8 #include "base/android/scoped_java_ref.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/synchronization/lock.h" 10 #include "base/synchronization/lock.h"
11 #include "content/common/content_export.h" 11 #include "content/common/content_export.h"
12 #include "content/common/device_orientation/device_motion_hardware_buffer.h" 12 #include "content/common/device_orientation/device_motion_hardware_buffer.h"
13 #include "content/common/device_orientation/device_orientation_hardware_buffer.h " 13 #include "content/common/device_orientation/device_orientation_hardware_buffer.h "
14 14
15 template<typename T> struct DefaultSingletonTraits; 15 template<typename T> struct DefaultSingletonTraits;
16 16
17 namespace content { 17 namespace content {
18 18
19 // Android implementation of Device Orientation API. 19 // Android implementation of Device Orientation API.
20 // 20 //
21 // Android's SensorManager has a push API, so when Got*() methods are called 21 // Android's SensorManager has a push API, so when Got*() methods are called
22 // by the system the browser process puts the received data into a shared 22 // by the system the browser process puts the received data into a shared
23 // memory buffer, which is read by the renderer processes. 23 // memory buffer, which is read by the renderer processes.
24 // 24 class CONTENT_EXPORT SensorManagerAndroid {
25
26 // TODO(timvolodine): rename this class to SensorManagerAndroid.
27 class CONTENT_EXPORT DataFetcherImplAndroid {
28 public: 25 public:
29 // Must be called at startup, before GetInstance(). 26 // Must be called at startup, before GetInstance().
30 static bool Register(JNIEnv* env); 27 static bool Register(JNIEnv* env);
31 28
32 // Needs to be thread-safe, because accessed from different threads. 29 // Needs to be thread-safe, because accessed from different threads.
33 static DataFetcherImplAndroid* GetInstance(); 30 static SensorManagerAndroid* GetInstance();
34 31
35 // Called from Java via JNI. 32 // Called from Java via JNI.
36 void GotOrientation(JNIEnv*, jobject, 33 void GotOrientation(JNIEnv*, jobject,
37 double alpha, double beta, double gamma); 34 double alpha, double beta, double gamma);
38 void GotAcceleration(JNIEnv*, jobject, 35 void GotAcceleration(JNIEnv*, jobject,
39 double x, double y, double z); 36 double x, double y, double z);
40 void GotAccelerationIncludingGravity(JNIEnv*, jobject, 37 void GotAccelerationIncludingGravity(JNIEnv*, jobject,
41 double x, double y, double z); 38 double x, double y, double z);
42 void GotRotationRate(JNIEnv*, jobject, 39 void GotRotationRate(JNIEnv*, jobject,
43 double alpha, double beta, double gamma); 40 double alpha, double beta, double gamma);
44 41
45 // Shared memory related methods. 42 // Shared memory related methods.
46 bool StartFetchingDeviceMotionData(DeviceMotionHardwareBuffer* buffer); 43 bool StartFetchingDeviceMotionData(DeviceMotionHardwareBuffer* buffer);
47 void StopFetchingDeviceMotionData(); 44 void StopFetchingDeviceMotionData();
48 45
49 bool StartFetchingDeviceOrientationData( 46 bool StartFetchingDeviceOrientationData(
50 DeviceOrientationHardwareBuffer* buffer); 47 DeviceOrientationHardwareBuffer* buffer);
51 void StopFetchingDeviceOrientationData(); 48 void StopFetchingDeviceOrientationData();
52 49
53 protected: 50 protected:
54 enum EventType { 51 enum EventType {
55 // These constants should match DEVICE_ORIENTATION and DEVICE_MOTION 52 // These constants should match DEVICE_ORIENTATION and DEVICE_MOTION
56 // constants in content/public/android/java/src/org/chromium/content/ 53 // constants in content/public/android/java/src/org/chromium/content/
57 // browser/DeviceMotionAndOrientation.java 54 // browser/DeviceMotionAndOrientation.java
58 kTypeOrientation = 0, 55 kTypeOrientation = 0,
59 kTypeMotion = 1 56 kTypeMotion = 1
60 }; 57 };
61 58
62 DataFetcherImplAndroid(); 59 SensorManagerAndroid();
63 virtual ~DataFetcherImplAndroid(); 60 virtual ~SensorManagerAndroid();
64 61
65 virtual bool Start(EventType event_type); 62 virtual bool Start(EventType event_type);
66 virtual void Stop(EventType event_type); 63 virtual void Stop(EventType event_type);
67 virtual int GetNumberActiveDeviceMotionSensors(); 64 virtual int GetNumberActiveDeviceMotionSensors();
68 65
69 private: 66 private:
70 friend struct DefaultSingletonTraits<DataFetcherImplAndroid>; 67 friend struct DefaultSingletonTraits<SensorManagerAndroid>;
71 68
72 enum { 69 enum {
73 RECEIVED_MOTION_DATA_ACCELERATION = 0, 70 RECEIVED_MOTION_DATA_ACCELERATION = 0,
74 RECEIVED_MOTION_DATA_ACCELERATION_INCL_GRAVITY = 1, 71 RECEIVED_MOTION_DATA_ACCELERATION_INCL_GRAVITY = 1,
75 RECEIVED_MOTION_DATA_ROTATION_RATE = 2, 72 RECEIVED_MOTION_DATA_ROTATION_RATE = 2,
76 RECEIVED_MOTION_DATA_MAX = 3, 73 RECEIVED_MOTION_DATA_MAX = 3,
77 }; 74 };
78 75
79 void CheckMotionBufferReadyToRead(); 76 void CheckMotionBufferReadyToRead();
80 void SetMotionBufferReadyStatus(bool ready); 77 void SetMotionBufferReadyStatus(bool ready);
81 void ClearInternalMotionBuffers(); 78 void ClearInternalMotionBuffers();
82 79
83 void SetOrientationBufferReadyStatus(bool ready); 80 void SetOrientationBufferReadyStatus(bool ready);
84 81
85 // The Java provider of orientation info. 82 // The Java provider of orientation info.
86 base::android::ScopedJavaGlobalRef<jobject> device_orientation_; 83 base::android::ScopedJavaGlobalRef<jobject> device_orientation_;
87 int number_active_device_motion_sensors_; 84 int number_active_device_motion_sensors_;
88 int received_motion_data_[RECEIVED_MOTION_DATA_MAX]; 85 int received_motion_data_[RECEIVED_MOTION_DATA_MAX];
89 DeviceMotionHardwareBuffer* device_motion_buffer_; 86 DeviceMotionHardwareBuffer* device_motion_buffer_;
90 DeviceOrientationHardwareBuffer* device_orientation_buffer_; 87 DeviceOrientationHardwareBuffer* device_orientation_buffer_;
91 bool is_motion_buffer_ready_; 88 bool is_motion_buffer_ready_;
92 bool is_orientation_buffer_ready_; 89 bool is_orientation_buffer_ready_;
93 90
94 base::Lock motion_buffer_lock_; 91 base::Lock motion_buffer_lock_;
95 base::Lock orientation_buffer_lock_; 92 base::Lock orientation_buffer_lock_;
96 93
97 DISALLOW_COPY_AND_ASSIGN(DataFetcherImplAndroid); 94 DISALLOW_COPY_AND_ASSIGN(SensorManagerAndroid);
98 }; 95 };
99 96
100 } // namespace content 97 } // namespace content
101 98
102 #endif // CHROME_BROWSER_DEVICE_ORIENTATION_DATA_FETCHER_IMPL_ANDROID_H_ 99 #endif // CHROME_BROWSER_DEVICE_ORIENTATION_SENSOR_MANAGER_ANDROID_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698