Bug 1124185 - Replace removeAllPages with history.clear() and deprecate it. r=mak draft
authorAndrew Krawchyk <akrawchyk@gmail.com>
Wed, 28 Oct 2015 13:51:59 -0400
changeset 304050 a15151c15499799b923ad64a63e9d1556f51c358
parent 304028 fc706d376f0658e560a59c3dd520437b18e8c4a4
child 510628 91bc4b4c7f229f823851823d554e13eee62162ed
push id6883
push userakrawchyk@gmail.com
push dateWed, 28 Oct 2015 17:59:19 +0000
reviewersmak
bugs1124185
milestone44.0a1
Bug 1124185 - Replace removeAllPages with history.clear() and deprecate it. r=mak
addon-sdk/source/test/addons/places/lib/places-helper.js
browser/components/newtab/tests/xpcshell/test_RemoteDirectoryLinksProvider.js
browser/modules/test/xpcshell/test_DirectoryLinksProvider.js
services/sync/modules/engines/history.js
toolkit/components/places/nsIBrowserHistory.idl
toolkit/components/places/nsNavHistory.cpp
toolkit/components/places/nsPlacesExpiration.js
toolkit/components/places/tests/sync/xpcshell.ini
--- a/addon-sdk/source/test/addons/places/lib/places-helper.js
+++ b/addon-sdk/source/test/addons/places/lib/places-helper.js
@@ -1,14 +1,14 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  'use strict'
 
-const { Cc, Ci } = require('chrome');
+const { Cc, Ci, Cu } = require('chrome');
 const bmsrv = Cc['@mozilla.org/browser/nav-bookmarks-service;1'].
                     getService(Ci.nsINavBookmarksService);
 const hsrv = Cc['@mozilla.org/browser/nav-history-service;1'].
               getService(Ci.nsINavHistoryService);
 const brsrv = Cc["@mozilla.org/browser/nav-history-service;1"]
                      .getService(Ci.nsIBrowserHistory);
 const tagsrv = Cc['@mozilla.org/browser/tagging-service;1'].
               getService(Ci.nsITaggingService);
@@ -21,16 +21,21 @@ const { defer, all } = require('sdk/core
 const { once } = require('sdk/system/events');
 const { set } = require('sdk/preferences/service');
 const {
   Bookmark, Group, Separator,
   save, search,
   MENU, TOOLBAR, UNSORTED
 } = require('sdk/places/bookmarks');
 
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+
+XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils",
+  "resource://gre/modules/PlacesUtils.jsm");
+
 function invalidResolve (assert) {
   return function (e) {
     assert.fail('Resolve state should not be called: ' + e);
   };
 }
 exports.invalidResolve = invalidResolve;
 
 // Removes all children of group
@@ -40,18 +45,17 @@ function clearBookmarks (group) {
    : clearAllBookmarks();
 }
 
 function clearAllBookmarks () {
   [MENU, TOOLBAR, UNSORTED].forEach(clearBookmarks);
 }
 
 function clearHistory (done) {
-  hsrv.removeAllPages();
-  once('places-expiration-finished', done);
+  PlacesUtils.history.clear().catch(Cu.reportError).then(done);
 }
 
 // Cleans bookmarks and history and disables maintanance
 function resetPlaces (done) {
   // Set last maintenance to current time to prevent
   // Places DB maintenance occuring and locking DB
   set('places.database.lastMaintenance', Math.floor(Date.now() / 1000));
   clearAllBookmarks();
--- a/browser/components/newtab/tests/xpcshell/test_RemoteDirectoryLinksProvider.js
+++ b/browser/components/newtab/tests/xpcshell/test_RemoteDirectoryLinksProvider.js
@@ -17,16 +17,18 @@ Cu.import("resource://gre/modules/osfile
 Cu.import("resource://gre/modules/Task.jsm");
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/PlacesUtils.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "NetUtil",
   "resource://gre/modules/NetUtil.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "RemoteNewTabUtils",
   "resource:///modules/RemoteNewTabUtils.jsm");
+XPCOMUtils.defineLazyModuleGetter(this, "PlacesTestUtils",
+  "resource://testing-common/PlacesTestUtils.jsm");
 
 do_get_profile();
 
 const DIRECTORY_LINKS_FILE = "directoryLinks.json";
 const DIRECTORY_FRECENCY = 1000;
 const SUGGESTED_FRECENCY = Infinity;
 const kURLData = {"directory": [{"url":"http://example.com","title":"LocalSource"}]};
 const kTestURL = 'data:application/json,' + JSON.stringify(kURLData);
@@ -1280,18 +1282,17 @@ add_task(function test_RemoteDirectoryLi
   RemoteDirectoryLinksProvider._setFrequencyCapClick(landingUrl);
   RemoteDirectoryLinksProvider._setFrequencyCapClick("http://bar.com");
   // both tiles must have clicked
   do_check_true(RemoteDirectoryLinksProvider._frequencyCaps[landingUrl].clicked);
   do_check_true(RemoteDirectoryLinksProvider._frequencyCaps["http://bar.com"].clicked);
 
   testObserver = new UrlDeletionTester();
   RemoteDirectoryLinksProvider.addObserver(testObserver);
-  // remove all hostory
-  PlacesUtils.bhistory.removeAllPages();
+  yield PlacesTestUtils.clearHistory();
 
   yield testObserver.promise;
   RemoteDirectoryLinksProvider.removeObserver(testObserver);
   // no clicks should remain in the cap object
   do_check_false(RemoteDirectoryLinksProvider._frequencyCaps[landingUrl].hasOwnProperty("clicked"));
   do_check_false(RemoteDirectoryLinksProvider._frequencyCaps["http://bar.com"].hasOwnProperty("clicked"));
 
   // verify that disk written data is kosher
--- a/browser/modules/test/xpcshell/test_DirectoryLinksProvider.js
+++ b/browser/modules/test/xpcshell/test_DirectoryLinksProvider.js
@@ -17,16 +17,18 @@ Cu.import("resource://gre/modules/osfile
 Cu.import("resource://gre/modules/Task.jsm");
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/PlacesUtils.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "NetUtil",
   "resource://gre/modules/NetUtil.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "NewTabUtils",
   "resource://gre/modules/NewTabUtils.jsm");
+XPCOMUtils.defineLazyModuleGetter(this, "PlacesTestUtils",
+  "resource://testing-common/PlacesTestUtils.jsm");
 
 do_get_profile();
 
 const DIRECTORY_LINKS_FILE = "directoryLinks.json";
 const DIRECTORY_FRECENCY = 1000;
 const SUGGESTED_FRECENCY = Infinity;
 const kURLData = {"directory": [{"url":"http://example.com","title":"LocalSource"}]};
 const kTestURL = 'data:application/json,' + JSON.stringify(kURLData);
@@ -1682,18 +1684,17 @@ add_task(function test_DirectoryLinksPro
   DirectoryLinksProvider._setFrequencyCapClick(landingUrl);
   DirectoryLinksProvider._setFrequencyCapClick("http://bar.com");
   // both tiles must have clicked
   do_check_true(DirectoryLinksProvider._frequencyCaps[landingUrl].clicked);
   do_check_true(DirectoryLinksProvider._frequencyCaps["http://bar.com"].clicked);
 
   testObserver = new UrlDeletionTester();
   DirectoryLinksProvider.addObserver(testObserver);
-  // remove all hostory
-  PlacesUtils.bhistory.removeAllPages();
+  yield PlacesTestUtils.clearHistory();
 
   yield testObserver.promise;
   DirectoryLinksProvider.removeObserver(testObserver);
   // no clicks should remain in the cap object
   do_check_false(DirectoryLinksProvider._frequencyCaps[landingUrl].hasOwnProperty("clicked"));
   do_check_false(DirectoryLinksProvider._frequencyCaps["http://bar.com"].hasOwnProperty("clicked"));
 
   // verify that disk written data is kosher
--- a/services/sync/modules/engines/history.js
+++ b/services/sync/modules/engines/history.js
@@ -360,17 +360,19 @@ HistoryStore.prototype = {
     } else {
       record.deleted = true;
     }
 
     return record;
   },
 
   wipe: function HistStore_wipe() {
-    PlacesUtils.history.removeAllPages();
+    let cb = Async.makeSyncCallback();
+    PlacesUtils.history.clear().then(result => {cb(null, result)}, err => {cb(err)});
+    return Async.waitForSyncCallback(cb);
   }
 };
 
 function HistoryTracker(name, engine) {
   Tracker.call(this, name, engine);
 }
 HistoryTracker.prototype = {
   __proto__: Tracker.prototype,
--- a/toolkit/components/places/nsIBrowserHistory.idl
+++ b/toolkit/components/places/nsIBrowserHistory.idl
@@ -83,14 +83,16 @@ interface nsIBrowserHistory : nsISupport
     void removeVisitsByTimeframe(in PRTime aBeginTime,
                                  in PRTime aEndTime);
 
     /**
      * Removes all existing pages from global history.
      * Visits are removed synchronously, but pages are expired asynchronously
      * off the main-thread.
      *
+     * @deprecated Please use PlacesUtils.history.clear() instead.
+     *
      * @note The removal happens in a batch. Single removals are not notified,
      *       instead an onClearHistory notification is sent to
      *       nsINavHistoryObserver implementers.
      */
     void removeAllPages();
 };
--- a/toolkit/components/places/nsNavHistory.cpp
+++ b/toolkit/components/places/nsNavHistory.cpp
@@ -2792,16 +2792,18 @@ nsNavHistory::RemoveVisitsByTimeframe(PR
 
 // nsNavHistory::RemoveAllPages
 //
 //    This function is used to clear history.
 
 NS_IMETHODIMP
 nsNavHistory::RemoveAllPages()
 {
+  PLACES_WARN_DEPRECATED();
+
   NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread");
 
   nsresult rv = mDB->MainConn()->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
     "DELETE FROM moz_historyvisits"
   ));
   NS_ENSURE_SUCCESS(rv, rv);
 
   // Clear the registered embed visits.
--- a/toolkit/components/places/nsPlacesExpiration.js
+++ b/toolkit/components/places/nsPlacesExpiration.js
@@ -192,17 +192,17 @@ const EXPIRATION_QUERIES = {
     sql: `DELETE FROM moz_historyvisits WHERE id IN (
             SELECT v_id FROM expiration_notify WHERE v_id NOTNULL
           )`,
     actions: ACTION.TIMED_OVERLIMIT | ACTION.IDLE_DIRTY | ACTION.IDLE_DAILY |
              ACTION.DEBUG
   },
 
   // Finds orphan URIs in the database.
-  // Notice we won't notify single removed URIs on removeAllPages, so we don't
+  // Notice we won't notify single removed URIs on History.clear(), so we don't
   // run this query in such a case, but just delete URIs.
   // This could run in the middle of adding a visit or bookmark to a new page.
   // In such a case since it is async, could end up expiring the orphan page
   // before it actually gets the new visit or bookmark.
   // Thus, since new pages get frecency -1, we filter on that.
   QUERY_FIND_URIS_TO_EXPIRE: {
     sql: `INSERT INTO expiration_notify
             (p_id, url, guid, visit_date, expected_results)
deleted file mode 100644
--- a/toolkit/components/places/tests/sync/xpcshell.ini
+++ /dev/null
@@ -1,18 +0,0 @@
-[DEFAULT]
-head = head_sync.js
-tail = 
-
-[test_bookmarks_sorted_by_none.js]
-[test_database_sync_after_addBookmark.js]
-[test_database_sync_after_addBookmark_batched.js]
-[test_database_sync_after_addVisit.js]
-[test_database_sync_after_addVisit_batched.js]
-[test_database_sync_after_modifyBookmark.js]
-[test_database_sync_after_shutdown.js]
-[test_database_sync_after_shutdown_with_removeAllPages.js]
-[test_database_sync_embed_visits.js]
-[test_database_sync_expireAllFavicons.js]
-[test_database_sync_onitemadded.js]
-[test_database_sync_with_specialHistoryQueries.js]
-[test_multiple_bookmarks_around_sync.js]
-[test_multiple_visits_around_sync.js]