bug 704307 - strictmode Disk read Violation when loading awesomebar r=dougt
authorBrad Lassey <blassey@mozilla.com>
Tue, 29 Nov 2011 22:54:07 -0500
changeset 83634 a9c28fe6b23ffbeaf35aa4171471f87194c95885
parent 83633 9aa68bb7be35cfe134b9730d1e2f32102abdadcb
child 83635 18b9c82223b71e441bbd1c7f95968d5708aff600
push id519
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 00:38:35 +0000
treeherdermozilla-beta@788ea1ef610b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdougt
bugs704307
milestone11.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
bug 704307 - strictmode Disk read Violation when loading awesomebar r=dougt
mobile/android/base/GeckoApp.java
mobile/android/base/GeckoAppShell.java
mobile/android/base/GeckoThread.java
mobile/android/base/gfx/PlaceholderLayerClient.java
--- a/mobile/android/base/GeckoApp.java
+++ b/mobile/android/base/GeckoApp.java
@@ -81,29 +81,31 @@ import android.preference.*;
 
 import android.util.*;
 import android.net.*;
 import android.database.*;
 import android.database.sqlite.*;
 import android.provider.*;
 import android.content.pm.*;
 import android.content.pm.PackageManager.*;
-import android.content.SharedPreferences.*;
 import dalvik.system.*;
 
 abstract public class GeckoApp
     extends Activity implements GeckoEventListener, SensorEventListener, LocationListener
 {
     private static final String LOGTAG = "GeckoApp";
 
-    public static final String ACTION_ALERT_CLICK = "org.mozilla.gecko.ACTION_ALERT_CLICK";
-    public static final String ACTION_ALERT_CLEAR = "org.mozilla.gecko.ACTION_ALERT_CLEAR";
-    public static final String ACTION_WEBAPP      = "org.mozilla.gecko.WEBAPP";
-    public static final String ACTION_DEBUG       = "org.mozilla.gecko.DEBUG";
-    public static final String ACTION_BOOKMARK    = "org.mozilla.gecko.BOOKMARK";
+    public static final String ACTION_ALERT_CLICK   = "org.mozilla.gecko.ACTION_ALERT_CLICK";
+    public static final String ACTION_ALERT_CLEAR   = "org.mozilla.gecko.ACTION_ALERT_CLEAR";
+    public static final String ACTION_WEBAPP        = "org.mozilla.gecko.WEBAPP";
+    public static final String ACTION_DEBUG         = "org.mozilla.gecko.DEBUG";
+    public static final String ACTION_BOOKMARK      = "org.mozilla.gecko.BOOKMARK";
+    public static final String SAVED_STATE_URI      = "uri";
+    public static final String SAVED_STATE_TITLE    = "title";
+    public static final String SAVED_STATE_VIEWPORT = "viewport";
 
     private LinearLayout mMainLayout;
     private AbsoluteLayout mGeckoLayout;
     public static SurfaceView cameraView;
     public static GeckoApp mAppContext;
     public static boolean mFullScreen = false;
     public static File sGREDir = null;
     public static Menu sMenu;
@@ -123,16 +125,20 @@ abstract public class GeckoApp
     private Geocoder mGeocoder;
     private Address  mLastGeoAddress;
     private static LayerController mLayerController;
     private static PlaceholderLayerClient mPlaceholderLayerClient;
     private static GeckoSoftwareLayerClient mSoftwareLayerClient;
     AboutHomeContent mAboutHomeContent;
     boolean mUserDefinedProfile = false;
 
+    public String mLastUri;
+    public String mLastTitle;
+    public String mLastViewport;
+
     private Vector<View> mPluginViews = new Vector<View>();
 
     public interface OnTabsChangedListener {
         public void onTabsChanged(Tab tab);
     }
     
     private static ArrayList<OnTabsChangedListener> mTabsChangedListeners;
 
@@ -380,17 +386,17 @@ abstract public class GeckoApp
                 String args = intent.getStringExtra("args");
                 if (args != null && args.contains("-profile"))
                     mUserDefinedProfile = true;
 
         if (intent == null)
             intent = getIntent();
 
         prefetchDNS(intent.getData());
-        new GeckoThread(intent).start();
+        new GeckoThread(intent, mLastUri, mLastTitle).start();
 
         return true;
     }
 
     @Override
     public boolean onCreateOptionsMenu(Menu menu)
     {
         sMenu = menu;
@@ -544,57 +550,49 @@ abstract public class GeckoApp
     }
 
     public static String getStartupBitmapFilePath() {
         File file = new File(GeckoAppShell.getCacheDir(),
                              "lastScreen.png");
         return file.toString();
     }
 
-    public SharedPreferences getPlaceholderPrefs() {
-        return getSharedPreferences("GeckoApp", MODE_PRIVATE);
+    public String getLastViewport() {
+        return mLastViewport;
     }
 
+    protected void onSaveInstanceState(Bundle outState) {
+        super.onSaveInstanceState(outState);
+        if (outState == null)
+            outState = new Bundle();
+        outState.putString(SAVED_STATE_URI, mLastUri);
+        outState.putString(SAVED_STATE_TITLE, mLastTitle);
+        outState.putString(SAVED_STATE_VIEWPORT, mLastViewport);
+    }
+
+
     private void rememberLastScreen(boolean sync) {
         if (mUserDefinedProfile)
             return;
 
         Tab tab = Tabs.getInstance().getSelectedTab();
         if (tab == null)
             return;
 
         HistoryEntry lastHistoryEntry = tab.getLastHistoryEntry();
         if (lastHistoryEntry == null)
             return;
 
         if (getLayerController().getLayerClient() != mSoftwareLayerClient)
             return;
 
-        ViewportMetrics viewport = mSoftwareLayerClient.getGeckoViewportMetrics();
-        String uri = lastHistoryEntry.mUri;
-        String title = lastHistoryEntry.mTitle;
-
-        SharedPreferences prefs = getPlaceholderPrefs();
-        Editor editor = prefs.edit();
-
-        editor.putString("last-uri", uri);
-        editor.putString("last-title", title);
+        mLastViewport = mSoftwareLayerClient.getGeckoViewportMetrics().toJSON();
+        mLastUri = lastHistoryEntry.mUri;
+        mLastTitle = lastHistoryEntry.mTitle;
 
-        if (viewport != null) {
-            /* XXX Saving this viewport means there may be a slight
-             *     discrepancy between what the user sees when shutting down
-             *     and what they see when starting up, but it oughtn't be much.
-             *
-             *     The alternative is to do a transformation between the two.
-             */
-            editor.putString("viewport", viewport.toJSON());
-        }
-
-        Log.i(LOGTAG, "Saving:: " + uri + " " + title);
-        editor.commit();
 
         GeckoEvent event = new GeckoEvent();
         event.mType = GeckoEvent.SAVE_STATE;
         event.mCharacters = getStartupBitmapFilePath();
         if (sync)
             GeckoAppShell.sendEventToGeckoSync(event);
         else
             GeckoAppShell.sendEventToGecko(event);
@@ -1233,17 +1231,21 @@ abstract public class GeckoApp
         });
     }
 
     /** Called when the activity is first created. */
     @Override
     public void onCreate(Bundle savedInstanceState)
     {
         Log.w(LOGTAG, "zerdatime " + new Date().getTime() + " - onCreate");
-
+        if (savedInstanceState != null) {
+            mLastUri = savedInstanceState.getString(SAVED_STATE_URI);
+            mLastTitle = savedInstanceState.getString(SAVED_STATE_TITLE);
+            mLastViewport = savedInstanceState.getString(SAVED_STATE_VIEWPORT);
+        }
         if (Build.VERSION.SDK_INT >= 9) {
             StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
                                        .detectDiskReads().detectDiskWrites().detectNetwork()
                                        .penaltyLog().build());
             StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().penaltyLog().build());
         }
 
         super.onCreate(savedInstanceState);
--- a/mobile/android/base/GeckoAppShell.java
+++ b/mobile/android/base/GeckoAppShell.java
@@ -1021,20 +1021,22 @@ public class GeckoAppShell
         ConnectivityManager cm = (ConnectivityManager)
             GeckoApp.mAppContext.getSystemService(Context.CONNECTIVITY_SERVICE);
         if (cm.getActiveNetworkInfo() == null)
             return false;
         return true;
     }
 
     public static void setSelectedLocale(String localeCode) {
-        SharedPreferences settings =
+        /* We're not using this, not need to save it (see bug 635342)
+          SharedPreferences settings =
             GeckoApp.mAppContext.getPreferences(Activity.MODE_PRIVATE);
         settings.edit().putString(GeckoApp.mAppContext.getPackageName() + ".locale",
                                   localeCode).commit();
+        */
         Locale locale;
         int index;
         if ((index = localeCode.indexOf('-')) != -1 ||
             (index = localeCode.indexOf('_')) != -1) {
             String langCode = localeCode.substring(0, index);
             String countryCode = localeCode.substring(index + 1);
             locale = new Locale(langCode, countryCode);
         } else {
--- a/mobile/android/base/GeckoThread.java
+++ b/mobile/android/base/GeckoThread.java
@@ -33,46 +33,48 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 package org.mozilla.gecko;
 
 import android.content.Intent;
-import android.content.SharedPreferences;
 import android.content.res.Resources;
 import android.content.res.Configuration;
 import android.util.Log;
 import android.widget.AbsoluteLayout;
 import java.io.File;
 import java.io.FilenameFilter;
 import java.io.PrintWriter;
 import java.io.StringWriter;
 import java.util.Date;
 import java.util.Locale;
 
 public class GeckoThread extends Thread {
     private static final String LOGTAG = "GeckoThread";
 
     Intent mIntent;
+    String mUri;
+    String mTitle;
 
-    GeckoThread (Intent intent) {
+    GeckoThread (Intent intent, String uri, String title) {
         mIntent = intent;
+        mUri = uri;
+        mTitle = title;
     }
 
     public void run() {
         final GeckoApp app = GeckoApp.mAppContext;
         Intent intent = mIntent;
         String uri = intent.getDataString();
         String title = uri;
         if (!app.mUserDefinedProfile && (uri == null || uri.length() == 0)) {
-            SharedPreferences prefs = app.getSharedPreferences("GeckoApp", app.MODE_PRIVATE);
-            uri = prefs.getString("last-uri", "");
-            title = prefs.getString("last-title", uri);
+            uri = mUri;
+            title = mTitle;
         }
         if (uri == null || uri.equals("") || uri.equals("about:home")) {
             app.showAboutHome();
         }
         File cacheFile = GeckoAppShell.getCacheDir();
         File libxulFile = new File(cacheFile, "libxul.so");
 
         if ((!libxulFile.exists() ||
--- a/mobile/android/base/gfx/PlaceholderLayerClient.java
+++ b/mobile/android/base/gfx/PlaceholderLayerClient.java
@@ -40,17 +40,16 @@ package org.mozilla.gecko.gfx;
 import org.mozilla.gecko.gfx.BufferedCairoImage;
 import org.mozilla.gecko.gfx.CairoUtils;
 import org.mozilla.gecko.gfx.FloatSize;
 import org.mozilla.gecko.gfx.LayerClient;
 import org.mozilla.gecko.gfx.PointUtils;
 import org.mozilla.gecko.gfx.SingleTileLayer;
 import org.mozilla.gecko.GeckoApp;
 import android.content.Context;
-import android.content.SharedPreferences;
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
 import android.graphics.PointF;
 import android.graphics.RectF;
 import android.os.AsyncTask;
 import android.os.Environment;
 import android.util.Log;
 import org.json.JSONException;
@@ -69,21 +68,21 @@ public class PlaceholderLayerClient exte
     private ViewportMetrics mViewport;
     private boolean mViewportUnknown;
     private int mWidth, mHeight, mFormat;
     private ByteBuffer mBuffer;
     private FetchImageTask mTask;
 
     private PlaceholderLayerClient(Context context) {
         mContext = context;
-        SharedPreferences prefs = GeckoApp.mAppContext.getPlaceholderPrefs();
+        String viewport = GeckoApp.mAppContext.getLastViewport();
         mViewportUnknown = true;
-        if (prefs.contains("viewport")) {
+        if (viewport != null) {
             try {
-                JSONObject viewportObject = new JSONObject(prefs.getString("viewport", null));
+                JSONObject viewportObject = new JSONObject(viewport);
                 mViewport = new ViewportMetrics(viewportObject);
                 mViewportUnknown = false;
             } catch (JSONException e) {
                 Log.e(LOGTAG, "Error parsing saved viewport!");
                 mViewport = new ViewportMetrics();
             }
         } else {
             mViewport = new ViewportMetrics();