Bug 1339413 - Implement prefs for capping the amount of history we import from Chrome. r=Gijs, a=jcristau FIREFOX_52_0b7_BUILD1 FIREFOX_52_0b7_RELEASE
authorDão Gottwald <dao@mozilla.com>
Wed, 15 Feb 2017 18:42:15 +0100
changeset 367167 820bc5bd3120853d611af1056f4a2b35528bb927
parent 367166 34b59d9839904cc0ea3029f1c58636136d3774b1
child 367169 aa37f468f432c0de882aa23d51c01cdf90339389
push id6943
push userryanvm@gmail.com
push dateThu, 16 Feb 2017 18:50:27 +0000
treeherdermozilla-beta@820bc5bd3120 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGijs, jcristau
bugs1339413
milestone52.0
Bug 1339413 - Implement prefs for capping the amount of history we import from Chrome. r=Gijs, a=jcristau MozReview-Commit-ID: BdlNxS76Ko9
browser/app/profile/firefox.js
browser/components/migration/ChromeProfileMigrator.js
--- a/browser/app/profile/firefox.js
+++ b/browser/app/profile/firefox.js
@@ -1515,16 +1515,19 @@ pref("browser.migrate.automigrate.enable
 #else
 pref("browser.migrate.automigrate.enabled", false);
 #endif
 // 4 here means the suggestion notification will be automatically
 // hidden the 4th day, so it will actually be shown on 3 different days.
 pref("browser.migrate.automigrate.daysToOfferUndo", 4);
 pref("browser.migrate.automigrate.ui.enabled", true);
 
+pref("browser.migrate.chrome.history.limit", 0);
+pref("browser.migrate.chrome.history.maxAgeInDays", 0);
+
 // Enable browser frames for use on desktop.  Only exposed to chrome callers.
 pref("dom.mozBrowserFramesEnabled", true);
 
 pref("extensions.pocket.enabled", true);
 
 pref("signon.schemeUpgrades", true);
 
 // "Simplify Page" feature in Print Preview. This feature is disabled by default
--- a/browser/components/migration/ChromeProfileMigrator.js
+++ b/browser/components/migration/ChromeProfileMigrator.js
@@ -65,16 +65,28 @@ function getDataFolder(subfoldersWin, su
  *          FILETIME is based on same structure of Windows.
  */
 function chromeTimeToDate(aTime)
 {
   return new Date((aTime * S100NS_PER_MS - S100NS_FROM1601TO1970) / 10000);
 }
 
 /**
+ * Convert Date object to Chrome time format
+ *
+ * @param   aDate
+ *          Date object or integer equivalent
+ * @return  Chrome time
+ * @note    For details on Chrome time, see chromeTimeToDate.
+ */
+function dateToChromeTime(aDate) {
+  return (aDate * 10000 + S100NS_FROM1601TO1970) / S100NS_PER_MS;
+}
+
+/**
  * Insert bookmark items into specific folder.
  *
  * @param   parentGuid
  *          GUID of the folder where items will be inserted
  * @param   items
  *          bookmark items to be inserted
  * @param   errorAccumulator
  *          function that gets called with any errors thrown so we don't drop them on the floor.
@@ -307,18 +319,30 @@ function GetHistoryResource(aProfileFold
   if (!historyFile.exists())
     return null;
 
   return {
     type: MigrationUtils.resourceTypes.HISTORY,
 
     migrate(aCallback) {
       Task.spawn(function* () {
-        let rows = yield MigrationUtils.getRowsFromDBWithoutLocks(historyFile.path, "Chrome history",
-          `SELECT url, title, last_visit_time, typed_count FROM urls WHERE hidden = 0`);
+        const MAX_AGE_IN_DAYS = Services.prefs.getIntPref("browser.migrate.chrome.history.maxAgeInDays");
+        const LIMIT = Services.prefs.getIntPref("browser.migrate.chrome.history.limit");
+
+        let query = "SELECT url, title, last_visit_time, typed_count FROM urls WHERE hidden = 0";
+        if (MAX_AGE_IN_DAYS) {
+          let maxAge = dateToChromeTime(Date.now() - MAX_AGE_IN_DAYS * 24 * 60 * 60 * 1000);
+          query += " AND last_visit_time > " + maxAge;
+        }
+        if (LIMIT) {
+          query += " ORDER BY last_visit_time DESC LIMIT " + LIMIT;
+        }
+
+        let rows =
+          yield MigrationUtils.getRowsFromDBWithoutLocks(historyFile.path, "Chrome history", query);
         let places = [];
         for (let row of rows) {
           try {
             // if having typed_count, we changes transition type to typed.
             let transType = PlacesUtils.history.TRANSITION_LINK;
             if (row.getResultByName("typed_count") > 0)
               transType = PlacesUtils.history.TRANSITION_TYPED;