B2G/gecko/browser/components/nsBrowserGlue.js
/**
   * Initialize Places
   * - imports the bookmarks html file if bookmarks database is empty, try to
   *   restore bookmarks from a JSON backup if the backend indicates that the
   *   database was corrupt.
   *
   * These prefs can be set up by the frontend:
   *
   * WARNING: setting these preferences to true will overwite existing bookmarks
   *
   * - browser.places.importBookmarksHTML
   *   Set to true will import the bookmarks.html file from the profile folder.
   * - 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.
   */
Initialize Places
- imports the bookmarks html file if bookmarks database is empty, try to
restore bookmarks from a JSON backup if the backend indicates that the
database was corrupt.

These prefs can be set up by the frontend.

setting these preferences to true will overwite existing bookmarks

- browser.places.importBookmarksHTML
Set to true will import the bookmarks.html file from the profile folder.
- 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.
Initialize Places - imports the bookmarks html file if bookmarks database is empty try to restore bookmarks from a JSON backup if the backend indicates that the database was corrupt . These prefs can be set up by the frontend . setting these preferences to true will overwite existing bookmarks - browser . places . importBookmarksHTML Set to true will import the bookmarks . html file from the profile folder . - 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 .
function BG__initPlaces(aInitialMigrationPerformed) {
    var dbStatus = PlacesUtils.history.databaseStatus;
    var importBookmarks = !aInitialMigrationPerformed &&
                          (dbStatus == PlacesUtils.history.DATABASE_STATUS_CREATE ||
                           dbStatus == PlacesUtils.history.DATABASE_STATUS_CORRUPT);
    var importBookmarksHTML = false;
    try {
      importBookmarksHTML =
        Services.prefs.getBoolPref("browser.places.importBookmarksHTML");
      if (importBookmarksHTML)
        importBookmarks = true;
    } catch(ex) {}
    var restoreDefaultBookmarks = false;
    try {
      restoreDefaultBookmarks =
        Services.prefs.getBoolPref("browser.bookmarks.restore_default_bookmarks");
      if (restoreDefaultBookmarks) {
        this._backupBookmarks();
        importBookmarks = true;
      }
    } catch(ex) {}
    if (importBookmarks && !restoreDefaultBookmarks && !importBookmarksHTML) {
      var bookmarksBackupFile = PlacesUtils.backups.getMostRecent("json");
      if (bookmarksBackupFile) {
        PlacesUtils.restoreBookmarksFromJSONFile(bookmarksBackupFile);
        importBookmarks = false;
      }
      else {
        importBookmarks = true;
        var dirService = Cc["@mozilla.org/file/directory_service;1"].
                         getService(Ci.nsIProperties);
        var bookmarksHTMLFile = dirService.get("BMarks", Ci.nsILocalFile);
        if (bookmarksHTMLFile.exists()) {
          importBookmarksHTML = true;
        }
        else {
          restoreDefaultBookmarks = true;
        }
      }
    }
    if (!importBookmarks) {
      this._distributionCustomizer.applyBookmarks();
      this.ensurePlacesDefaultQueriesInitialized();
    }
    else {
      var autoExportHTML = false;
      try {
        autoExportHTML = Services.prefs.getBoolPref("browser.bookmarks.autoExportHTML");
      } catch(ex) {}
      var smartBookmarksVersion = 0;
      try {
        smartBookmarksVersion = Services.prefs.getIntPref("browser.places.smartBookmarksVersion");
      } catch(ex) {}
      if (!autoExportHTML && smartBookmarksVersion != -1)
        Services.prefs.setIntPref("browser.places.smartBookmarksVersion", 0);
      var dirService = Cc["@mozilla.org/file/directory_service;1"].
                       getService(Ci.nsIProperties);
      var bookmarksURI = null;
      if (restoreDefaultBookmarks) {
        bookmarksURI = NetUtil.newURI("resource:///defaults/profile/bookmarks.html");
      }
      else {
        var bookmarksFile = dirService.get("BMarks", Ci.nsILocalFile);
        if (bookmarksFile.exists())
          bookmarksURI = NetUtil.newURI(bookmarksFile);
      }
      if (bookmarksURI) {
        try {
          BookmarkHTMLUtils.importFromURL(bookmarksURI.spec, true, (function (success) {
            if (success) {
              this._distributionCustomizer.applyBookmarks();
              this.ensurePlacesDefaultQueriesInitialized();
            }
            else {
              Cu.reportError("Bookmarks.html file could be corrupt.");
            }
          }).bind(this));
        } catch (err) {
          Cu.reportError("Bookmarks.html file could be corrupt. " + err);
        }
      }
      else {
        Cu.reportError("Unable to find bookmarks.html file.");
      }
      if (importBookmarksHTML)
        Services.prefs.setBoolPref("browser.places.importBookmarksHTML", false);
      if (restoreDefaultBookmarks)
        Services.prefs.setBoolPref("browser.bookmarks.restore_default_bookmarks",
                                   false);
    }
    if (!this._isIdleObserver) {
      this._idleService.addIdleObserver(this, BOOKMARKS_BACKUP_IDLE_TIME);
      this._isIdleObserver = true;
    }
  }
function BG__initPlaces ( aInitialMigrationPerformed ) { var dbStatus = PlacesUtils . history . databaseStatus ; var importBookmarks = ! aInitialMigrationPerformed && ( dbStatus == PlacesUtils . history . DATABASE_STATUS_CREATE || dbStatus == PlacesUtils . history . DATABASE_STATUS_CORRUPT ) ; var importBookmarksHTML = false ; try { importBookmarksHTML = Services . prefs . getBoolPref ( "browser.places.importBookmarksHTML" ) ; if ( importBookmarksHTML ) importBookmarks = true ; } catch ( ex ) { } var restoreDefaultBookmarks = false ; try { restoreDefaultBookmarks = Services . prefs . getBoolPref ( "browser.bookmarks.restore_default_bookmarks" ) ; if ( restoreDefaultBookmarks ) { this . _backupBookmarks ( ) ; importBookmarks = true ; } } catch ( ex ) { } if ( importBookmarks && ! restoreDefaultBookmarks && ! importBookmarksHTML ) { var bookmarksBackupFile = PlacesUtils . backups . getMostRecent ( "json" ) ; if ( bookmarksBackupFile ) { PlacesUtils . restoreBookmarksFromJSONFile ( bookmarksBackupFile ) ; importBookmarks = false ; } else { importBookmarks = true ; var dirService = Cc [ "@mozilla.org/file/directory_service;1" ] . getService ( Ci . nsIProperties ) ; var bookmarksHTMLFile = dirService . get ( "BMarks" , Ci . nsILocalFile ) ; if ( bookmarksHTMLFile . exists ( ) ) { importBookmarksHTML = true ; } else { restoreDefaultBookmarks = true ; } } } if ( ! importBookmarks ) { this . _distributionCustomizer . applyBookmarks ( ) ; this . ensurePlacesDefaultQueriesInitialized ( ) ; } else { var autoExportHTML = false ; try { autoExportHTML = Services . prefs . getBoolPref ( "browser.bookmarks.autoExportHTML" ) ; } catch ( ex ) { } var smartBookmarksVersion = 0 ; try { smartBookmarksVersion = Services . prefs . getIntPref ( "browser.places.smartBookmarksVersion" ) ; } catch ( ex ) { } if ( ! autoExportHTML && smartBookmarksVersion != - 1 ) Services . prefs . setIntPref ( "browser.places.smartBookmarksVersion" , 0 ) ; var dirService = Cc [ "@mozilla.org/file/directory_service;1" ] . getService ( Ci . nsIProperties ) ; var bookmarksURI = null ; if ( restoreDefaultBookmarks ) { bookmarksURI = NetUtil . newURI ( "resource:///defaults/profile/bookmarks.html" ) ; } else { var bookmarksFile = dirService . get ( "BMarks" , Ci . nsILocalFile ) ; if ( bookmarksFile . exists ( ) ) bookmarksURI = NetUtil . newURI ( bookmarksFile ) ; } if ( bookmarksURI ) { try { BookmarkHTMLUtils . importFromURL ( bookmarksURI . spec , true , ( function ( success ) { if ( success ) { this . _distributionCustomizer . applyBookmarks ( ) ; this . ensurePlacesDefaultQueriesInitialized ( ) ; } else { Cu . reportError ( "Bookmarks.html file could be corrupt." ) ; } } ) . bind ( this ) ) ; } catch ( err ) { Cu . reportError ( "Bookmarks.html file could be corrupt. " + err ) ; } } else { Cu . reportError ( "Unable to find bookmarks.html file." ) ; } if ( importBookmarksHTML ) Services . prefs . setBoolPref ( "browser.places.importBookmarksHTML" , false ) ; if ( restoreDefaultBookmarks ) Services . prefs . setBoolPref ( "browser.bookmarks.restore_default_bookmarks" , false ) ; } if ( ! this . _isIdleObserver ) { this . _idleService . addIdleObserver ( this , BOOKMARKS_BACKUP_IDLE_TIME ) ; this . _isIdleObserver = true ; } }
Initialize Places
 - imports the bookmarks html file if bookmarks database is empty, try to
   restore bookmarks from a JSON backup if the backend indicates that the
   database was corrupt.
Initialize Places - imports the bookmarks html file if bookmarks database is empty try to restore bookmarks from a JSON backup if the backend indicates that the database was corrupt .
// 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). // If the database is corrupt or has been newly created we should // import bookmarks. // Check if user or an extension has required to import bookmarks.html // Check if Safe Mode or the user has required to restore bookmarks from // default profile's bookmarks.html // Ensure that we already have a bookmarks backup for today. // If the user did not require to restore default bookmarks, or import // from bookmarks.html, we will try to restore from JSON // get latest JSON backup // restore from JSON backup // We have created a new database but we don't have any backup available // If bookmarks.html is available in current profile import it... // ...otherwise we will restore defaults // If bookmarks are not imported, then initialize smart bookmarks.  This // happens during a common startup. // Otherwise, if any kind of import runs, smart bookmarks creation should be // delayed till the import operations has finished.  Not doing so would // cause them to be overwritten by the newly imported bookmarks. // Now apply distribution customized bookmarks. // This should always run after Places initialization. // An import operation is about to run. // Don't try to recreate smart bookmarks if autoExportHTML is true or // smart bookmarks are disabled. // Get bookmarks.html file location // User wants to restore bookmarks.html file from default profile folder // Import from bookmarks.html file. // Now apply distribution customized bookmarks. // This should always run after Places initialization. // Ensure that smart bookmarks are created once the operation is // complete. // Reset preferences, so we won't try to import again at next run // Initialize bookmark archiving on idle. // Once a day, either on idle or shutdown, bookmarks are backed up.