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

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

Issue 1164563003: Extract device_sensors to /device via Mojofication (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CONTENT_BROWSER_DEVICE_SENSORS_SENSOR_MANAGER_ANDROID_H_
6 #define CONTENT_BROWSER_DEVICE_SENSORS_SENSOR_MANAGER_ANDROID_H_
7
8 #include "base/android/scoped_java_ref.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/synchronization/lock.h"
11 #include "content/common/content_export.h"
12 #include "content/common/device_sensors/device_light_hardware_buffer.h"
13 #include "content/common/device_sensors/device_motion_hardware_buffer.h"
14 #include "content/common/device_sensors/device_orientation_hardware_buffer.h"
15
16 template<typename T> struct DefaultSingletonTraits;
17
18 namespace content {
19
20 // Android implementation of Device {Motion|Orientation|Light} API.
21 //
22 // Android's SensorManager has a push API, so when Got*() methods are called
23 // by the system the browser process puts the received data into a shared
24 // memory buffer, which is read by the renderer processes.
25 class CONTENT_EXPORT SensorManagerAndroid {
26 public:
27 // Must be called at startup, before GetInstance().
28 static bool Register(JNIEnv* env);
29
30 // Needs to be thread-safe, because accessed from different threads.
31 static SensorManagerAndroid* GetInstance();
32
33 // Called from Java via JNI.
34 void GotLight(JNIEnv*, jobject, double value);
35 void GotOrientation(JNIEnv*, jobject,
36 double alpha, double beta, double gamma);
37 void GotAcceleration(JNIEnv*, jobject,
38 double x, double y, double z);
39 void GotAccelerationIncludingGravity(JNIEnv*, jobject,
40 double x, double y, double z);
41 void GotRotationRate(JNIEnv*, jobject,
42 double alpha, double beta, double gamma);
43
44 // Shared memory related methods.
45 bool StartFetchingDeviceLightData(DeviceLightHardwareBuffer* buffer);
46 void StopFetchingDeviceLightData();
47
48 bool StartFetchingDeviceMotionData(DeviceMotionHardwareBuffer* buffer);
49 void StopFetchingDeviceMotionData();
50
51 bool StartFetchingDeviceOrientationData(
52 DeviceOrientationHardwareBuffer* buffer);
53 void StopFetchingDeviceOrientationData();
54
55 void Shutdown();
56
57 protected:
58 enum EventType {
59 // These constants should match DEVICE_ORIENTATION, DEVICE_MOTION and
60 // DEVICE_LIGHT constants in content/public/android/java/src/org/
61 // chromium/content/browser/DeviceSensors.java
62 kTypeOrientation = 0,
63 kTypeMotion = 1,
64 kTypeLight = 2
65 };
66
67 SensorManagerAndroid();
68 virtual ~SensorManagerAndroid();
69
70 virtual bool Start(EventType event_type);
71 virtual void Stop(EventType event_type);
72 virtual int GetNumberActiveDeviceMotionSensors();
73
74 void StartFetchingLightDataOnUI(DeviceLightHardwareBuffer* buffer);
75 void StopFetchingLightDataOnUI();
76
77 void StartFetchingMotionDataOnUI(DeviceMotionHardwareBuffer* buffer);
78 void StopFetchingMotionDataOnUI();
79
80 void StartFetchingOrientationDataOnUI(
81 DeviceOrientationHardwareBuffer* buffer);
82 void StopFetchingOrientationDataOnUI();
83
84 private:
85 friend struct DefaultSingletonTraits<SensorManagerAndroid>;
86
87 enum {
88 RECEIVED_MOTION_DATA_ACCELERATION = 0,
89 RECEIVED_MOTION_DATA_ACCELERATION_INCL_GRAVITY = 1,
90 RECEIVED_MOTION_DATA_ROTATION_RATE = 2,
91 RECEIVED_MOTION_DATA_MAX = 3,
92 };
93
94 void SetLightBufferValue(double lux);
95
96 void CheckMotionBufferReadyToRead();
97 void SetMotionBufferReadyStatus(bool ready);
98 void ClearInternalMotionBuffers();
99
100 void SetOrientationBufferReadyStatus(bool ready);
101 bool isUsingBackupSensorsForOrientation();
102
103 // The Java provider of sensors info.
104 base::android::ScopedJavaGlobalRef<jobject> device_sensors_;
105 int number_active_device_motion_sensors_;
106 int received_motion_data_[RECEIVED_MOTION_DATA_MAX];
107 DeviceLightHardwareBuffer* device_light_buffer_;
108 DeviceMotionHardwareBuffer* device_motion_buffer_;
109 DeviceOrientationHardwareBuffer* device_orientation_buffer_;
110 bool is_light_buffer_ready_;
111 bool is_motion_buffer_ready_;
112 bool is_orientation_buffer_ready_;
113
114 base::Lock light_buffer_lock_;
115 base::Lock motion_buffer_lock_;
116 base::Lock orientation_buffer_lock_;
117
118 bool is_using_backup_sensors_for_orientation_;
119 bool is_shutdown_;
120
121 DISALLOW_COPY_AND_ASSIGN(SensorManagerAndroid);
122 };
123
124 } // namespace content
125
126 #endif // CONTENT_BROWSER_DEVICE_SENSORS_SENSOR_MANAGER_ANDROID_H_
OLDNEW
« no previous file with comments | « content/browser/device_sensors/inertial_sensor_consts.h ('k') | content/browser/device_sensors/sensor_manager_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698