Bug 1065891 - (Part 2.6) Migrate search activity default pref on app update. r=bnicholson
authorMargaret Leibovic <margaret.leibovic@gmail.com>
Mon, 29 Sep 2014 20:56:21 -0700
changeset 207916 135564e9e7f522beae4ecf382de602e3907bf15a
parent 207915 6a12c3ea84e0e6b74d72039de0a36779949f87a8
child 207917 94ff5ef6ef34240460fd73bf84013189bc89bfae
push id27569
push usercbook@mozilla.com
push dateTue, 30 Sep 2014 13:14:19 +0000
treeherderautoland@2ae57957e4bb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbnicholson
bugs1065891
milestone35.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 1065891 - (Part 2.6) Migrate search activity default pref on app update. r=bnicholson
mobile/android/chrome/content/browser.js
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -818,22 +818,42 @@ var BrowserApp = {
       });
   },
 
   onAppUpdated: function() {
     // initialize the form history and passwords databases on upgrades
     Services.obs.notifyObservers(null, "FormHistory:Init", "");
     Services.obs.notifyObservers(null, "Passwords:Init", "");
 
-    // Migrate user-set "plugins.click_to_play" pref. See bug 884694.
-    // Because the default value is true, a user-set pref means that the pref was set to false.
-    if (Services.prefs.prefHasUserValue("plugins.click_to_play")) {
-      Services.prefs.setIntPref("plugin.default.state", Ci.nsIPluginTag.STATE_ENABLED);
-      Services.prefs.clearUserPref("plugins.click_to_play");
-    }
+    // Migrate the UI if necessary.
+    const UI_VERSION = 1;
+
+    let currentUIVersion = 0;
+    try {
+      currentUIVersion = Services.prefs.getIntPref("browser.migration.version");
+    } catch(ex) {}
+
+    if (currentUIVersion >= UI_VERSION) {
+      return;
+    }
+
+    if (currentUIVersion < 1) {
+      // Migrate user-set "plugins.click_to_play" pref. See bug 884694.
+      // Because the default value is true, a user-set pref means that the pref was set to false.
+      if (Services.prefs.prefHasUserValue("plugins.click_to_play")) {
+        Services.prefs.setIntPref("plugin.default.state", Ci.nsIPluginTag.STATE_ENABLED);
+        Services.prefs.clearUserPref("plugins.click_to_play");
+      }
+
+      // Set the default search engine for the search activity.
+      SearchEngines.migrateSearchActivityDefaultPref();
+    }
+
+    // Update the migration version.
+    Services.prefs.setIntPref("browser.migration.version", UI_VERSION);
   },
 
   shutdown: function shutdown() {
     NativeWindow.uninit();
     LightWeightThemeWebInstaller.uninit();
     FormAssistant.uninit();
     IndexedDB.uninit();
     ViewportHandler.uninit();
@@ -6908,16 +6928,20 @@ var SearchEngines = {
         }
         break;
       default:
         dump("Unexpected message type observed: " + aTopic);
         break;
     }
   },
 
+  migrateSearchActivityDefaultPref: function migrateSearchActivityDefaultPref() {
+    Services.search.init(() => this._setSearchActivityDefaultPref(Services.search.defaultEngine));
+  },
+
   // Updates the search activity pref when the default engine changes.
   _setSearchActivityDefaultPref: function _setSearchActivityDefaultPref(engine) {
     // Helper function copied from nsSearchService.js. This is the logic that is used
     // to create file names for search plugin XML serialized to disk.
     function sanitizeName(aName) {
       const maxLength = 60;
       const minLength = 1;
       let name = aName.toLowerCase();