Bug 1014242 - Delay loading of distribution quickshare lists. r=wesj
authorRichard Newman <rnewman@mozilla.com>
Thu, 05 Jun 2014 11:33:52 -0700
changeset 206184 17f0049099028179eb9243851fd7d38e684443d9
parent 206183 e157171a4df1bd8e28efc425da03436fa73f333b
child 206185 82cdfd1b391408e60b25752900d850674f35c135
push id3741
push userasasaki@mozilla.com
push dateMon, 21 Jul 2014 20:25:18 +0000
treeherdermozilla-beta@4d6f46f5af68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerswesj
bugs1014242
milestone32.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 1014242 - Delay loading of distribution quickshare lists. r=wesj
mobile/android/base/widget/ActivityChooserModel.java
--- a/mobile/android/base/widget/ActivityChooserModel.java
+++ b/mobile/android/base/widget/ActivityChooserModel.java
@@ -1043,45 +1043,57 @@ public class ActivityChooserModel extend
             }
         }
     }
 
     /**
      * Command for reading the historical records from a file off the UI thread.
      */
     private void readHistoricalDataImpl() {
-        FileInputStream fis = null;
         try {
             GeckoProfile profile = GeckoProfile.get(mContext);
             File f = profile.getFile(mHistoryFileName);
             if (!f.exists()) {
                 // Fall back to the non-profile aware file if it exists...
                 File oldFile = new File(mHistoryFileName);
                 oldFile.renameTo(f);
             }
-            fis = new FileInputStream(f);
+            readHistoricalDataFromStream(new FileInputStream(f));
         } catch (FileNotFoundException fnfe) {
-            try {
-                Distribution dist = new Distribution(mContext);
-                File distFile = dist.getDistributionFile("quickshare/" + mHistoryFileName);
-                if (distFile == null) {
-                    if (DEBUG) {
-                        Log.i(LOG_TAG, "Could not open historical records file: " + mHistoryFileName);
+            final Distribution dist = Distribution.getInstance(mContext);
+            dist.addOnDistributionReadyCallback(new Runnable() {
+                @Override
+                public void run() {
+                    Log.d(LOGTAG, "Running post-distribution task: quickshare.");
+
+                    if (!dist.exists()) {
+                        return;
                     }
-                    return;
+
+                    try {
+                        File distFile = dist.getDistributionFile("quickshare/" + mHistoryFileName);
+                        if (distFile == null) {
+                            if (DEBUG) {
+                                Log.i(LOG_TAG, "Could not open historical records file: " + mHistoryFileName);
+                            }
+                            return;
+                        }
+                        readHistoricalDataFromStream(new FileInputStream(distFile));
+                    } catch (Exception ex) {
+                        if (DEBUG) {
+                            Log.i(LOG_TAG, "Could not open historical records file: " + mHistoryFileName);
+                        }
+                        return;
+                    }
                 }
-                fis = new FileInputStream(distFile);
-            } catch(Exception ex) {
-                if (DEBUG) {
-                    Log.i(LOG_TAG, "Could not open historical records file: " + mHistoryFileName);
-                }
-                return;
-            }
+            });
         }
+    }
 
+    private void readHistoricalDataFromStream(FileInputStream fis) {
         try {
             XmlPullParser parser = Xml.newPullParser();
             parser.setInput(fis, null);
 
             int type = XmlPullParser.START_DOCUMENT;
             while (type != XmlPullParser.END_DOCUMENT && type != XmlPullParser.START_TAG) {
                 type = parser.next();
             }
@@ -1119,19 +1131,19 @@ public class ActivityChooserModel extend
                     Log.i(LOG_TAG, "Read " + readRecord.toString());
                 }
             }
 
             if (DEBUG) {
                 Log.i(LOG_TAG, "Read " + historicalRecords.size() + " historical records.");
             }
         } catch (XmlPullParserException xppe) {
-            Log.e(LOG_TAG, "Error reading historical recrod file: " + mHistoryFileName, xppe);
+            Log.e(LOG_TAG, "Error reading historical record file: " + mHistoryFileName, xppe);
         } catch (IOException ioe) {
-            Log.e(LOG_TAG, "Error reading historical recrod file: " + mHistoryFileName, ioe);
+            Log.e(LOG_TAG, "Error reading historical record file: " + mHistoryFileName, ioe);
         } finally {
             if (fis != null) {
                 try {
                     fis.close();
                 } catch (IOException ioe) {
                     /* ignore */
                 }
             }
@@ -1184,21 +1196,21 @@ public class ActivityChooserModel extend
 
                 serializer.endTag(null, TAG_HISTORICAL_RECORDS);
                 serializer.endDocument();
 
                 if (DEBUG) {
                     Log.i(LOG_TAG, "Wrote " + recordCount + " historical records.");
                 }
             } catch (IllegalArgumentException iae) {
-                Log.e(LOG_TAG, "Error writing historical recrod file: " + mHistoryFileName, iae);
+                Log.e(LOG_TAG, "Error writing historical record file: " + mHistoryFileName, iae);
             } catch (IllegalStateException ise) {
-                Log.e(LOG_TAG, "Error writing historical recrod file: " + mHistoryFileName, ise);
+                Log.e(LOG_TAG, "Error writing historical record file: " + mHistoryFileName, ise);
             } catch (IOException ioe) {
-                Log.e(LOG_TAG, "Error writing historical recrod file: " + mHistoryFileName, ioe);
+                Log.e(LOG_TAG, "Error writing historical record file: " + mHistoryFileName, ioe);
             } finally {
                 mCanReadHistoricalData = true;
                 if (fos != null) {
                     try {
                         fos.close();
                     } catch (IOException e) {
                         /* ignore */
                     }