[Mypal] Stop using deprecated calls to getMostRecent().
parent
d5885a6f81
commit
e95b7edc02
|
@ -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");
|
||||||
|
@ -926,8 +926,7 @@ 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;
|
||||||
}
|
}
|
||||||
} catch(ex) {}
|
} catch(ex) {}
|
||||||
|
@ -1073,22 +1072,19 @@ BrowserGlue.prototype = {
|
||||||
}
|
}
|
||||||
|
|
||||||
let waitingForBackupToComplete = true;
|
let waitingForBackupToComplete = true;
|
||||||
if (this._shouldBackupBookmarks()) {
|
this._backupBookmarks().then(
|
||||||
waitingForBackupToComplete = false;
|
function onSuccess() {
|
||||||
this._backupBookmarks().then(
|
waitingForBackupToComplete = false;
|
||||||
function onSuccess() {
|
},
|
||||||
waitingForBackupToComplete = true;
|
function onFailure() {
|
||||||
},
|
Cu.reportError("Unable to backup bookmarks.");
|
||||||
function onFailure() {
|
waitingForBackupToComplete = false;
|
||||||
Cu.reportError("Unable to backup bookmarks.");
|
}
|
||||||
waitingForBackupToComplete = true;
|
);
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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 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
|
// Exceptionally, since this is a non-default setting and HTML format is
|
||||||
|
@ -1097,51 +1093,44 @@ BrowserGlue.prototype = {
|
||||||
// spin the event loop on shutdown until we include a watchdog to prevent
|
// spin the event loop on shutdown until we include a watchdog to prevent
|
||||||
// potential hangs (bug 518683). The asynchronous shutdown operations
|
// potential hangs (bug 518683). The asynchronous shutdown operations
|
||||||
// will then be handled by a shutdown service (bug 435058).
|
// will then be handled by a shutdown service (bug 435058).
|
||||||
waitingForHTMLExportToComplete = false;
|
waitingForHTMLExportToComplete = true;
|
||||||
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() {
|
|
||||||
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() {
|
_backupBookmarks: function() {
|
||||||
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.
|
// Should backup bookmarks if there are no backups or the maximum
|
||||||
let maxBackups = BOOKMARKS_BACKUP_MAX_BACKUPS;
|
// interval between backups elapsed.
|
||||||
try {
|
if (!lastBackupFile ||
|
||||||
maxBackups = Services.prefs.getIntPref("browser.bookmarks.max_backups");
|
new Date() - PlacesBackups.getDateForFile(lastBackupFile) > BOOKMARKS_BACKUP_INTERVAL) {
|
||||||
}
|
let maxBackups = BOOKMARKS_BACKUP_MAX_BACKUPS;
|
||||||
catch(ex) { /* Use default. */ }
|
try {
|
||||||
|
maxBackups = Services.prefs.getIntPref("browser.bookmarks.max_backups");
|
||||||
|
}
|
||||||
|
catch(ex) { /* Use default. */ }
|
||||||
|
|
||||||
yield PlacesBackups.create(maxBackups); // Don't force creation.
|
yield PlacesBackups.create(maxBackups); // Don't force creation.
|
||||||
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue