Bug 706733 - Use constants defined on nsIBrowserProfileMigrator rather than redefining them r=mak
authorMatthew Noorenberghe <mozilla@noorenberghe.ca>
Fri, 02 Dec 2011 01:14:33 -0800
changeset 84206 b6d90462cc6d882d15846848cbc45362f63f4f51
parent 84205 78e4144065ccb92c41672519a2842b49898a67ed
child 84207 c550ffd3ba74600b3f892a75807d21e70e253a75
push id21832
push userbmo@edmorley.co.uk
push dateWed, 11 Jan 2012 17:04:15 +0000
treeherdermozilla-central@40c9f9ff9fd5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak
bugs706733
milestone12.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 706733 - Use constants defined on nsIBrowserProfileMigrator rather than redefining them r=mak
browser/components/migration/src/ChromeProfileMigrator.js
--- a/browser/components/migration/src/ChromeProfileMigrator.js
+++ b/browser/components/migration/src/ChromeProfileMigrator.js
@@ -35,31 +35,23 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 const Cc = Components.classes;
 const Ci = Components.interfaces;
 const Cu = Components.utils;
 const Cr = Components.results;
+const MIGRATOR = Ci.nsIBrowserProfileMigrator;
 
 const LOCAL_FILE_CID = "@mozilla.org/file/local;1";
 const FILE_INPUT_STREAM_CID = "@mozilla.org/network/file-input-stream;1";
 
 const BUNDLE_MIGRATION = "chrome://browser/locale/migration/migration.properties";
 
-const MIGRATE_ALL = 0x0000;
-const MIGRATE_SETTINGS = 0x0001;
-const MIGRATE_COOKIES = 0x0002;
-const MIGRATE_HISTORY = 0x0004;
-const MIGRATE_FORMDATA = 0x0008;
-const MIGRATE_PASSWORDS = 0x0010;
-const MIGRATE_BOOKMARKS = 0x0020;
-const MIGRATE_OTHERDATA = 0x0040;
-
 const S100NS_FROM1601TO1970 = 0x19DB1DED53E8000;
 const S100NS_PER_MS = 10;
 
 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
 Components.utils.import("resource://gre/modules/Services.jsm");
 Components.utils.import("resource://gre/modules/PlacesUtils.jsm");
 Components.utils.import("resource://gre/modules/NetUtil.jsm");
 
@@ -137,69 +129,69 @@ ChromeProfileMigrator.prototype = {
   _replaceBookmarks : false,
   _sourceProfile: null,
   _profilesCache: null,
 
   /**
    * Notify to observers to start migration
    *
    * @param   aType
-   *          notification type such as MIGRATE_BOOKMARKS
+   *          notification type such as MIGRATOR.BOOKMARKS
    */
   _notifyStart : function Chrome_notifyStart(aType)
   {
     Services.obs.notifyObservers(null, "Migration:ItemBeforeMigrate", aType);
     this._pendingCount++;
   },
 
   /**
    * Notify observers that a migration error occured with an item
    *
    * @param   aType
-   *          notification type such as MIGRATE_BOOKMARKS
+   *          notification type such as MIGRATOR.BOOKMARKS
    */
   _notifyError : function Chrome_notifyError(aType)
   {
     Services.obs.notifyObservers(null, "Migration:ItemError", aType);
   },
 
   /**
    * Notify to observers to finish migration for item
    * If all items are finished, it sends migration end notification.
    *
    * @param   aType
-   *          notification type such as MIGRATE_BOOKMARKS
+   *          notification type such as MIGRATOR.BOOKMARKS
    */
   _notifyCompleted : function Chrome_notifyIfCompleted(aType)
   {
     Services.obs.notifyObservers(null, "Migration:ItemAfterMigrate", aType);
     if (--this._pendingCount == 0) {
       // All items are migrated, so we have to send end notification.
       Services.obs.notifyObservers(null, "Migration:Ended", null);
     }
   },
 
   /**
    * Migrating bookmark items
    */
   _migrateBookmarks : function Chrome_migrateBookmarks()
   {
-    this._notifyStart(MIGRATE_BOOKMARKS);
+    this._notifyStart(MIGRATOR.BOOKMARKS);
 
     try {
       PlacesUtils.bookmarks.runInBatchMode({
         _self : this,
         runBatched : function (aUserData) {
           let migrator = this._self;
           let file = Cc[LOCAL_FILE_CID].createInstance(Ci.nsILocalFile);
           file.initWithPath(migrator._paths.bookmarks);
 
           NetUtil.asyncFetch(file, function(aInputStream, aResultCode) {
             if (!Components.isSuccessCode(aResultCode)) {
-              migrator._notifyCompleted(MIGRATE_BOOKMARKS);
+              migrator._notifyCompleted(MIGRATOR.BOOKMARKS);
               return;
             }
 
             // Parse Chrome bookmark file that is JSON format
             let bookmarkJSON = NetUtil.readInputStreamToString(aInputStream,
                                                                aInputStream.available(),
                                                                { charset : "UTF-8" });
             let roots = JSON.parse(bookmarkJSON).roots;
@@ -227,33 +219,33 @@ ChromeProfileMigrator.prototype = {
                 parentId =
                   PlacesUtils.bookmarks.createFolder(parentId,
                                                      bookmarksSubfolderTitle,
                                                      PlacesUtils.bookmarks.DEFAULT_INDEX);
               }
               insertBookmarkItems(parentId, roots.other.children);
             }
 
-            migrator._notifyCompleted(MIGRATE_BOOKMARKS);
+            migrator._notifyCompleted(MIGRATOR.BOOKMARKS);
           });
         }
       }, null);
     } catch (e) {
       Cu.reportError(e);
-      this._notifyError(MIGRATE_BOOKMARKS);
-      this._notifyCompleted(MIGRATE_BOOKMARKS);
+      this._notifyError(MIGRATOR.BOOKMARKS);
+      this._notifyCompleted(MIGRATOR.BOOKMARKS);
     }
   },
 
   /**
    * Migrating history
    */
   _migrateHistory : function Chrome_migrateHistory()
   {
-    this._notifyStart(MIGRATE_HISTORY);
+    this._notifyStart(MIGRATOR.HISTORY);
 
     try {
       PlacesUtils.history.runInBatchMode({
         _self : this,
         runBatched : function (aUserData) {
           // access sqlite3 database of Chrome's history
           let file = Cc[LOCAL_FILE_CID].createInstance(Ci.nsILocalFile);
           file.initWithPath(this._self._paths.history);
@@ -300,35 +292,35 @@ ChromeProfileMigrator.prototype = {
 
             handleError : function(aError) {
               Cu.reportError("Async statement execution returned with '" +
                              aError.result + "', '" + aError.message + "'");
             },
 
             handleCompletion : function(aReason) {
               this._db.asyncClose();
-              this._self._notifyCompleted(MIGRATE_HISTORY);
+              this._self._notifyCompleted(MIGRATOR.HISTORY);
             }
           });
           stmt.finalize();
         }
       }, null);
     } catch (e) {
       Cu.reportError(e);
-      this._notifyError(MIGRATE_HISTORY);
-      this._notifyCompleted(MIGRATE_HISTORY);
+      this._notifyError(MIGRATOR.HISTORY);
+      this._notifyCompleted(MIGRATOR.HISTORY);
     }
   },
 
   /**
    * Migrating cookies
    */
   _migrateCookies : function Chrome_migrateCookies()
   {
-    this._notifyStart(MIGRATE_COOKIES);
+    this._notifyStart(MIGRATOR.COOKIES);
 
     try {
       // Access sqlite3 database of Chrome's cookie
       let file = Cc[LOCAL_FILE_CID].createInstance(Ci.nsILocalFile);
       file.initWithPath(this._paths.cookies);
 
       let dbConn = Services.storage.openUnsharedDatabase(file);
       let stmt = dbConn.createAsyncStatement(
@@ -364,24 +356,24 @@ ChromeProfileMigrator.prototype = {
 
         handleError : function(aError) {
           Cu.reportError("Async statement execution returned with '" +
                          aError.result + "', '" + aError.message + "'");
         },
 
         handleCompletion : function(aReason) {
           this._db.asyncClose();
-          this._self._notifyCompleted(MIGRATE_COOKIES);
+          this._self._notifyCompleted(MIGRATOR.COOKIES);
         },
       });
       stmt.finalize();
     } catch (e) {
       Cu.reportError(e);
-      this._notifyError(MIGRATE_COOKIES);
-      this._notifyCompleted(MIGRATE_COOKIES);
+      this._notifyError(MIGRATOR.COOKIES);
+      this._notifyCompleted(MIGRATOR.COOKIES);
     }
   },
 
   /**
    * nsIBrowserProfileMigrator interface implementation
    */
 
   /**
@@ -404,23 +396,23 @@ ChromeProfileMigrator.prototype = {
     this._sourceProfile = aProfile;
 
     Services.obs.notifyObservers(null, "Migration:Started", null);
 
     // Reset panding count.  If this count becomes 0, "Migration:Ended"
     // notification is sent
     this._pendingCount = 1;
 
-    if (aItems & MIGRATE_HISTORY)
+    if (aItems & MIGRATOR.HISTORY)
       this._migrateHistory();
 
-    if (aItems & MIGRATE_COOKIES)
+    if (aItems & MIGRATOR.COOKIES)
       this._migrateCookies();
 
-    if (aItems & MIGRATE_BOOKMARKS)
+    if (aItems & MIGRATOR.BOOKMARKS)
       this._migrateBookmarks();
 
     if (--this._pendingCount == 0) {
       // When async imports are immeditelly completed unfortunately,
       // this will be called.
       // Usually, this notification is sent by _notifyCompleted()
       Services.obs.notifyObservers(null, "Migration:Ended", null);
     }
@@ -447,17 +439,17 @@ ChromeProfileMigrator.prototype = {
 
     // bookmark and preference are JSON format
 
     try {
       let file = chromeProfileDir.clone();
       file.append("Bookmarks");
       if (file.exists()) {
         this._paths.bookmarks = file.path;
-        result += MIGRATE_BOOKMARKS;
+        result += MIGRATOR.BOOKMARKS;
       }
     } catch (e) {
       Cu.reportError(e);
     }
 
     if (!this._paths.prefs) {
       let file = chromeProfileDir.clone();
       file.append("Preferences");
@@ -466,28 +458,28 @@ ChromeProfileMigrator.prototype = {
 
     // history and cookies are SQLite database
 
     try {
       let file = chromeProfileDir.clone();
       file.append("History");
       if (file.exists()) {
         this._paths.history = file.path;
-        result += MIGRATE_HISTORY;
+        result += MIGRATOR.HISTORY;
       }
     } catch (e) {
       Cu.reportError(e);
     }
 
     try {
       let file = chromeProfileDir.clone();
       file.append("Cookies");
       if (file.exists()) {
         this._paths.cookies = file.path;
-        result += MIGRATE_COOKIES;
+        result += MIGRATOR.COOKIES;
       }
     } catch (e) {
       Cu.reportError(e);
     }
 
     return result;
   },