Bug 570636 - Decide how to co-exist as a sync add-on and built-in sync [r=mconnor]

Migrate prefs from extensions.weave. to services.sync. when loading the service for the first time before migration.
This commit is contained in:
Edward Lee 2010-06-16 14:30:13 -07:00
Родитель 0cbfa6f197
Коммит ce6de55601
6 изменённых файлов: 183 добавлений и 111 удалений

Просмотреть файл

@ -57,7 +57,7 @@ WeaveCrypto.prototype = {
QueryInterface: XPCOMUtils.generateQI([Ci.IWeaveCrypto]),
prefBranch : null,
debug : true, // extensions.weave.log.cryptoDebug
debug : true, // services.sync.log.cryptoDebug
nss : null,
nss_t : null,
@ -79,7 +79,7 @@ WeaveCrypto.prototype = {
init : function() {
try {
// Preferences. Add observer so we get notified of changes.
this.prefBranch = Services.prefs.getBranch("extensions.weave.log.");
this.prefBranch = Services.prefs.getBranch("services.sync.log.");
this.prefBranch.QueryInterface(Ci.nsIPrefBranch2);
this.prefBranch.addObserver("cryptoDebug", this.observer, false);
this.observer._self = this;

Просмотреть файл

@ -50,7 +50,7 @@ DEFAULT_SERVER: "@server_url@",
UPDATED_DEV_URL: "https://services.mozilla.com/sync/updated/?version=@weave_version@&channel=@xpi_type@",
UPDATED_REL_URL: "http://www.mozilla.com/firefox/sync/updated.html",
PREFS_BRANCH: "extensions.weave.",
PREFS_BRANCH: "services.sync.",
// Host "key" to access Weave Identity in the password manager
PWDMGR_HOST: "chrome://weave",

Просмотреть файл

@ -40,7 +40,7 @@ const Cc = Components.classes;
const Ci = Components.interfaces;
const Cu = Components.utils;
const WEAVE_SYNC_PREFS = "extensions.weave.prefs.sync.";
const WEAVE_SYNC_PREFS = "services.sync.prefs.sync.";
const WEAVE_PREFS_GUID = "preferences";
Cu.import("resource://services-sync/engines.js");

Просмотреть файл

@ -77,6 +77,7 @@ Cu.import("resource://services-sync/engines/history.js", Weave);
Cu.import("resource://services-sync/engines/prefs.js", Weave);
Cu.import("resource://services-sync/engines/passwords.js", Weave);
Cu.import("resource://services-sync/engines/tabs.js", Weave);
Cu.import("resource://services-sync/ext/Preferences.js");
Cu.import("resource://services-sync/identity.js", Weave);
Cu.import("resource://services-sync/notifications.js", Weave);
Cu.import("resource://services-sync/resource.js", Weave);
@ -256,6 +257,7 @@ WeaveSvc.prototype = {
* Prepare to initialize the rest of Weave after waiting a little bit
*/
onStartup: function onStartup() {
this._migratePrefs();
this._initLogs();
this._log.info("Loading Weave " + WEAVE_VERSION);
@ -325,6 +327,28 @@ WeaveSvc.prototype = {
return Status.service;
},
_migratePrefs: function _migratePrefs() {
// No need to re-migrate
if (Svc.Prefs.get("migrated", false))
return;
// Grab the list of old pref names
let oldPrefBranch = "extensions.weave.";
let oldPrefNames = Cc["@mozilla.org/preferences-service;1"].
getService(Ci.nsIPrefService).
getBranch(oldPrefBranch).
getChildList("", {});
// Map each old pref to the current pref branch
let oldPref = new Preferences(oldPrefBranch);
for each (let pref in oldPrefNames)
Svc.Prefs.set(pref, oldPref.get(pref));
// Remove all the old prefs and remember that we've migrated
oldPref.resetBranch("");
Svc.Prefs.set("migrated", true);
},
_initLogs: function WeaveSvc__initLogs() {
this._log = Log4Moz.repository.getLogger("Service.Main");
this._log.level =

Просмотреть файл

@ -1,113 +1,113 @@
pref("extensions.weave.serverURL", "@server_url@");
pref("extensions.weave.storageAPI", "1.0");
pref("extensions.weave.userURL", "user/");
pref("extensions.weave.miscURL", "misc/");
pref("extensions.weave.termsURL", "https://services.mozilla.com/tos/");
pref("extensions.weave.privacyURL", "https://services.mozilla.com/privacy-policy/");
pref("services.sync.serverURL", "@server_url@");
pref("services.sync.storageAPI", "1.0");
pref("services.sync.userURL", "user/");
pref("services.sync.miscURL", "misc/");
pref("services.sync.termsURL", "https://services.mozilla.com/tos/");
pref("services.sync.privacyURL", "https://services.mozilla.com/privacy-policy/");
pref("extensions.weave.lastversion", "firstrun");
pref("extensions.weave.autoconnect", true);
pref("services.sync.lastversion", "firstrun");
pref("services.sync.autoconnect", true);
pref("extensions.weave.engine.bookmarks", true);
pref("extensions.weave.engine.history", true);
pref("extensions.weave.engine.passwords", true);
pref("extensions.weave.engine.prefs", true);
pref("extensions.weave.engine.tabs", true);
pref("extensions.weave.engine.tabs.filteredUrls", "^(about:.*|chrome://weave/.*|wyciwyg:.*|file:.*)$");
pref("services.sync.engine.bookmarks", true);
pref("services.sync.engine.history", true);
pref("services.sync.engine.passwords", true);
pref("services.sync.engine.prefs", true);
pref("services.sync.engine.tabs", true);
pref("services.sync.engine.tabs.filteredUrls", "^(about:.*|chrome://weave/.*|wyciwyg:.*|file:.*)$");
pref("extensions.weave.log.appender.console", "Warn");
pref("extensions.weave.log.appender.dump", "Error");
pref("extensions.weave.log.appender.debugLog", "Trace");
pref("extensions.weave.log.rootLogger", "Debug");
pref("extensions.weave.log.logger.service.main", "Debug");
pref("extensions.weave.log.logger.authenticator", "Debug");
pref("extensions.weave.log.logger.network.resources", "Debug");
pref("extensions.weave.log.logger.engine.bookmarks", "Debug");
pref("extensions.weave.log.logger.engine.clients", "Debug");
pref("extensions.weave.log.logger.engine.forms", "Debug");
pref("extensions.weave.log.logger.engine.history", "Debug");
pref("extensions.weave.log.logger.engine.passwords", "Debug");
pref("extensions.weave.log.logger.engine.prefs", "Debug");
pref("extensions.weave.log.logger.engine.tabs", "Debug");
pref("extensions.weave.log.cryptoDebug", false);
pref("services.sync.log.appender.console", "Warn");
pref("services.sync.log.appender.dump", "Error");
pref("services.sync.log.appender.debugLog", "Trace");
pref("services.sync.log.rootLogger", "Debug");
pref("services.sync.log.logger.service.main", "Debug");
pref("services.sync.log.logger.authenticator", "Debug");
pref("services.sync.log.logger.network.resources", "Debug");
pref("services.sync.log.logger.engine.bookmarks", "Debug");
pref("services.sync.log.logger.engine.clients", "Debug");
pref("services.sync.log.logger.engine.forms", "Debug");
pref("services.sync.log.logger.engine.history", "Debug");
pref("services.sync.log.logger.engine.passwords", "Debug");
pref("services.sync.log.logger.engine.prefs", "Debug");
pref("services.sync.log.logger.engine.tabs", "Debug");
pref("services.sync.log.cryptoDebug", false);
// Preferences to be synced by default
pref("extensions.weave.prefs.sync.accessibility.blockautorefresh", true);
pref("extensions.weave.prefs.sync.accessibility.browsewithcaret", true);
pref("extensions.weave.prefs.sync.accessibility.typeaheadfind", true);
pref("extensions.weave.prefs.sync.accessibility.typeaheadfind.linksonly", true);
pref("extensions.weave.prefs.sync.app.update.mode", true);
pref("extensions.weave.prefs.sync.browser.download.manager.closeWhenDone", true);
pref("extensions.weave.prefs.sync.browser.download.manager.retention", true);
pref("extensions.weave.prefs.sync.browser.download.manager.scanWhenDone", true);
pref("extensions.weave.prefs.sync.browser.download.manager.showWhenStarting", true);
pref("extensions.weave.prefs.sync.browser.formfill.enable", true);
pref("extensions.weave.prefs.sync.browser.history_expire_days", true);
pref("extensions.weave.prefs.sync.browser.history_expire_days_min", true);
pref("extensions.weave.prefs.sync.browser.link.open_newwindow", true);
pref("extensions.weave.prefs.sync.browser.offline-apps.notify", true);
pref("extensions.weave.prefs.sync.browser.safebrowsing.enabled", true);
pref("extensions.weave.prefs.sync.browser.safebrowsing.malware.enabled", true);
pref("extensions.weave.prefs.sync.browser.search.selectedEngine", true);
pref("extensions.weave.prefs.sync.browser.search.update", true);
pref("extensions.weave.prefs.sync.browser.startup.homepage", true);
pref("extensions.weave.prefs.sync.browser.startup.page", true);
pref("extensions.weave.prefs.sync.browser.tabs.autoHide", true);
pref("extensions.weave.prefs.sync.browser.tabs.closeButtons", true);
pref("extensions.weave.prefs.sync.browser.tabs.loadInBackground", true);
pref("extensions.weave.prefs.sync.browser.tabs.tabMaxWidth", true);
pref("extensions.weave.prefs.sync.browser.tabs.tabMinWidth", true);
pref("extensions.weave.prefs.sync.browser.tabs.warnOnClose", true);
pref("extensions.weave.prefs.sync.browser.tabs.warnOnOpen", true);
pref("extensions.weave.prefs.sync.browser.urlbar.autocomplete.enabled", true);
pref("extensions.weave.prefs.sync.browser.urlbar.autoFill", true);
pref("extensions.weave.prefs.sync.browser.urlbar.default.behavior", true);
pref("extensions.weave.prefs.sync.browser.urlbar.maxRichResults", true);
pref("extensions.weave.prefs.sync.dom.disable_open_during_load", true);
pref("extensions.weave.prefs.sync.dom.disable_window_flip", true);
pref("extensions.weave.prefs.sync.dom.disable_window_move_resize", true);
pref("extensions.weave.prefs.sync.dom.disable_window_open_feature.status", true);
pref("extensions.weave.prefs.sync.dom.disable_window_status_change", true);
pref("extensions.weave.prefs.sync.dom.event.contextmenu.enabled", true);
pref("extensions.weave.prefs.sync.extensions.personas.current", true);
pref("extensions.weave.prefs.sync.extensions.update.enabled", true);
pref("extensions.weave.prefs.sync.general.autoScroll", true);
pref("extensions.weave.prefs.sync.general.smoothScroll", true);
pref("extensions.weave.prefs.sync.intl.accept_languages", true);
pref("extensions.weave.prefs.sync.javascript.enabled", true);
pref("extensions.weave.prefs.sync.layout.spellcheckDefault", true);
pref("extensions.weave.prefs.sync.lightweightThemes.isThemeSelected", true);
pref("extensions.weave.prefs.sync.lightweightThemes.usedThemes", true);
pref("extensions.weave.prefs.sync.network.cookie.cookieBehavior", true);
pref("extensions.weave.prefs.sync.network.cookie.lifetimePolicy", true);
pref("extensions.weave.prefs.sync.permissions.default.image", true);
pref("extensions.weave.prefs.sync.pref.advanced.images.disable_button.view_image", true);
pref("extensions.weave.prefs.sync.pref.advanced.javascript.disable_button.advanced", true);
pref("extensions.weave.prefs.sync.pref.downloads.disable_button.edit_actions", true);
pref("extensions.weave.prefs.sync.pref.privacy.disable_button.cookie_exceptions", true);
pref("extensions.weave.prefs.sync.privacy.clearOnShutdown.cache", true);
pref("extensions.weave.prefs.sync.privacy.clearOnShutdown.cookies", true);
pref("extensions.weave.prefs.sync.privacy.clearOnShutdown.downloads", true);
pref("extensions.weave.prefs.sync.privacy.clearOnShutdown.formdata", true);
pref("extensions.weave.prefs.sync.privacy.clearOnShutdown.history", true);
pref("extensions.weave.prefs.sync.privacy.clearOnShutdown.offlineApps", true);
pref("extensions.weave.prefs.sync.privacy.clearOnShutdown.passwords", true);
pref("extensions.weave.prefs.sync.privacy.clearOnShutdown.sessions", true);
pref("extensions.weave.prefs.sync.privacy.clearOnShutdown.siteSettings", true);
pref("extensions.weave.prefs.sync.privacy.sanitize.sanitizeOnShutdown", true);
pref("extensions.weave.prefs.sync.security.OCSP.disable_button.managecrl", true);
pref("extensions.weave.prefs.sync.security.OCSP.enabled", true);
pref("extensions.weave.prefs.sync.security.OCSP.require", true);
pref("extensions.weave.prefs.sync.security.default_personal_cert", true);
pref("extensions.weave.prefs.sync.security.enable_java", true);
pref("extensions.weave.prefs.sync.security.enable_ssl3", true);
pref("extensions.weave.prefs.sync.security.enable_tls", true);
pref("extensions.weave.prefs.sync.security.warn_entering_secure", true);
pref("extensions.weave.prefs.sync.security.warn_entering_weak", true);
pref("extensions.weave.prefs.sync.security.warn_leaving_secure", true);
pref("extensions.weave.prefs.sync.security.warn_submit_insecure", true);
pref("extensions.weave.prefs.sync.security.warn_viewing_mixed", true);
pref("extensions.weave.prefs.sync.signon.rememberSignons", true);
pref("extensions.weave.prefs.sync.spellchecker.dictionary", true);
pref("extensions.weave.prefs.sync.xpinstall.whitelist.required", true);
pref("services.sync.prefs.sync.accessibility.blockautorefresh", true);
pref("services.sync.prefs.sync.accessibility.browsewithcaret", true);
pref("services.sync.prefs.sync.accessibility.typeaheadfind", true);
pref("services.sync.prefs.sync.accessibility.typeaheadfind.linksonly", true);
pref("services.sync.prefs.sync.app.update.mode", true);
pref("services.sync.prefs.sync.browser.download.manager.closeWhenDone", true);
pref("services.sync.prefs.sync.browser.download.manager.retention", true);
pref("services.sync.prefs.sync.browser.download.manager.scanWhenDone", true);
pref("services.sync.prefs.sync.browser.download.manager.showWhenStarting", true);
pref("services.sync.prefs.sync.browser.formfill.enable", true);
pref("services.sync.prefs.sync.browser.history_expire_days", true);
pref("services.sync.prefs.sync.browser.history_expire_days_min", true);
pref("services.sync.prefs.sync.browser.link.open_newwindow", true);
pref("services.sync.prefs.sync.browser.offline-apps.notify", true);
pref("services.sync.prefs.sync.browser.safebrowsing.enabled", true);
pref("services.sync.prefs.sync.browser.safebrowsing.malware.enabled", true);
pref("services.sync.prefs.sync.browser.search.selectedEngine", true);
pref("services.sync.prefs.sync.browser.search.update", true);
pref("services.sync.prefs.sync.browser.startup.homepage", true);
pref("services.sync.prefs.sync.browser.startup.page", true);
pref("services.sync.prefs.sync.browser.tabs.autoHide", true);
pref("services.sync.prefs.sync.browser.tabs.closeButtons", true);
pref("services.sync.prefs.sync.browser.tabs.loadInBackground", true);
pref("services.sync.prefs.sync.browser.tabs.tabMaxWidth", true);
pref("services.sync.prefs.sync.browser.tabs.tabMinWidth", true);
pref("services.sync.prefs.sync.browser.tabs.warnOnClose", true);
pref("services.sync.prefs.sync.browser.tabs.warnOnOpen", true);
pref("services.sync.prefs.sync.browser.urlbar.autocomplete.enabled", true);
pref("services.sync.prefs.sync.browser.urlbar.autoFill", true);
pref("services.sync.prefs.sync.browser.urlbar.default.behavior", true);
pref("services.sync.prefs.sync.browser.urlbar.maxRichResults", true);
pref("services.sync.prefs.sync.dom.disable_open_during_load", true);
pref("services.sync.prefs.sync.dom.disable_window_flip", true);
pref("services.sync.prefs.sync.dom.disable_window_move_resize", true);
pref("services.sync.prefs.sync.dom.disable_window_open_feature.status", true);
pref("services.sync.prefs.sync.dom.disable_window_status_change", true);
pref("services.sync.prefs.sync.dom.event.contextmenu.enabled", true);
pref("services.sync.prefs.sync.extensions.personas.current", true);
pref("services.sync.prefs.sync.extensions.update.enabled", true);
pref("services.sync.prefs.sync.general.autoScroll", true);
pref("services.sync.prefs.sync.general.smoothScroll", true);
pref("services.sync.prefs.sync.intl.accept_languages", true);
pref("services.sync.prefs.sync.javascript.enabled", true);
pref("services.sync.prefs.sync.layout.spellcheckDefault", true);
pref("services.sync.prefs.sync.lightweightThemes.isThemeSelected", true);
pref("services.sync.prefs.sync.lightweightThemes.usedThemes", true);
pref("services.sync.prefs.sync.network.cookie.cookieBehavior", true);
pref("services.sync.prefs.sync.network.cookie.lifetimePolicy", true);
pref("services.sync.prefs.sync.permissions.default.image", true);
pref("services.sync.prefs.sync.pref.advanced.images.disable_button.view_image", true);
pref("services.sync.prefs.sync.pref.advanced.javascript.disable_button.advanced", true);
pref("services.sync.prefs.sync.pref.downloads.disable_button.edit_actions", true);
pref("services.sync.prefs.sync.pref.privacy.disable_button.cookie_exceptions", true);
pref("services.sync.prefs.sync.privacy.clearOnShutdown.cache", true);
pref("services.sync.prefs.sync.privacy.clearOnShutdown.cookies", true);
pref("services.sync.prefs.sync.privacy.clearOnShutdown.downloads", true);
pref("services.sync.prefs.sync.privacy.clearOnShutdown.formdata", true);
pref("services.sync.prefs.sync.privacy.clearOnShutdown.history", true);
pref("services.sync.prefs.sync.privacy.clearOnShutdown.offlineApps", true);
pref("services.sync.prefs.sync.privacy.clearOnShutdown.passwords", true);
pref("services.sync.prefs.sync.privacy.clearOnShutdown.sessions", true);
pref("services.sync.prefs.sync.privacy.clearOnShutdown.siteSettings", true);
pref("services.sync.prefs.sync.privacy.sanitize.sanitizeOnShutdown", true);
pref("services.sync.prefs.sync.security.OCSP.disable_button.managecrl", true);
pref("services.sync.prefs.sync.security.OCSP.enabled", true);
pref("services.sync.prefs.sync.security.OCSP.require", true);
pref("services.sync.prefs.sync.security.default_personal_cert", true);
pref("services.sync.prefs.sync.security.enable_java", true);
pref("services.sync.prefs.sync.security.enable_ssl3", true);
pref("services.sync.prefs.sync.security.enable_tls", true);
pref("services.sync.prefs.sync.security.warn_entering_secure", true);
pref("services.sync.prefs.sync.security.warn_entering_weak", true);
pref("services.sync.prefs.sync.security.warn_leaving_secure", true);
pref("services.sync.prefs.sync.security.warn_submit_insecure", true);
pref("services.sync.prefs.sync.security.warn_viewing_mixed", true);
pref("services.sync.prefs.sync.signon.rememberSignons", true);
pref("services.sync.prefs.sync.spellchecker.dictionary", true);
pref("services.sync.prefs.sync.xpinstall.whitelist.required", true);

Просмотреть файл

@ -0,0 +1,48 @@
Cu.import("resource://services-sync/ext/Preferences.js");
function run_test() {
_("Set some prefs on the old branch");
let globalPref = new Preferences("");
globalPref.set("extensions.weave.hello", "world");
globalPref.set("extensions.weave.number", 42);
globalPref.set("extensions.weave.yes", true);
globalPref.set("extensions.weave.no", false);
_("Make sure the old prefs are there");
do_check_eq(globalPref.get("extensions.weave.hello"), "world");
do_check_eq(globalPref.get("extensions.weave.number"), 42);
do_check_eq(globalPref.get("extensions.weave.yes"), true);
do_check_eq(globalPref.get("extensions.weave.no"), false);
_("New prefs shouldn't exist yet");
do_check_eq(globalPref.get("services.sync.hello"), null);
do_check_eq(globalPref.get("services.sync.number"), null);
do_check_eq(globalPref.get("services.sync.yes"), null);
do_check_eq(globalPref.get("services.sync.no"), null);
_("Loading service should migrate");
Cu.import("resource://services-sync/service.js");
do_check_eq(globalPref.get("services.sync.hello"), "world");
do_check_eq(globalPref.get("services.sync.number"), 42);
do_check_eq(globalPref.get("services.sync.yes"), true);
do_check_eq(globalPref.get("services.sync.no"), false);
do_check_eq(globalPref.get("extensions.weave.hello"), null);
do_check_eq(globalPref.get("extensions.weave.number"), null);
do_check_eq(globalPref.get("extensions.weave.yes"), null);
do_check_eq(globalPref.get("extensions.weave.no"), null);
_("Migrating should set a pref to make sure to not re-migrate");
do_check_true(globalPref.get("services.sync.migrated"));
_("Make sure re-migrate doesn't happen");
globalPref.set("extensions.weave.tooLate", "already migrated!");
do_check_eq(globalPref.get("extensions.weave.tooLate"), "already migrated!");
do_check_eq(globalPref.get("services.sync.tooLate"), null);
Weave.Service._migratePrefs();
do_check_eq(globalPref.get("extensions.weave.tooLate"), "already migrated!");
do_check_eq(globalPref.get("services.sync.tooLate"), null);
_("Clearing out pref changes for other tests");
globalPref.resetBranch("extensions.weave.");
globalPref.resetBranch("services.sync.");
}