Bug 1124956 - Fix Sync engine selection after migration to FxA. r=adw

This commit is contained in:
Mark Hammond 2015-01-29 10:41:00 +11:00
parent 370ecafbbb
commit 560014f64c
5 changed files with 39 additions and 20 deletions

View File

@ -16,7 +16,7 @@ Cu.import("resource://gre/modules/FxAccountsCommon.js", fxAccountsCommon);
Cu.import("resource://services-sync/util.js");
const PREF_LAST_FXA_USER = "identity.fxaccounts.lastSignedInUserHash";
const PREF_SYNC_SHOW_CUSTOMIZATION = "services.sync.ui.showCustomizationDialog";
const PREF_SYNC_SHOW_CUSTOMIZATION = "services.sync-setup.ui.showCustomizationDialog";
const ACTION_URL_PARAM = "action";

View File

@ -210,27 +210,39 @@ Migrator.prototype = {
// Must be ready to perform the actual migration.
this.log.info("Performing final sync migration steps");
// Do the actual migration.
// Do the actual migration. We setup one observer for when the new identity
// is about to be initialized so we can reset some key preferences - but
// there's no promise associated with this.
let observeStartOverIdentity;
Services.obs.addObserver(observeStartOverIdentity = () => {
this.log.info("observed that startOver is about to re-initialize the identity");
Services.obs.removeObserver(observeStartOverIdentity, "weave:service:start-over:init-identity");
// We've now reset all sync prefs - set the engine related prefs back to
// what they were.
for (let [prefName, prefType, prefVal] of enginePrefs) {
this.log.debug("Restoring pref ${prefName} (type=${prefType}) to ${prefVal}",
{prefName, prefType, prefVal});
switch (prefType) {
case Services.prefs.PREF_BOOL:
Services.prefs.setBoolPref(prefName, prefVal);
break;
case Services.prefs.PREF_STRING:
Services.prefs.setCharPref(prefName, prefVal);
break;
default:
// _getEngineEnabledPrefs doesn't return any other type...
Cu.reportError("unknown engine pref type for " + prefName + ": " + prefType);
}
}
}, "weave:service:start-over:init-identity", false);
// And another observer for the startOver being fully complete - the only
// reason for this is so we can wait until everything is fully reset.
let startOverComplete = new Promise((resolve, reject) => {
let observe;
Services.obs.addObserver(observe = () => {
this.log.info("observed that startOver is complete");
Services.obs.removeObserver(observe, "weave:service:start-over:finish");
// We've now reset all sync prefs - set the engine related prefs back to
// what they were.
for (let [prefName, prefType, prefVal] of enginePrefs) {
switch (prefType) {
case Services.prefs.PREF_BOOL:
Services.prefs.setBoolPref(prefName, prefVal);
break;
case Services.prefs.PREF_STRING:
Services.prefs.setCharPref(prefName, prefVal);
break;
default:
// _getEngineEnabledPrefs doesn't return any other type...
Cu.reportError("unknown engine pref type for " + prefName + ": " + prefType);
}
}
resolve();
}, "weave:service:start-over:finish", false);
});
@ -240,6 +252,8 @@ Migrator.prototype = {
yield startOverComplete;
// observer fired, now kick things off with the FxA user.
this.log.info("scheduling initial FxA sync.");
// Note we technically don't need to unblockSync as by now all sync prefs
// have been reset - but it doesn't hurt.
this._unblockSync();
Weave.Service.scheduler.scheduleNextSync(0);

View File

@ -47,7 +47,7 @@ const OBSERVER_TOPICS = [
fxAccountsCommon.ONLOGOUT_NOTIFICATION,
];
const PREF_SYNC_SHOW_CUSTOMIZATION = "services.sync.ui.showCustomizationDialog";
const PREF_SYNC_SHOW_CUSTOMIZATION = "services.sync-setup.ui.showCustomizationDialog";
function deriveKeyBundle(kB) {
let out = CryptoUtils.hkdf(kB, undefined,

View File

@ -592,8 +592,10 @@ ErrorHandler.prototype = {
fapp.level = Log.Level[Svc.Prefs.get("log.appender.file.level")];
root.addAppender(fapp);
// Arrange for the FxA, Hawk and TokenServer logs to also go to our appenders.
for (let extra of ["FirefoxAccounts", "Hawk", "Common.TokenServerClient"]) {
// Arrange for a number of other sync-related logs to also go to our
// appenders.
for (let extra of ["FirefoxAccounts", "Hawk", "Common.TokenServerClient",
"Sync.SyncMigration"]) {
let log = Log.repository.getLogger(extra);
for (let appender of [fapp, dapp, capp]) {
log.addAppender(appender);

View File

@ -926,6 +926,9 @@ Sync11Service.prototype = {
this.identity.finalize().then(
() => {
// an observer so the FxA migration code can take some action before
// the new identity is created.
Svc.Obs.notify("weave:service:start-over:init-identity");
this.identity.username = "";
this.status.__authManager = null;
this.identity = Status._authManager;