Bug 1882339: Delay sync initialization until oauth message. r=skhamis,markh

Differential Revision: https://phabricator.services.mozilla.com/D202849
This commit is contained in:
Tarik Eshaq 2024-04-02 20:33:48 +00:00
parent 31f42f9bc3
commit f80f8a5040
2 changed files with 38 additions and 21 deletions

View file

@ -65,6 +65,13 @@ XPCOMUtils.defineLazyPreferenceGetter(
true
);
XPCOMUtils.defineLazyPreferenceGetter(
lazy,
"oauthEnabled",
"identity.fxaccounts.oauth.enabled",
true
);
export const ERROR_INVALID_ACCOUNT_STATE = "ERROR_INVALID_ACCOUNT_STATE";
// An AccountState object holds all state related to one specific account.
@ -550,7 +557,7 @@ export class FxAccounts {
await this.signOut();
return null;
}
if (!this._internal.isUserEmailVerified(data)) {
if (!this._internal.isUserEmailVerified(data) && !lazy.oauthEnabled) {
// If the email is not verified, start polling for verification,
// but return null right away. We don't want to return a promise
// that might not be fulfilled for a long time.
@ -995,16 +1002,17 @@ FxAccountsInternal.prototype = {
);
}
await this.abortExistingFlow();
let currentAccountState = (this.currentAccountState = this.newAccountState(
Cu.cloneInto(credentials, {}) // Pass a clone of the credentials object.
));
const currentAccountState = (this.currentAccountState =
this.newAccountState(
Cu.cloneInto(credentials, {}) // Pass a clone of the credentials object.
));
// This promise waits for storage, but not for verification.
// We're telling the caller that this is durable now (although is that
// really something we should commit to? Why not let the write happen in
// the background? Already does for updateAccountData ;)
await currentAccountState.promiseInitialized;
// Starting point for polling if new user
if (!this.isUserEmailVerified(credentials)) {
if (!this.isUserEmailVerified(credentials) && !lazy.oauthEnabled) {
this.startVerifiedCheck(credentials);
}
await this.notifyObservers(ONLOGIN_NOTIFICATION);
@ -1478,13 +1486,14 @@ FxAccountsInternal.prototype = {
/** Sets the user to be verified in the account state,
* This prevents any polling for the user's verification state from the FxA server
**/
setUserVerified() {
return this.withCurrentAccountState(async currentState => {
async setUserVerified() {
await this.withCurrentAccountState(async currentState => {
const userData = await currentState.getUserAccountData();
if (!userData.verified) {
await currentState.updateAccountData({ verified: true });
await currentState.updateUserAccountData({ verified: true });
}
});
await this.notifyObservers(ONVERIFIED_NOTIFICATION);
},
async _getVerifiedAccountOrReject() {

View file

@ -80,6 +80,13 @@ XPCOMUtils.defineLazyPreferenceGetter(
val => Services.io.newURI(val)
);
XPCOMUtils.defineLazyPreferenceGetter(
lazy,
"oauthEnabled",
"identity.fxaccounts.oauth.enabled",
false
);
// These engines were added years after Sync had been introduced, they need
// special handling since they are system add-ons and are un-available on
// older versions of Firefox.
@ -487,16 +494,19 @@ FxAccountsWebChannelHelpers.prototype = {
"webchannel"
);
const xps = await this._initializeSync();
await this._fxAccounts._internal.setSignedInUser(accountData);
if (requestedServices) {
// User has enabled Sync.
if (requestedServices.sync) {
const { offeredEngines, declinedEngines } = requestedServices.sync;
this._setEnabledEngines(offeredEngines, declinedEngines);
log.debug("Webchannel is enabling sync");
await xps.Weave.Service.configure();
if (lazy.oauthEnabled) {
await this._fxAccounts._internal.setSignedInUser(accountData);
} else {
const xps = await this._initializeSync();
await this._fxAccounts._internal.setSignedInUser(accountData);
if (requestedServices) {
// User has enabled Sync.
if (requestedServices.sync) {
const { offeredEngines, declinedEngines } = requestedServices.sync;
this._setEnabledEngines(offeredEngines, declinedEngines);
log.debug("Webchannel is enabling sync");
await xps.Weave.Service.configure();
}
}
}
},
@ -628,9 +638,7 @@ FxAccountsWebChannelHelpers.prototype = {
};
},
_getCapabilities() {
if (
Services.prefs.getBoolPref("identity.fxaccounts.oauth.enabled", false)
) {
if (lazy.oauthEnabled) {
return {
multiService: true,
pairing: lazy.pairingEnabled,