Bug 1160450 - Places Maintenance never runs. r=ttaubert, a=lizzard
authorMarco Bonardo <mbonardo@mozilla.com>
Fri, 01 May 2015 10:42:48 +0200
changeset 267320 0263beaa3556b9f7fb9723211141696c473df884
parent 267319 20bcf9c3e9b7afe1075b7a644e9986e4d30b55fc
child 267321 925a441b9187ce3470cf40dea9ba456bceab3826
push id830
push userraliiev@mozilla.com
push dateFri, 19 Jun 2015 19:24:37 +0000
treeherdermozilla-release@932614382a68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersttaubert, lizzard
bugs1160450
milestone39.0a2
Bug 1160450 - Places Maintenance never runs. r=ttaubert, a=lizzard
toolkit/components/places/PlacesDBUtils.jsm
toolkit/components/places/tests/unit/test_preventive_maintenance.js
toolkit/components/places/tests/unit/test_telemetry.js
--- a/toolkit/components/places/PlacesDBUtils.jsm
+++ b/toolkit/components/places/PlacesDBUtils.jsm
@@ -62,17 +62,16 @@ this.PlacesDBUtils = {
       }
 
       if (aTasks.callback) {
         let scope = aTasks.scope || Cu.getGlobalForObject(aTasks.callback);
         aTasks.callback.call(scope, aTasks.messages);
       }
 
       // Notify observers that maintenance finished.
-      Services.prefs.setIntPref("places.database.lastMaintenance", parseInt(Date.now() / 1000));
       Services.obs.notifyObservers(null, FINISHED_MAINTENANCE_TOPIC, null);
     }
   },
 
   _isShuttingDown : false,
   shutdown: function PDBU_shutdown() {
     PlacesDBUtils._isShuttingDown = true;
   },
@@ -89,17 +88,22 @@ this.PlacesDBUtils = {
   maintenanceOnIdle: function PDBU_maintenanceOnIdle(aCallback, aScope)
   {
     let tasks = new Tasks([
       this.checkIntegrity
     , this.checkCoherence
     , this._refreshUI
     ]);
     tasks._telemetryStart = Date.now();
-    tasks.callback = aCallback;
+    tasks.callback = function() {
+      Services.prefs.setIntPref("places.database.lastMaintenance",
+                                parseInt(Date.now() / 1000));
+      if (aCallback)
+        aCallback();
+    }
     tasks.scope = aScope;
     this._executeTasks(tasks);
   },
 
   /**
    * Executes integrity check, common and advanced maintenance tasks (like
    * expiration and vacuum).  Will also collect statistics on the database.
    *
--- a/toolkit/components/places/tests/unit/test_preventive_maintenance.js
+++ b/toolkit/components/places/tests/unit/test_preventive_maintenance.js
@@ -1273,24 +1273,27 @@ add_task(function test_preventive_mainte
 
   // Get current bookmarks max ID for cleanup
   let stmt = mDBConn.createStatement("SELECT MAX(id) FROM moz_bookmarks");
   stmt.executeStep();
   defaultBookmarksMaxId = stmt.getInt32(0);
   stmt.finalize();
   do_check_true(defaultBookmarksMaxId > 0);
 
-  for ([, test] in Iterator(tests)) {
+  for (let [, test] in Iterator(tests)) {
     dump("\nExecuting test: " + test.name + "\n" + "*** " + test.desc + "\n");
     yield test.setup();
 
     let promiseMaintenanceFinished =
         promiseTopicObserved(FINISHED_MAINTENANCE_NOTIFICATION_TOPIC);
-    PlacesDBUtils.maintenanceOnIdle();
+    Services.prefs.clearUserPref("places.database.lastMaintenance");
+    let callbackInvoked = false;
+    PlacesDBUtils.maintenanceOnIdle(() => callbackInvoked = true);
     yield promiseMaintenanceFinished;
+    do_check_true(callbackInvoked);
 
     // Check the lastMaintenance time has been saved.
     do_check_neq(Services.prefs.getIntPref("places.database.lastMaintenance"), null);
 
     if (test.asyncCheck) {
       let deferred = Promise.defer();
       test.asyncCheck(deferred.resolve);
       yield deferred.promise;
--- a/toolkit/components/places/tests/unit/test_telemetry.js
+++ b/toolkit/components/places/tests/unit/test_telemetry.js
@@ -121,19 +121,21 @@ add_task(function test_execute()
     let validate = histograms[histogramId];
     let snapshot = Services.telemetry.getHistogramById(histogramId).snapshot();
     validate(snapshot.sum);
     do_check_true(snapshot.counts.reduce(function(a, b) a + b) > 0);
   }
 });
 
 add_test(function test_healthreport_callback() {
+  Services.prefs.clearUserPref("places.database.lastMaintenance");
   PlacesDBUtils.telemetry(null, function onResult(data) {
     do_check_neq(data, null);
 
     do_check_eq(Object.keys(data).length, 2);
     do_check_eq(data.PLACES_PAGES_COUNT, 1);
     do_check_eq(data.PLACES_BOOKMARKS_COUNT, 1);
 
+    do_check_true(!Services.prefs.prefHasUserValue("places.database.lastMaintenance"));
     run_next_test();
   });
 });