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

Unified Diff: content/public/android/java/src/org/chromium/content/browser/DeviceMotionAndOrientation.java

Issue 14352008: Java-side sensor polling getHandler() method simplification as per joth's comment. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: added named todo and reference to crbug Created 7 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/public/android/java/src/org/chromium/content/browser/DeviceMotionAndOrientation.java
diff --git a/content/public/android/java/src/org/chromium/content/browser/DeviceMotionAndOrientation.java b/content/public/android/java/src/org/chromium/content/browser/DeviceMotionAndOrientation.java
index 866884882fa6e197b0ec75c8a91735ae36f1dbc5..ecb9d626479bd0283bd290e42fef55265061735a 100644
--- a/content/public/android/java/src/org/chromium/content/browser/DeviceMotionAndOrientation.java
+++ b/content/public/android/java/src/org/chromium/content/browser/DeviceMotionAndOrientation.java
@@ -10,6 +10,7 @@ import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Handler;
+import android.os.HandlerThread;
import android.os.Looper;
import android.util.Log;
@@ -358,41 +359,19 @@ class DeviceMotionAndOrientation implements SensorEventListener {
}
private Handler getHandler() {
+ // TODO(timvolodine): Remove the mHandlerLock when sure that getHandler is not called
+ // from multiple threads. This will be the case when device motion and device orientation
+ // use the same polling thread (also see crbug/234282).
synchronized (mHandlerLock) {
- // If we don't have a background thread, start it now.
- if (mThread == null) {
- mThread = new Thread(new Runnable() {
- @Override
- public void run() {
- Looper.prepare();
- // Our Handler doesn't actually have to do anything, because
- // SensorManager posts directly to the underlying Looper.
- setHandler(new Handler());
- Looper.loop();
- }
- });
- mThread.start();
- }
- // Wait for the background thread to spin up.
- while (mHandler == null) {
- try {
- mHandlerLock.wait();
- } catch (InterruptedException e) {
- // Somebody doesn't want us to wait! That's okay, SensorManager accepts null.
- return null;
- }
+ if (mHandler == null) {
+ HandlerThread thread = new HandlerThread("DeviceMotionAndOrientation");
+ thread.start();
+ mHandler = new Handler(thread.getLooper()); // blocks on thread start
}
return mHandler;
}
}
- private void setHandler(Handler handler) {
- synchronized (mHandlerLock) {
- mHandler = handler;
- mHandlerLock.notify();
- }
- }
-
@CalledByNative
static DeviceMotionAndOrientation getInstance() {
synchronized (sSingletonLock) {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698