Bug 1339413 - Implement prefs for capping the amount of history we import from Chrome. r?gijs
MozReview-Commit-ID: BdlNxS76Ko9
--- a/browser/app/profile/firefox.js
+++ b/browser/app/profile/firefox.js
@@ -1530,16 +1530,19 @@ pref("browser.esedbreader.loglevel", "Er
pref("browser.laterrun.enabled", false);
pref("browser.migrate.automigrate.enabled", false);
// 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
@@ -64,16 +64,28 @@ function getDataFolder(subfoldersWin, su
* @note Google Chrome uses FILETIME / 10 as time.
* 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.
@@ -305,18 +317,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;