mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-10-22 23:27:30 +09:00
Fix bookmarks backup logic.
This is a follow-up to an incomplete patch submitted to Tycho: https://github.com/MoonchildProductions/Pale-Moon/pull/1082 Also reduces the idle time before attempting to backup in the background to 10 minutes (was 15).
This commit is contained in:
parent
a1c22f3a76
commit
83dcf0f290
1 changed files with 36 additions and 52 deletions
|
|
@ -58,8 +58,8 @@ const PREF_PLUGINS_NOTIFYUSER = "plugins.update.notifyUser";
|
||||||
const PREF_PLUGINS_UPDATEURL = "plugins.update.url";
|
const PREF_PLUGINS_UPDATEURL = "plugins.update.url";
|
||||||
|
|
||||||
// We try to backup bookmarks at idle times, to avoid doing that at shutdown.
|
// We try to backup bookmarks at idle times, to avoid doing that at shutdown.
|
||||||
// Number of idle seconds before trying to backup bookmarks. 15 minutes.
|
// Number of idle seconds before trying to backup bookmarks. 10 minutes.
|
||||||
const BOOKMARKS_BACKUP_IDLE_TIME = 15 * 60;
|
const BOOKMARKS_BACKUP_IDLE_TIME = 10 * 60;
|
||||||
// Minimum interval in milliseconds between backups.
|
// Minimum interval in milliseconds between backups.
|
||||||
const BOOKMARKS_BACKUP_INTERVAL = 86400 * 1000;
|
const BOOKMARKS_BACKUP_INTERVAL = 86400 * 1000;
|
||||||
// Maximum number of backups to create. Old ones will be purged.
|
// Maximum number of backups to create. Old ones will be purged.
|
||||||
|
|
@ -238,9 +238,9 @@ BrowserGlue.prototype = {
|
||||||
this._onPlacesShutdown();
|
this._onPlacesShutdown();
|
||||||
break;
|
break;
|
||||||
case "idle":
|
case "idle":
|
||||||
if ((this._idleService.idleTime > BOOKMARKS_BACKUP_IDLE_TIME * 1000) &&
|
if (this._idleService.idleTime > BOOKMARKS_BACKUP_IDLE_TIME * 1000) {
|
||||||
this._shouldBackupBookmarks())
|
|
||||||
this._backupBookmarks();
|
this._backupBookmarks();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case "distribution-customization-complete":
|
case "distribution-customization-complete":
|
||||||
Services.obs.removeObserver(this, "distribution-customization-complete");
|
Services.obs.removeObserver(this, "distribution-customization-complete");
|
||||||
|
|
@ -949,7 +949,6 @@ BrowserGlue.prototype = {
|
||||||
Services.prefs.getBoolPref("browser.bookmarks.restore_default_bookmarks");
|
Services.prefs.getBoolPref("browser.bookmarks.restore_default_bookmarks");
|
||||||
if (restoreDefaultBookmarks) {
|
if (restoreDefaultBookmarks) {
|
||||||
// Ensure that we already have a bookmarks backup for today.
|
// Ensure that we already have a bookmarks backup for today.
|
||||||
if (this._shouldBackupBookmarks())
|
|
||||||
yield this._backupBookmarks();
|
yield this._backupBookmarks();
|
||||||
importBookmarks = true;
|
importBookmarks = true;
|
||||||
}
|
}
|
||||||
|
|
@ -959,7 +958,7 @@ BrowserGlue.prototype = {
|
||||||
// from bookmarks.html, we will try to restore from JSON/JSONLZ4
|
// from bookmarks.html, we will try to restore from JSON/JSONLZ4
|
||||||
if (importBookmarks && !restoreDefaultBookmarks && !importBookmarksHTML) {
|
if (importBookmarks && !restoreDefaultBookmarks && !importBookmarksHTML) {
|
||||||
// get latest JSON/JSONLZ4 backup
|
// get latest JSON/JSONLZ4 backup
|
||||||
var bookmarksBackupFile = yield PlacesBackups.getMostRecentBackup();
|
var bookmarksBackupFile = PlacesBackups.getMostRecentBackup();
|
||||||
if (bookmarksBackupFile) {
|
if (bookmarksBackupFile) {
|
||||||
// restore from JSON/JSONLZ4 backup
|
// restore from JSON/JSONLZ4 backup
|
||||||
yield BookmarkJSONUtils.importFromFile(bookmarksBackupFile, true);
|
yield BookmarkJSONUtils.importFromFile(bookmarksBackupFile, true);
|
||||||
|
|
@ -1102,68 +1101,52 @@ BrowserGlue.prototype = {
|
||||||
}
|
}
|
||||||
|
|
||||||
let waitingForBackupToComplete = true;
|
let waitingForBackupToComplete = true;
|
||||||
if (this._shouldBackupBookmarks()) {
|
|
||||||
waitingForBackupToComplete = false;
|
|
||||||
this._backupBookmarks().then(
|
this._backupBookmarks().then(
|
||||||
function onSuccess() {
|
function onSuccess() {
|
||||||
waitingForBackupToComplete = true;
|
waitingForBackupToComplete = false;
|
||||||
},
|
},
|
||||||
function onFailure() {
|
function onFailure() {
|
||||||
Cu.reportError("Unable to backup bookmarks.");
|
Cu.reportError("Unable to backup bookmarks.");
|
||||||
waitingForBackupToComplete = true;
|
waitingForBackupToComplete = false;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
|
||||||
// Backup bookmarks to bookmarks.html to support apps that depend
|
// Backup bookmarks to bookmarks.html to support apps that depend
|
||||||
// on the legacy format.
|
// on the legacy format.
|
||||||
let waitingForHTMLExportToComplete = true;
|
let waitingForHTMLExportToComplete = false;
|
||||||
// If this fails to get the preference value, we don't export.
|
|
||||||
if (Services.prefs.getBoolPref("browser.bookmarks.autoExportHTML")) {
|
if (Services.prefs.getBoolPref("browser.bookmarks.autoExportHTML")) {
|
||||||
// Exceptionally, since this is a non-default setting and HTML format is
|
// Exporting to HTML is explicitly enabled.
|
||||||
// discouraged in favor of the JSON/JSONLZ4 backups, we spin the event
|
// We spin the event loop on shutdown, to wait for the export to finish.
|
||||||
// loop on shutdown, to wait for the export to finish. We cannot safely
|
waitingForHTMLExportToComplete = true;
|
||||||
// spin the event loop on shutdown until we include a watchdog to prevent
|
|
||||||
// potential hangs (bug 518683). The asynchronous shutdown operations
|
|
||||||
// will then be handled by a shutdown service (bug 435058).
|
|
||||||
waitingForHTMLExportToComplete = false;
|
|
||||||
BookmarkHTMLUtils.exportToFile(BookmarkHTMLUtils.defaultPath).then(
|
BookmarkHTMLUtils.exportToFile(BookmarkHTMLUtils.defaultPath).then(
|
||||||
function onSuccess() {
|
function onSuccess() {
|
||||||
waitingForHTMLExportToComplete = true;
|
waitingForHTMLExportToComplete = false;
|
||||||
},
|
},
|
||||||
function onFailure() {
|
function onFailure() {
|
||||||
Cu.reportError("Unable to auto export html.");
|
Cu.reportError("Unable to auto export html.");
|
||||||
waitingForHTMLExportToComplete = true;
|
waitingForHTMLExportToComplete = false;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The events loop should spin at least once because waitingForBackupToComplete
|
||||||
|
// is true before checking whether backup should be made.
|
||||||
let thread = Services.tm.currentThread;
|
let thread = Services.tm.currentThread;
|
||||||
while (!waitingForBackupToComplete || !waitingForHTMLExportToComplete) {
|
while (waitingForBackupToComplete || waitingForHTMLExportToComplete) {
|
||||||
thread.processNextEvent(true);
|
thread.processNextEvent(true);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
* Determine whether to backup bookmarks or not.
|
|
||||||
* @return true if bookmarks should be backed up, false if not.
|
|
||||||
*/
|
|
||||||
_shouldBackupBookmarks: function BG__shouldBackupBookmarks() {
|
|
||||||
let lastBackupFile = PlacesBackups.getMostRecent();
|
|
||||||
|
|
||||||
// Should backup bookmarks if there are no backups or the maximum interval between
|
|
||||||
// backups elapsed.
|
|
||||||
return (!lastBackupFile ||
|
|
||||||
new Date() - PlacesBackups.getDateForFile(lastBackupFile) > BOOKMARKS_BACKUP_INTERVAL);
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Backup bookmarks.
|
* Backup bookmarks.
|
||||||
*/
|
*/
|
||||||
_backupBookmarks: function BG__backupBookmarks() {
|
_backupBookmarks: function BG__backupBookmarks() {
|
||||||
return Task.spawn(function() {
|
return Task.spawn(function() {
|
||||||
// Backup bookmarks if there are no backups or the maximum interval between
|
let lastBackupFile = yield PlacesBackups.getMostRecentBackup();
|
||||||
// backups elapsed.
|
// We should backup bookmarks if there are no backups or the maximum
|
||||||
|
// interval between backups has lapsed.
|
||||||
|
let hasLapsed = (new Date() - PlacesBackups.getDateForFile(lastBackupFile)) > BOOKMARKS_BACKUP_INTERVAL;
|
||||||
|
if (!lastBackupFile || hasLapsed) {
|
||||||
let maxBackups = BOOKMARKS_BACKUP_MAX_BACKUPS;
|
let maxBackups = BOOKMARKS_BACKUP_MAX_BACKUPS;
|
||||||
try {
|
try {
|
||||||
maxBackups = Services.prefs.getIntPref("browser.bookmarks.max_backups");
|
maxBackups = Services.prefs.getIntPref("browser.bookmarks.max_backups");
|
||||||
|
|
@ -1171,6 +1154,7 @@ BrowserGlue.prototype = {
|
||||||
catch(ex) { /* Use default. */ }
|
catch(ex) { /* Use default. */ }
|
||||||
|
|
||||||
yield PlacesBackups.create(maxBackups); // Don't force creation.
|
yield PlacesBackups.create(maxBackups); // Don't force creation.
|
||||||
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue