Bug 1116446 - Part 3: Use BookmarkJSONUtils.importFromFile instead of PlacesUtils.restoreBookmarksFromJSONFile in nsSuiteGlue.js. r=Neil a=IanN for comm-aurora comm-beta CLOSED TREE
authorTooru Fujisawa <arai_a@mac.com>
Tue, 30 Dec 2014 21:30:29 +0900
changeset 25593 0c59a68dbe20e039ac698cfd10ef783582aa1e85
parent 25592 d4bc15898eeb350a4c3e1322e15f71f64657bc94
child 25594 4462b7b3777a313843f60f0653f7a68850881b2f
push id1850
push userclokep@gmail.com
push dateWed, 08 Mar 2017 19:29:12 +0000
treeherdercomm-esr52@028df196b2d9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersNeil, IanN
bugs1116446
Bug 1116446 - Part 3: Use BookmarkJSONUtils.importFromFile instead of PlacesUtils.restoreBookmarksFromJSONFile in nsSuiteGlue.js. r=Neil a=IanN for comm-aurora comm-beta CLOSED TREE
suite/common/src/nsSuiteGlue.js
--- a/suite/common/src/nsSuiteGlue.js
+++ b/suite/common/src/nsSuiteGlue.js
@@ -28,16 +28,22 @@ XPCOMUtils.defineLazyModuleGetter(this, 
                                   "resource://gre/modules/PlacesUtils.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "PlacesBackups",
                                   "resource://gre/modules/PlacesBackups.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "BookmarkHTMLUtils",
                                   "resource://gre/modules/BookmarkHTMLUtils.jsm");
 
+XPCOMUtils.defineLazyModuleGetter(this, "BookmarkJSONUtils",
+                                  "resource://gre/modules/BookmarkJSONUtils.jsm");
+
+XPCOMUtils.defineLazyModuleGetter(this, "Task",
+                                  "resource://gre/modules/Task.jsm");
+
 XPCOMUtils.defineLazyModuleGetter(this, "DebuggerServer",
                                   "resource://gre/modules/devtools/dbg-server.jsm");
 
 // 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.
 const BOOKMARKS_BACKUP_IDLE_TIME = 15 * 60;
 // Minimum interval in milliseconds between backups.
 const BOOKMARKS_BACKUP_INTERVAL = 86400 * 1000;
@@ -712,21 +718,21 @@ SuiteGlue.prototype = {
    * - browser.places.smartBookmarksVersion
    *   Set during HTML import to indicate that Smart Bookmarks were created.
    *   Set to -1 to disable Smart Bookmarks creation.
    *   Set to 0 to restore current Smart Bookmarks.
    * - browser.bookmarks.restore_default_bookmarks
    *   Set to true by safe-mode dialog to indicate we must restore default
    *   bookmarks.
    */
-  _initPlaces: function(aInitialMigrationPerformed) {
+  _initPlaces: Task.async(function(aInitialMigrationPerformed) {
     // We must instantiate the history service since it will tell us if we
     // need to import or restore bookmarks due to first-run, corruption or
     // forced migration (due to a major schema change).
-    var bookmarksBackupFile = PlacesBackups.getMostRecent("json");
+    var bookmarksBackupFile = yield PlacesBackups.getMostRecentBackup();
 
     // If the database is corrupt or has been newly created we should
     // import bookmarks. Same if we don't have any JSON backups, which
     // probably means that we never have used bookmarks in places yet.
     var dbStatus = PlacesUtils.history.databaseStatus;
     var importBookmarks = !aInitialMigrationPerformed &&
                           (dbStatus == PlacesUtils.history.DATABASE_STATUS_CREATE ||
                            dbStatus == PlacesUtils.history.DATABASE_STATUS_CORRUPT ||
@@ -755,17 +761,17 @@ SuiteGlue.prototype = {
     } catch(ex) {}
 
     // If the user did not require to restore default bookmarks, or import
     // from bookmarks.html, we will try to restore from JSON.
     if (importBookmarks && !restoreDefaultBookmarks && !importBookmarksHTML) {
       // Get latest JSON backup.
       if (bookmarksBackupFile) {
         // Restore from JSON backup.
-        PlacesUtils.restoreBookmarksFromJSONFile(bookmarksBackupFile);
+        yield BookmarkJSONUtils.importFromFile(bookmarksBackupFile, true);
         importBookmarks = false;
       }
       else if (dbStatus == PlacesUtils.history.DATABASE_STATUS_OK) {
         importBookmarks = false;
       }
       else {
         // We have created a new database but we don't have any backup available.
         importBookmarks = true;
@@ -846,17 +852,17 @@ SuiteGlue.prototype = {
     }
 
     // Initialize bookmark archiving on idle.
     // Once a day, either on idle or shutdown, bookmarks are backed up.
     if (!this._isIdleObserver) {
       this._idleService.addIdleObserver(this, BOOKMARKS_BACKUP_IDLE_TIME);
       this._isIdleObserver = true;
     }
-  },
+  }),
 
   /**
    * Places shut-down tasks
    * - back up bookmarks if needed.
    * - export bookmarks as HTML, if so configured.
    * - finalize components depending on Places.
    */
   _onPlacesShutdown: function() {