Chromium Code Reviews| 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..ed096979aa2e52a1220c220548e2662cc0de8e51 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; |
| @@ -359,40 +360,15 @@ class DeviceMotionAndOrientation implements SensorEventListener { |
| private Handler getHandler() { |
| synchronized (mHandlerLock) { |
|
joth
2013/04/18 17:26:26
unless getHandler() is called from multiple thread
timvolodine
2013/04/22 10:00:52
In the transitional implementation (i.e. using sha
|
| - // 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) { |