Bug 855638 - Part 1: Remove previous calls to PlacesUtils.backups and move them to PlacesBackups. r=mak

This commit is contained in:
Raymond Lee 2013-04-17 14:08:11 +08:00
parent 1cce48e69f
commit 77e95e32b8
4 changed files with 20 additions and 12 deletions

View File

@ -15,8 +15,8 @@
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
Components.utils.import("resource:///modules/MigrationUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils",
"resource://gre/modules/PlacesUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "PlacesBackups",
"resource://gre/modules/PlacesBackups.jsm");
function FirefoxProfileMigrator() { }
@ -76,7 +76,7 @@ FirefoxProfileMigrator.prototype.getResources = function() {
["signons.sqlite", "key3.db"]);
let formData = getFileResource(types.FORMDATA, ["formhistory.sqlite"]);
let bookmarksBackups = getFileResource(types.OTHERDATA,
[PlacesUtils.backups.profileRelativeFolderPath]);
[PlacesBackups.profileRelativeFolderPath]);
let dictionary = getFileResource(types.OTHERDATA, ["persdict.dat"]);
return [r for each (r in [places, cookies, passwords, formData,

View File

@ -62,6 +62,10 @@ XPCOMUtils.defineLazyModuleGetter(this, "RecentWindow",
XPCOMUtils.defineLazyModuleGetter(this, "Task",
"resource://gre/modules/Task.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "PlacesBackups",
"resource://gre/modules/PlacesBackups.jsm");
const PREF_PLUGINS_NOTIFYUSER = "plugins.update.notifyUser";
const PREF_PLUGINS_UPDATEURL = "plugins.update.url";
@ -931,7 +935,7 @@ BrowserGlue.prototype = {
// from bookmarks.html, we will try to restore from JSON
if (importBookmarks && !restoreDefaultBookmarks && !importBookmarksHTML) {
// get latest JSON backup
var bookmarksBackupFile = PlacesUtils.backups.getMostRecent("json");
var bookmarksBackupFile = PlacesBackups.getMostRecent("json");
if (bookmarksBackupFile) {
// restore from JSON backup
yield BookmarkJSONUtils.importFromFile(bookmarksBackupFile, true);
@ -1102,12 +1106,12 @@ BrowserGlue.prototype = {
* @return true if bookmarks should be backed up, false if not.
*/
_shouldBackupBookmarks: function BG__shouldBackupBookmarks() {
let lastBackupFile = PlacesUtils.backups.getMostRecent();
let lastBackupFile = PlacesBackups.getMostRecent();
// Should backup bookmarks if there are no backups or the maximum interval between
// backups elapsed.
return (!lastBackupFile ||
new Date() - PlacesUtils.backups.getDateForFile(lastBackupFile) > BOOKMARKS_BACKUP_INTERVAL);
new Date() - PlacesBackups.getDateForFile(lastBackupFile) > BOOKMARKS_BACKUP_INTERVAL);
},
/**
@ -1123,7 +1127,7 @@ BrowserGlue.prototype = {
}
catch(ex) { /* Use default. */ }
yield PlacesUtils.backups.create(maxBackups); // Don't force creation.
yield PlacesBackups.create(maxBackups); // Don't force creation.
});
},

View File

@ -9,6 +9,8 @@ XPCOMUtils.defineLazyModuleGetter(this, "Task",
"resource://gre/modules/Task.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "BookmarkJSONUtils",
"resource://gre/modules/BookmarkJSONUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "PlacesBackups",
"resource://gre/modules/PlacesBackups.jsm");
var PlacesOrganizer = {
_places: null,
@ -365,13 +367,13 @@ var PlacesOrganizer = {
while (restorePopup.childNodes.length > 1)
restorePopup.removeChild(restorePopup.firstChild);
let backupFiles = PlacesUtils.backups.entries;
let backupFiles = PlacesBackups.entries;
if (backupFiles.length == 0)
return;
// Populate menu with backups.
for (let i = 0; i < backupFiles.length; i++) {
let backupDate = PlacesUtils.backups.getDateForFile(backupFiles[i]);
let backupDate = PlacesBackups.getDateForFile(backupFiles[i]);
let m = restorePopup.insertBefore(document.createElement("menuitem"),
document.getElementById("restoreFromFile"));
m.setAttribute("label",
@ -395,7 +397,7 @@ var PlacesOrganizer = {
*/
onRestoreMenuItemClick: function PO_onRestoreMenuItemClick(aMenuItem) {
let backupName = aMenuItem.getAttribute("value");
let backupFiles = PlacesUtils.backups.entries;
let backupFiles = PlacesBackups.entries;
for (let i = 0; i < backupFiles.length; i++) {
if (backupFiles[i].leafName == backupName) {
this.restoreBookmarksFromFile(backupFiles[i]);
@ -484,7 +486,7 @@ var PlacesOrganizer = {
Ci.nsIFilePicker.modeSave);
fp.appendFilter(PlacesUIUtils.getString("bookmarksRestoreFilterName"),
PlacesUIUtils.getString("bookmarksRestoreFilterExtension"));
fp.defaultString = PlacesUtils.backups.getFilenameForDate();
fp.defaultString = PlacesBackups.getFilenameForDate();
fp.displayDirectory = backupsDir;
fp.open(fpCallback);
},

View File

@ -29,7 +29,7 @@ this.PlacesBackups = {
get folder() {
let bookmarksBackupDir = Services.dirsvc.get("ProfD", Ci.nsILocalFile);
bookmarksBackupDir.append("bookmarkbackups");
bookmarksBackupDir.append(this.profileRelativeFolderPath);
if (!bookmarksBackupDir.exists()) {
bookmarksBackupDir.create(Ci.nsIFile.DIRECTORY_TYPE, parseInt("0700", 8));
if (!bookmarksBackupDir.exists())
@ -39,6 +39,8 @@ this.PlacesBackups = {
return this.folder = bookmarksBackupDir;
},
get profileRelativeFolderPath() "bookmarkbackups",
/**
* Cache current backups in a sorted (by date DESC) array.
*/