Backed out changeset 5785913a71c0 (bug 1954136) for causing xpcshell failures @ test_history_engine.js CLOSED TREE
This commit is contained in:
@@ -33,8 +33,6 @@
|
||||
* The description of the page, if any.
|
||||
* @property {string|URL|nsIURI} [previewImageURL]
|
||||
* The preview image URL of the page, if any.
|
||||
* @property {string} [siteName]
|
||||
* The name of the site, if any.
|
||||
* @property {number} [frecency]
|
||||
* The frecency of the page, if any.
|
||||
* See https://firefox-source-docs.mozilla.org/browser/urlbar/ranking.html.
|
||||
@@ -91,7 +89,6 @@ const ONRESULT_CHUNK_SIZE = 300;
|
||||
// This constant determines the maximum number of remove pages before we cycle.
|
||||
const REMOVE_PAGES_CHUNKLEN = 300;
|
||||
|
||||
// eslint-disable-next-line no-shadow
|
||||
export var History = Object.freeze({
|
||||
ANNOTATION_EXPIRE_NEVER: 4,
|
||||
// Constants for the type of annotation.
|
||||
@@ -154,7 +151,7 @@ export var History = Object.freeze({
|
||||
}
|
||||
|
||||
return lazy.PlacesUtils.promiseDBConnection().then(db =>
|
||||
innerFetch(db, guidOrURI, options)
|
||||
fetch(db, guidOrURI, options)
|
||||
);
|
||||
},
|
||||
|
||||
@@ -235,7 +232,7 @@ export var History = Object.freeze({
|
||||
*
|
||||
* @throws (Error)
|
||||
* If the `url` specified was for a protocol that should not be
|
||||
* stored. @see nsNavHistory::CanAddURI
|
||||
* stored (@see nsNavHistory::CanAddURI).
|
||||
* @throws (Error)
|
||||
* If `pageInfo` has an unexpected type.
|
||||
* @throws (Error)
|
||||
@@ -287,7 +284,7 @@ export var History = Object.freeze({
|
||||
*
|
||||
* @throws (Error)
|
||||
* If the `url` specified was for a protocol that should not be
|
||||
* stored. @see nsNavHistory::CanAddURI
|
||||
* stored (@see nsNavHistory::CanAddURI).
|
||||
* @throws (Error)
|
||||
* If `pageInfos` has an unexpected type.
|
||||
* @throws (Error)
|
||||
@@ -397,11 +394,11 @@ export var History = Object.freeze({
|
||||
urlsSlice = urls.splice(0, REMOVE_PAGES_CHUNKLEN - guidsSlice.length);
|
||||
}
|
||||
|
||||
let pagesToRemove = { guids: guidsSlice, urls: urlsSlice };
|
||||
let pages = { guids: guidsSlice, urls: urlsSlice };
|
||||
|
||||
let result = await lazy.PlacesUtils.withConnectionWrapper(
|
||||
"History.sys.mjs: remove",
|
||||
db => remove(db, pagesToRemove, onResult)
|
||||
db => remove(db, pages, onResult)
|
||||
);
|
||||
|
||||
removedPages = removedPages || result;
|
||||
@@ -1041,7 +1038,7 @@ var notifyOnResult = async function (data, onResult) {
|
||||
};
|
||||
|
||||
// Inner implementation of History.fetch.
|
||||
var innerFetch = async function (db, guidOrURL, options) {
|
||||
var fetch = async function (db, guidOrURL, options) {
|
||||
let whereClauseFragment = "";
|
||||
let params = {};
|
||||
if (URL.isInstance(guidOrURL)) {
|
||||
@@ -1071,7 +1068,6 @@ var innerFetch = async function (db, guidOrURL, options) {
|
||||
FROM moz_places h ${joinFragment}
|
||||
${whereClauseFragment}
|
||||
${visitOrderFragment}`;
|
||||
/** @type {PageInfo} */
|
||||
let pageInfo = null;
|
||||
let placeId = null;
|
||||
await db.executeCached(query, params, row => {
|
||||
|
||||
@@ -18,15 +18,6 @@ ChromeUtils.defineLazyGetter(
|
||||
/^bookmarks-([0-9-]+)(?:_([0-9]+)){0,1}(?:_([a-z0-9=_+-]{24,})){0,1}\.(json(lz4)?)$/i
|
||||
);
|
||||
|
||||
/**
|
||||
* Limits the number of backup files by deleting old backups.
|
||||
*
|
||||
* @param {number} aMaxBackups
|
||||
* @param {string[]} backupFiles
|
||||
*
|
||||
* @returns {Promise<void>}
|
||||
* Resolves when the oldest files have been deleted.
|
||||
*/
|
||||
async function limitBackups(aMaxBackups, backupFiles) {
|
||||
if (
|
||||
typeof aMaxBackups == "number" &&
|
||||
@@ -43,14 +34,6 @@ async function limitBackups(aMaxBackups, backupFiles) {
|
||||
|
||||
/**
|
||||
* Appends meta-data information to a given filename.
|
||||
*
|
||||
* @param {string} aFilename
|
||||
* The file name.
|
||||
* @param {{count: string|number, hash: string}} aMetaData
|
||||
* Metadata related to the file.
|
||||
*
|
||||
* @returns {string}
|
||||
* The filename with appended metadata information.
|
||||
*/
|
||||
function appendMetaDataToFilename(aFilename, aMetaData) {
|
||||
let matches = aFilename.match(lazy.filenamesRegex);
|
||||
@@ -69,11 +52,7 @@ function appendMetaDataToFilename(aFilename, aMetaData) {
|
||||
/**
|
||||
* Gets the hash from a backup filename.
|
||||
*
|
||||
* @param {string} aFilename
|
||||
* The backup file name.
|
||||
*
|
||||
* @returns {null|string}
|
||||
* The extracted hash or null.
|
||||
* @returns the extracted hash or null.
|
||||
*/
|
||||
function getHashFromFilename(aFilename) {
|
||||
let matches = aFilename.match(lazy.filenamesRegex);
|
||||
@@ -85,11 +64,6 @@ function getHashFromFilename(aFilename) {
|
||||
|
||||
/**
|
||||
* Given two filenames, checks if they contain the same date.
|
||||
*
|
||||
* @param {string} aSourceName
|
||||
* @param {string} aTargetName
|
||||
*
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function isFilenameWithSameDate(aSourceName, aTargetName) {
|
||||
let sourceMatches = aSourceName.match(lazy.filenamesRegex);
|
||||
@@ -101,11 +75,7 @@ function isFilenameWithSameDate(aSourceName, aTargetName) {
|
||||
/**
|
||||
* Given a filename, searches for another backup with the same date.
|
||||
*
|
||||
* @param {string} aFilename
|
||||
* The name of the backup file.
|
||||
*
|
||||
* @returns {Promise<string|null>}
|
||||
* Resolves to a path string or null.
|
||||
* @returns path string or null.
|
||||
*/
|
||||
function getBackupFileForSameDate(aFilename) {
|
||||
return (async function () {
|
||||
@@ -135,8 +105,8 @@ export var PlacesBackups = {
|
||||
/**
|
||||
* Gets backup folder asynchronously.
|
||||
*
|
||||
* @returns {Promise<string>}
|
||||
* A promise that resolves to the folder string path.
|
||||
* @returns {Promise}
|
||||
* @resolve the folder (the folder string path).
|
||||
*/
|
||||
getBackupFolder: function PB_getBackupFolder() {
|
||||
return (async () => {
|
||||
@@ -152,9 +122,6 @@ export var PlacesBackups = {
|
||||
})();
|
||||
},
|
||||
|
||||
/**
|
||||
* @returns {string}
|
||||
*/
|
||||
get profileRelativeFolderPath() {
|
||||
return "bookmarkbackups";
|
||||
},
|
||||
@@ -162,8 +129,8 @@ export var PlacesBackups = {
|
||||
/**
|
||||
* Cache current backups in a sorted (by date DESC) array.
|
||||
*
|
||||
* @returns {Promise<string[]>}
|
||||
* A sorted array of string paths.
|
||||
* @returns {Promise}
|
||||
* @resolve a sorted array of string paths.
|
||||
*/
|
||||
getBackupFiles: function PB_getBackupFiles() {
|
||||
return (async () => {
|
||||
@@ -199,7 +166,7 @@ export var PlacesBackups = {
|
||||
this._backupFiles.sort((a, b) => {
|
||||
let aDate = this.getDateForFile(a);
|
||||
let bDate = this.getDateForFile(b);
|
||||
return bDate.getTime() - aDate.getTime();
|
||||
return bDate - aDate;
|
||||
});
|
||||
|
||||
return this._backupFiles;
|
||||
@@ -216,11 +183,9 @@ export var PlacesBackups = {
|
||||
/**
|
||||
* Generates a ISO date string (YYYY-MM-DD) from a Date object.
|
||||
*
|
||||
* @param {Date} dateObj
|
||||
* The date object to parse.
|
||||
*
|
||||
* @returns {string}
|
||||
* An ISO date string.
|
||||
* @param dateObj
|
||||
* The date object to parse.
|
||||
* @returns an ISO date string.
|
||||
*/
|
||||
toISODateString: function toISODateString(dateObj) {
|
||||
if (!dateObj || dateObj.constructor.name != "Date" || !dateObj.getTime()) {
|
||||
@@ -237,13 +202,13 @@ export var PlacesBackups = {
|
||||
/**
|
||||
* Creates a filename for bookmarks backup files.
|
||||
*
|
||||
* @param {Date} [aDateObj]
|
||||
* Date object used to build the filename. Will use current date if empty.
|
||||
* @param {boolean} [aCompress]
|
||||
* Determines if the file extension is json or jsonlz4. Default is json.
|
||||
*
|
||||
* @returns {string}
|
||||
* A bookmarks backup filename.
|
||||
* @param [optional] aDateObj
|
||||
* Date object used to build the filename.
|
||||
* Will use current date if empty.
|
||||
* @param [optional] bool - aCompress
|
||||
* Determines if file extension is json or jsonlz4
|
||||
Default is json
|
||||
* @returns A bookmarks backup filename.
|
||||
*/
|
||||
getFilenameForDate: function PB_getFilenameForDate(aDateObj, aCompress) {
|
||||
let dateObj = aDateObj || new Date();
|
||||
@@ -261,11 +226,8 @@ export var PlacesBackups = {
|
||||
* Creates a Date object from a backup file. The date is the backup
|
||||
* creation date.
|
||||
*
|
||||
* @param {string} aBackupFile
|
||||
* The path of the backup.
|
||||
*
|
||||
* @returns {Date}
|
||||
* A Date object for the backup's creation time.
|
||||
* @param {Sring} aBackupFile The path of the backup.
|
||||
* @returns {Date} A Date object for the backup's creation time.
|
||||
*/
|
||||
getDateForFile: function PB_getDateForFile(aBackupFile) {
|
||||
let filename = PathUtils.filename(aBackupFile);
|
||||
@@ -279,8 +241,8 @@ export var PlacesBackups = {
|
||||
/**
|
||||
* Get the most recent backup file.
|
||||
*
|
||||
* @returns {Promise<string|null>}
|
||||
* The path to the file or null if no valid backup was found.
|
||||
* @returns {Promise}
|
||||
* @result the path to the file.
|
||||
*/
|
||||
getMostRecentBackup: function PB_getMostRecentBackup() {
|
||||
return (async () => {
|
||||
@@ -302,19 +264,14 @@ export var PlacesBackups = {
|
||||
* If the backup is older than the last session, the calculated time is
|
||||
* reported to telemetry.
|
||||
*
|
||||
* @param {object} [options={}]
|
||||
* @param {number} [options.maxDays]
|
||||
* The maximum number of days a backup can be old.
|
||||
*
|
||||
* @returns {Promise<boolean>}
|
||||
* Resolves to true if a recent backup is available.
|
||||
* @param [maxDays] The maximum number of days a backup can be old.
|
||||
*/
|
||||
async hasRecentBackup({ maxDays = 3 } = {}) {
|
||||
let lastBackupFile = await PlacesBackups.getMostRecentBackup();
|
||||
if (!lastBackupFile) {
|
||||
return false;
|
||||
}
|
||||
let lastBackupTime = PlacesBackups.getDateForFile(lastBackupFile).getTime();
|
||||
let lastBackupTime = PlacesBackups.getDateForFile(lastBackupFile);
|
||||
let profileLastUse = Services.appinfo.replacedLockTime || Date.now();
|
||||
if (lastBackupTime > profileLastUse) {
|
||||
return true;
|
||||
@@ -328,11 +285,10 @@ export var PlacesBackups = {
|
||||
/**
|
||||
* Serializes bookmarks using JSON, and writes to the supplied file.
|
||||
*
|
||||
* @param {string} aFilePath
|
||||
* Path for the "bookmarks.json" file to be created.
|
||||
*
|
||||
* @returns {Promise<number>}
|
||||
* The number of serialized uri nodes.
|
||||
* @param aFilePath
|
||||
* path for the "bookmarks.json" file to be created.
|
||||
* @returns {Promise}
|
||||
* @resolves the number of serialized uri nodes.
|
||||
*/
|
||||
async saveBookmarksToJSONFile(aFilePath) {
|
||||
let { count: nodeCount, hash: hash } =
|
||||
@@ -403,14 +359,14 @@ export var PlacesBackups = {
|
||||
* Creates a dated backup in <profile>/bookmarkbackups.
|
||||
* Stores the bookmarks using a lz4 compressed JSON file.
|
||||
*
|
||||
* @param {number} [aMaxBackups]
|
||||
* The maximum number of backups to keep. If set to 0 all existing backups
|
||||
* are removed and aForceBackup is ignored, so a new one won't be created.
|
||||
* @param {boolean} [aForceBackup]
|
||||
* Forces creating a backup even if one was already created that day
|
||||
* (overwrites).
|
||||
*
|
||||
* @returns {Promise<void>}
|
||||
* @param [optional] int aMaxBackups
|
||||
* The maximum number of backups to keep. If set to 0
|
||||
* all existing backups are removed and aForceBackup is
|
||||
* ignored, so a new one won't be created.
|
||||
* @param [optional] bool aForceBackup
|
||||
* Forces creating a backup even if one was already
|
||||
* created that day (overwrites).
|
||||
* @returns {Promise}
|
||||
*/
|
||||
create: function PB_create(aMaxBackups, aForceBackup) {
|
||||
return (async () => {
|
||||
@@ -497,11 +453,10 @@ export var PlacesBackups = {
|
||||
/**
|
||||
* Gets the bookmark count for backup file.
|
||||
*
|
||||
* @param {string} aFilePath
|
||||
* The file path to the backup file.
|
||||
* @param aFilePath
|
||||
* File path The backup file.
|
||||
*
|
||||
* @returns {string|null}
|
||||
* The bookmark count or null.
|
||||
* @returns the bookmark count or null.
|
||||
*/
|
||||
getBookmarkCountForFile: function PB_getBookmarkCountForFile(aFilePath) {
|
||||
let count = null;
|
||||
@@ -517,10 +472,8 @@ export var PlacesBackups = {
|
||||
* Gets a bookmarks tree representation usable to create backups in different
|
||||
* file formats. The root or the tree is PlacesUtils.bookmarks.rootGuid.
|
||||
*
|
||||
* @returns {Promise<[object, number]>}
|
||||
* An array containing two values:
|
||||
* The first value is an object representing a tree with the places root as
|
||||
* its root. The second value the number of items the root has.
|
||||
* @returns {object}
|
||||
* an object representing a tree with the places root as its root.
|
||||
* Each bookmark is represented by an object having these properties:
|
||||
* - id: the item id (make this not enumerable after bug 824502)
|
||||
* - title: the title
|
||||
|
||||
@@ -206,7 +206,7 @@ const HistorySyncUtils = (PlacesSyncUtils.history = Object.freeze({
|
||||
if (visitDate > currentDate) {
|
||||
return currentDate;
|
||||
}
|
||||
if (visitDate.getTime() < BookmarkSyncUtils.EARLIEST_BOOKMARK_TIMESTAMP) {
|
||||
if (visitDate < BookmarkSyncUtils.EARLIEST_BOOKMARK_TIMESTAMP) {
|
||||
return new Date(BookmarkSyncUtils.EARLIEST_BOOKMARK_TIMESTAMP);
|
||||
}
|
||||
return visitDate;
|
||||
@@ -216,7 +216,7 @@ const HistorySyncUtils = (PlacesSyncUtils.history = Object.freeze({
|
||||
* Fetches the frecency for the URL provided
|
||||
*
|
||||
* @param url
|
||||
* @returns {Promise<number>} The frecency of the given url
|
||||
* @returns {number} The frecency of the given url
|
||||
*/
|
||||
async fetchURLFrecency(url) {
|
||||
let canonicalURL = lazy.PlacesUtils.SYNC_BOOKMARK_VALIDATORS.url(url);
|
||||
@@ -239,8 +239,7 @@ const HistorySyncUtils = (PlacesSyncUtils.history = Object.freeze({
|
||||
*
|
||||
* @param guids
|
||||
*
|
||||
* @returns {Promise<string[]>}
|
||||
* A new array with the guids that aren't syncable.
|
||||
* @returns {Array} new Array with the guids that aren't syncable
|
||||
*/
|
||||
async determineNonSyncableGuids(guids) {
|
||||
// Filter out hidden pages and transitions that we don't sync.
|
||||
@@ -292,8 +291,7 @@ const HistorySyncUtils = (PlacesSyncUtils.history = Object.freeze({
|
||||
* Fetch the last 20 visits (date and type of it) corresponding to a given url
|
||||
*
|
||||
* @param url
|
||||
* @returns {Promise<{date: Date, type: number}[]>}
|
||||
* Each element of the Array is an object with members: date and type
|
||||
* @returns {Array} Each element of the Array is an object with members: date and type
|
||||
*/
|
||||
async fetchVisitsForURL(url) {
|
||||
let canonicalURL = lazy.PlacesUtils.SYNC_BOOKMARK_VALIDATORS.url(url);
|
||||
@@ -333,7 +331,7 @@ const HistorySyncUtils = (PlacesSyncUtils.history = Object.freeze({
|
||||
* Fetches the guid of a uri
|
||||
*
|
||||
* @param uri
|
||||
* @returns {Promise<string>} The guid of the given uri.
|
||||
* @returns {string} The guid of the given uri
|
||||
*/
|
||||
async fetchGuidForURL(url) {
|
||||
let canonicalURL = lazy.PlacesUtils.SYNC_BOOKMARK_VALIDATORS.url(url);
|
||||
@@ -355,8 +353,7 @@ const HistorySyncUtils = (PlacesSyncUtils.history = Object.freeze({
|
||||
* Fetch information about a guid (url, title and frecency)
|
||||
*
|
||||
* @param guid
|
||||
* @returns {Promise<{url: string, title: string, frecency: number}>}
|
||||
* An object with three members: url, title and frecency of the given guid.
|
||||
* @returns {object} Object with three members: url, title and frecency of the given guid
|
||||
*/
|
||||
async fetchURLInfoForGuid(guid) {
|
||||
let db = await lazy.PlacesUtils.promiseDBConnection();
|
||||
@@ -388,17 +385,14 @@ const HistorySyncUtils = (PlacesSyncUtils.history = Object.freeze({
|
||||
},
|
||||
|
||||
/**
|
||||
* Get all URLs filtered by the specified limit and minimum visit date.
|
||||
* Get all URLs filtered by the limit and since members of the options object.
|
||||
*
|
||||
* @param {object} options
|
||||
* @param {number} options.limit
|
||||
* Maximum number of URLs to return.
|
||||
* @param {Date} options.since
|
||||
* Only include URLs visited after this date.
|
||||
* @returns {Promise<string[]>}
|
||||
* A list of URLs, up to the given limit, that were visited after the date
|
||||
* provided. Note that some visit types are explicitly excluded - downloads
|
||||
* and framed links.
|
||||
* @param options
|
||||
* Options object with two members, since and limit. Both of them must be provided
|
||||
* @returns {Array} - Up to limit number of URLs starting from the date provided by since
|
||||
*
|
||||
* Note that some visit types are explicitly excluded - downloads and framed
|
||||
* links.
|
||||
*/
|
||||
async getAllURLs(options) {
|
||||
// Check that the limit property is finite number.
|
||||
@@ -434,7 +428,7 @@ const HistorySyncUtils = (PlacesSyncUtils.history = Object.freeze({
|
||||
* Insert or update the unknownFields that this client doesn't understand (yet)
|
||||
* but stores & roundtrips them to prevent other clients from losing that data
|
||||
*
|
||||
* @param {object[]} updates array of objects
|
||||
* @param updates array of objects
|
||||
* an update object needs to have either a:
|
||||
* placeId: if we're putting unknownFields for a moz_places item
|
||||
* visitId: if we're putting unknownFields for a moz_historyvisits item
|
||||
@@ -2085,7 +2079,7 @@ async function resetAllSyncStatuses(db, syncStatus) {
|
||||
* @returns {string} json object containing unknownfields, null if none found
|
||||
*/
|
||||
PlacesSyncUtils.extractUnknownFields = (record, validFields) => {
|
||||
let result = Object.keys(record).reduce(
|
||||
let { unknownFields, hasUnknownFields } = Object.keys(record).reduce(
|
||||
({ unknownFields, hasUnknownFields }, key) => {
|
||||
if (validFields.includes(key)) {
|
||||
return { unknownFields, hasUnknownFields };
|
||||
@@ -2095,10 +2089,10 @@ PlacesSyncUtils.extractUnknownFields = (record, validFields) => {
|
||||
},
|
||||
{ unknownFields: {}, hasUnknownFields: false }
|
||||
);
|
||||
if (result.hasUnknownFields) {
|
||||
if (hasUnknownFields) {
|
||||
// For simplicity, we store the unknown fields as a string
|
||||
// since we never operate on it and just need it for roundtripping
|
||||
return JSON.stringify(result.unknownFields);
|
||||
return JSON.stringify(unknownFields);
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user