Bug 713011 - Add a check to ensure we are running on the correct thread. r=blassey
authorKartikaya Gupta <kgupta@mozilla.com>
Wed, 11 Jan 2012 17:08:14 -0500
changeset 85579 cd17d9409fda69fa6abefea715ab30935de13dad
parent 85578 b3b6bca8a02a3d34dd02491e2b5e84c73ce8f8b2
child 85580 69eb27cd5313d32e2377316aeee579d7e33e60d9
push id805
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 18:17:35 +0000
treeherdermozilla-aurora@6fb3bf232436 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersblassey
bugs713011
milestone12.0a1
Bug 713011 - Add a check to ensure we are running on the correct thread. r=blassey
mobile/android/base/ui/PanZoomController.java
--- a/mobile/android/base/ui/PanZoomController.java
+++ b/mobile/android/base/ui/PanZoomController.java
@@ -119,16 +119,18 @@ public class PanZoomController
         ANIMATED_ZOOM   /* animated zoom to a new rect */
     }
 
     private final LayerController mController;
     private final SubdocumentScrollHelper mSubscroller;
     private final Axis mX;
     private final Axis mY;
 
+    private Thread mMainThread;
+
     /* The timer that handles flings or bounces. */
     private Timer mAnimationTimer;
     /* The runnable being scheduled by the animation timer. */
     private AnimationRunnable mAnimationRunnable;
     /* The zoom focus at the first zoom event (in page coordinates). */
     private PointF mLastZoomFocus;
     /* The time the last motion event took place. */
     private long mLastEventTime;
@@ -136,22 +138,33 @@ public class PanZoomController
     private PanZoomState mState;
 
     public PanZoomController(LayerController controller) {
         mController = controller;
         mSubscroller = new SubdocumentScrollHelper(this);
         mX = new AxisX(mSubscroller);
         mY = new AxisY(mSubscroller);
 
+        mMainThread = GeckoApp.mAppContext.getMainLooper().getThread();
+        checkMainThread();
+
         mState = PanZoomState.NOTHING;
 
         GeckoAppShell.registerGeckoEventListener(MESSAGE_ZOOM_RECT, this);
         GeckoAppShell.registerGeckoEventListener(MESSAGE_ZOOM_PAGE, this);
     }
 
+    // for debugging bug 713011; it can be taken out once that is resolved.
+    private void checkMainThread() {
+        if (mMainThread != Thread.currentThread()) {
+            // log with full stack trace
+            Log.e(LOGTAG, "Uh-oh, we're running on the wrong thread!", new Exception());
+        }
+    }
+
     public void handleMessage(String event, JSONObject message) {
         Log.i(LOGTAG, "Got message: " + event);
         try {
             if (MESSAGE_ZOOM_RECT.equals(event)) {
                 float scale = mController.getZoomFactor();
                 float x = (float)message.getDouble("x");
                 float y = (float)message.getDouble("y");
                 final RectF zoomRect = new RectF(x, y,
@@ -193,16 +206,17 @@ public class PanZoomController
         case MotionEvent.ACTION_CANCEL: return onTouchCancel(event);
         default:                        return false;
         }
     }
 
     /** This function must be called from the UI thread. */
     @SuppressWarnings("fallthrough")
     public void abortAnimation() {
+        checkMainThread();
         // this happens when gecko changes the viewport on us or if the device is rotated.
         // if that's the case, abort any animation in progress and re-zoom so that the page
         // snaps to edges. for other cases (where the user's finger(s) are down) don't do
         // anything special.
         switch (mState) {
         case FLING:
             mX.stopFling();
             mY.stopFling();
@@ -626,16 +640,18 @@ public class PanZoomController
             } else {
                 finishAnimation();
                 mState = PanZoomState.NOTHING;
             }
         }
     }
 
     private void finishAnimation() {
+        checkMainThread();
+
         Log.d(LOGTAG, "Finishing animation at " + mController.getViewportMetrics());
         stopAnimationTimer();
 
         // Force a viewport synchronisation
         mController.setForceRedraw();
         mController.notifyLayerClientOfGeometryChange();
     }