Bug 706005 - Chrome migrator notifies user to close browser. r=MattN
authorBernardo P. Rittmeyer <bernardo@rittme.com>
Fri, 07 Aug 2015 23:36:32 -0700
changeset 288597 2ae99b834ad1e6b6aa6e7e5f17607cd603593400
parent 288596 aa72c5bb02342ae83109047043c1f47ea1a3a634
child 288598 61e20d581a287fe0673feb058aa0b119248a5f59
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-beta@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMattN
bugs706005
milestone42.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 706005 - Chrome migrator notifies user to close browser. r=MattN
browser/components/migration/ChromeProfileMigrator.js
browser/components/migration/MigrationUtils.jsm
browser/components/migration/content/migration.js
browser/components/migration/content/migration.xul
browser/components/migration/nsIBrowserProfileMigrator.idl
browser/locales/en-US/chrome/browser/migration/migration.dtd
--- a/browser/components/migration/ChromeProfileMigrator.js
+++ b/browser/components/migration/ChromeProfileMigrator.js
@@ -179,16 +179,23 @@ Object.defineProperty(ChromeProfileMigra
       catch(e) {
         Cu.reportError("Error parsing Chrome's preferences file: " + e);
       }
     }
     return "";
   }
 });
 
+Object.defineProperty(ChromeProfileMigrator.prototype, "sourceLocked", {
+  get: function Chrome_sourceLocked() {
+    // There is an exclusive lock on some SQLite databases. Assume they are locked for now.
+    return true;
+  },
+});
+
 function GetBookmarksResource(aProfileFolder) {
   let bookmarksFile = aProfileFolder.clone();
   bookmarksFile.append("Bookmarks");
   if (!bookmarksFile.exists())
     return null;
 
   return {
     type: MigrationUtils.resourceTypes.BOOKMARKS,
--- a/browser/components/migration/MigrationUtils.jsm
+++ b/browser/components/migration/MigrationUtils.jsm
@@ -163,16 +163,22 @@ this.MigratorPrototype = {
 
   /**
    * OVERRIDE IF AND ONLY IF your migrator supports importing the homepage.
    * @see nsIBrowserProfileMigrator
    */
   get sourceHomePageURL() "",
 
   /**
+   * Override if the data to migrate is locked/in-use and the user should
+   * probably shutdown the source browser.
+   */
+  get sourceLocked() false,
+
+  /**
    * DO NOT OVERRIDE - After deCOMing migration, the UI will just call
    * getResources.
    *
    * @see nsIBrowserProfileMigrator
    */
   getMigrateData: function MP_getMigrateData(aProfile) {
     let types = [r.type for each (r in this._getMaybeCachedResources(aProfile))];
     return types.reduce(function(a, b) a |= b, 0);
--- a/browser/components/migration/content/migration.js
+++ b/browser/components/migration/content/migration.js
@@ -59,16 +59,25 @@ var MigrationWizard = {
     os.removeObserver(this, "Migration:ItemError");
     os.removeObserver(this, "Migration:Ended");
     MigrationUtils.finishMigration();
   },
 
   // 1 - Import Source
   onImportSourcePageShow: function ()
   {
+    // Show warning message to close the selected browser when needed
+    function toggleCloseBrowserWarning() {
+      let visibility = "hidden";
+      if (group.selectedItem.id != "nothing") {
+        let migrator = MigrationUtils.getMigrator(group.selectedItem.id);
+        visibility = migrator.sourceLocked ? "visible" : "hidden";
+      }
+      document.getElementById("closeSourceBrowser").style.visibility = visibility;
+    }
     this._wiz.canRewind = false;
 
     var selectedMigrator = null;
 
     // Figure out what source apps are are available to import from:
     var group = document.getElementById("importSourceGroup");
     for (var i = 0; i < group.childNodes.length; ++i) {
       var migratorKey = group.childNodes[i].id;
@@ -81,19 +90,22 @@ var MigrationWizard = {
             selectedMigrator = group.childNodes[i];
         } else {
           // Hide this option
           group.childNodes[i].hidden = true;
         }
       }
     }
 
-    if (selectedMigrator)
+    group.addEventListener("command", toggleCloseBrowserWarning);
+
+    if (selectedMigrator) {
       group.selectedItem = selectedMigrator;
-    else {
+      toggleCloseBrowserWarning();
+    } else {
       // We didn't find a migrator, notify the user
       document.getElementById("noSources").hidden = false;
 
       this._wiz.canAdvance = false;
 
       document.getElementById("importBookmarks").hidden = true;
       document.getElementById("importAll").hidden = true;
     }
--- a/browser/components/migration/content/migration.xul
+++ b/browser/components/migration/content/migration.xul
@@ -47,16 +47,18 @@
       <radio id="canary"    label="&importFromCanary.label;"    accesskey="&importFromCanary.accesskey;"/>
 #elifdef XP_UNIX
       <radio id="chrome"    label="&importFromChrome.label;"    accesskey="&importFromChrome.accesskey;"/>
       <radio id="chromium"  label="&importFromChromium.label;"  accesskey="&importFromChromium.accesskey;"/>
 #endif
       <radio id="nothing"   label="&importFromNothing.label;"   accesskey="&importFromNothing.accesskey;" hidden="true"/>
     </radiogroup>
     <label id="noSources" hidden="true">&noMigrationSources.label;</label>
+    <spacer flex="1"/>
+    <description class="header" id="closeSourceBrowser" style="visibility:hidden">&closeSourceBrowser.label;</description>
   </wizardpage>
 
   <wizardpage id="selectProfile" pageid="selectProfile" label="&selectProfile.title;"
               next="importItems"
               onpageshow="return MigrationWizard.onSelectProfilePageShow();"
               onpagerewound="return MigrationWizard.onSelectProfilePageRewound();"
               onpageadvanced="return MigrationWizard.onSelectProfilePageAdvanced();">
     <description control="profiles">&selectProfile.label;</description>
--- a/browser/components/migration/nsIBrowserProfileMigrator.idl
+++ b/browser/components/migration/nsIBrowserProfileMigrator.idl
@@ -3,17 +3,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsISupports.idl"
 
 interface nsIArray;
 interface nsIProfileStartup;
 
-[scriptable, uuid(30e5a7ec-f71e-4f41-9dbd-7429c02132ec)]
+[scriptable, uuid(22b56ffc-3149-43c5-b5a9-b3a6b678de93)]
 interface nsIBrowserProfileMigrator : nsISupports
 {
   /**
    * profile items to migrate. use with migrate().
    */
   const unsigned short ALL         = 0x0000;
   const unsigned short SETTINGS    = 0x0001;
   const unsigned short COOKIES     = 0x0002;
@@ -38,27 +38,34 @@ interface nsIBrowserProfileMigrator : ns
    * @param   aProfile the profile that we are looking for available data
    *          to import
    * @param   aDoingStartup "true" if the profile is not currently being used.
    * @return  bit field containing profile items (see above)
    * @note    a return value of 0 represents no items rather than ALL.
    */
   unsigned short getMigrateData(in jsval aProfile, in boolean aDoingStartup);
 
-  /** 
-   * Whether or not there is any data that can be imported from this 
+  /**
+   * Whether or not there is any data that can be imported from this
    * browser (i.e. whether or not it is installed, and there exists
    * a user profile)
    */
   readonly attribute boolean          sourceExists;
 
 
-  /** 
-   * An enumeration of available profiles. If the import source does 
+  /**
+   * An enumeration of available profiles. If the import source does
    * not support profiles, this attribute is null.
    */
   readonly attribute jsval            sourceProfiles;
 
   /**
    * The import source homepage.  Returns null if not present/available
    */
   readonly attribute AUTF8String      sourceHomePageURL;
+
+
+  /**
+   * Whether the source browser data is locked/in-use meaning migration likely
+   * won't succeed and the user should be warned.
+   */
+  readonly attribute boolean          sourceLocked;
 };
--- a/browser/locales/en-US/chrome/browser/migration/migration.dtd
+++ b/browser/locales/en-US/chrome/browser/migration/migration.dtd
@@ -38,8 +38,9 @@
 <!ENTITY migrating.label                "The following items are currently being imported…">
 
 <!ENTITY selectProfile.title            "Select Profile">
 <!ENTITY selectProfile.label            "The following profiles are available to import from:">
 
 <!ENTITY done.title                     "Import Complete">
 <!ENTITY done.label                     "The following items were successfully imported:">
 
+<!ENTITY closeSourceBrowser.label       "Please ensure the selected browser is closed before continuing.">