Bug 1238785 - Start file cleanup in onStart. r=ahunt draft
authorMichael Comella <michael.l.comella@gmail.com>
Tue, 12 Apr 2016 16:59:50 -0700
changeset 350221 45940791001c81c24cb493dab7a5feddc3c8e7ff
parent 350220 2ab0e0f3e618f63b81dda92f83d4e5b669acd900
child 518271 7e756ba28c8c0e3a89f90d9a696e11290932aec8
push id15272
push usermichael.l.comella@gmail.com
push dateWed, 13 Apr 2016 00:15:45 +0000
reviewersahunt
bugs1238785
milestone48.0a1
Bug 1238785 - Start file cleanup in onStart. r=ahunt I added some log statements to ensure this worked correctly locally - on a new profile: * Log statements were printed listed the two files I expected to be deleted and their paths * The log statements did not appear after closing and reopened fennec, meaning the process short-circuited as expected. Ideally, I'd test that a profile that currently has these files actually gets them deleted, but it's not easy to create profiles. The previous patches also contributed unit tests. MozReview-Commit-ID: 1FOZraATc6x
mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
--- a/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
@@ -15,16 +15,17 @@ import org.json.JSONArray;
 import org.mozilla.gecko.adjust.AdjustHelperInterface;
 import org.mozilla.gecko.annotation.RobocopTarget;
 import org.mozilla.gecko.AppConstants.Versions;
 import org.mozilla.gecko.DynamicToolbar.VisibilityTransition;
 import org.mozilla.gecko.GeckoProfileDirectories.NoMozillaDirectoryException;
 import org.mozilla.gecko.Tabs.TabEvents;
 import org.mozilla.gecko.animation.PropertyAnimator;
 import org.mozilla.gecko.animation.ViewHelper;
+import org.mozilla.gecko.cleanup.FileCleanupController;
 import org.mozilla.gecko.db.BrowserContract;
 import org.mozilla.gecko.db.BrowserDB;
 import org.mozilla.gecko.db.SuggestedSites;
 import org.mozilla.gecko.distribution.Distribution;
 import org.mozilla.gecko.dlc.DownloadContentService;
 import org.mozilla.gecko.dlc.catalog.DownloadContent;
 import org.mozilla.gecko.favicons.Favicons;
 import org.mozilla.gecko.favicons.OnFaviconLoadedListener;
@@ -1045,16 +1046,21 @@ public class BrowserApp extends GeckoApp
                 if (profile.inGuestMode()) {
                     GuestSession.showNotification(BrowserApp.this);
                 } else {
                     // If we're restarting, we won't destroy the activity.
                     // Make sure we remove any guest notifications that might
                     // have been shown.
                     GuestSession.hideNotification(BrowserApp.this);
                 }
+
+                // It'd be better to launch this once, in onCreate, but there's ambiguity for when the
+                // profile is created so we run here instead. Don't worry, call start short-circuits pretty fast.
+                final SharedPreferences sharedPrefs = GeckoSharedPrefs.forProfileName(BrowserApp.this, profile.getName());
+                FileCleanupController.startIfReady(BrowserApp.this, sharedPrefs, profile.getDir().getAbsolutePath());
             }
         });
 
         // We don't upload in onCreate because that's only called when the Activity needs to be instantiated
         // and it's possible the system will never free the Activity from memory.
         //
         // We don't upload in onResume/onPause because that will be called each time the Activity is obscured,
         // including by our own Activities/dialogs, and there is no reason to upload each time we're unobscured.