Bug 529855: force creation of the Mobile root when it doesn't exist (support profiles created with older builds), r=mfinkle
authorGavin Sharp <gavin@gavinsharp.com>
Thu, 19 Nov 2009 18:56:52 -0500
changeset 65825 23284f162cb84098f58fc92930b6277e794395db
parent 65824 e5645811f30b230336a75b4a6fc13a39f41c626e
child 65826 4db2f5476f015fe36a67b16e005139f2a8cca542
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs529855
Bug 529855: force creation of the Mobile root when it doesn't exist (support profiles created with older builds), r=mfinkle
mobile/components/BrowserStartup.js
--- a/mobile/components/BrowserStartup.js
+++ b/mobile/components/BrowserStartup.js
@@ -82,32 +82,44 @@ BrowserStartup.prototype = {
                   getService(Ci.nsINavHistoryService);
 
     // If the database is corrupt or has been newly created we should
     // import bookmarks.
     let databaseStatus = histsvc.databaseStatus;
     let importBookmarks = databaseStatus == histsvc.DATABASE_STATUS_CREATE ||
                           databaseStatus == histsvc.DATABASE_STATUS_CORRUPT;
 
-    if (!importBookmarks)
-      return;
+    if (!importBookmarks) {
+      // Check to see whether "mobile" root already exists. This is to handle
+      // existing profiles created with pre-1.0 builds (which won't have mobile
+      // bookmarks root). We can remove this eventually when we stop
+      // caring about users migrating to current builds with pre-1.0 profiles.
+      let annos = Cc["@mozilla.org/browser/annotation-service;1"].
+                  getService(Ci.nsIAnnotationService);
+      let mobileRootItems = annos.getItemsWithAnnotation("mobile/bookmarksRoot", {});
+      if (mobileRootItems.length > 0)
+        return; // no need to do initial import
+    }
 
     Cu.import("resource://gre/modules/utils.js");
 
     try {
       let observer = {
         onStreamComplete : function(aLoader, aContext, aStatus, aLength, aResult) {
           let converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"].
                           createInstance(Ci.nsIScriptableUnicodeConverter);
           let jsonStr = "";
           try {
             converter.charset = "UTF-8";
             jsonStr = converter.convertFromByteArray(aResult, aResult.length);
 
-            PlacesUtils.restoreBookmarksFromJSONString(jsonStr, true);
+            // aReplace=false since this may be called when there are existing
+            // bookmarks that we don't want to overwrite ("no mobile root"
+            // case from above)
+            PlacesUtils.restoreBookmarksFromJSONString(jsonStr, false);
           } catch (err) {
             Cu.reportError("Failed to parse default bookmarks from bookmarks.json: " + err);
           }
         }
       };
 
       let ioSvc = Cc["@mozilla.org/network/io-service;1"].
                   getService(Ci.nsIIOService);