From cd3e129cfc51276ae740871b1617890b13baaee0 Mon Sep 17 00:00:00 2001 From: Grigory Kruglov Date: Thu, 28 Sep 2017 18:44:59 -0400 Subject: [PATCH] Bug 1404124 - Pickle account right after it's created r=eoger This is a relative of Bug 988605, with an exception that instead of going the whole way and ensuring pickled data is kept up-to-date as Nick proposed, this patch simply ensures that we pickle as soon as possible, with a goal of eliminating pickle races. The end goal is to kill off pickling entirely, and so the assumption here is that this workaround is good enough in the meantime. MozReview-Commit-ID: 7IjRH7KE2Z9 --HG-- extra : rebase_source : e25b6d6baf5544d5a087cd9e12ec41d6176c317f --- .../fxa/authenticator/AndroidFxAccount.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/mobile/android/services/src/main/java/org/mozilla/gecko/fxa/authenticator/AndroidFxAccount.java b/mobile/android/services/src/main/java/org/mozilla/gecko/fxa/authenticator/AndroidFxAccount.java index a39fcb79393d..a11a372a0360 100644 --- a/mobile/android/services/src/main/java/org/mozilla/gecko/fxa/authenticator/AndroidFxAccount.java +++ b/mobile/android/services/src/main/java/org/mozilla/gecko/fxa/authenticator/AndroidFxAccount.java @@ -41,6 +41,7 @@ import org.mozilla.gecko.fxa.login.StateFactory; import org.mozilla.gecko.fxa.sync.FxAccountProfileService; import org.mozilla.gecko.sync.ExtendedJSONObject; import org.mozilla.gecko.sync.NonObjectJSONException; +import org.mozilla.gecko.sync.ThreadPool; import org.mozilla.gecko.sync.Utils; import org.mozilla.gecko.sync.setup.Constants; import org.mozilla.gecko.util.ThreadUtils; @@ -588,10 +589,26 @@ public class AndroidFxAccount { accountManager.setUserData(account, key, userdata.getString(key)); } - AndroidFxAccount fxAccount = new AndroidFxAccount(context, account); + final AndroidFxAccount fxAccount = new AndroidFxAccount(context, account); if (!fromPickle) { fxAccount.clearSyncPrefs(); + + // We can nearly eliminate various pickle races by pickling the account right after creation. + // These races are an unfortunate by-product of Bug 1368147. The long-term solution is to stop + // pickling entirely, but for now we just ensure we'll have a pickle file as soon as possible. + // Pickle in a background thread to avoid strict mode warnings. + ThreadPool.run(new Runnable() { + @Override + public void run() { + try { + AccountPickler.pickle(fxAccount, FxAccountConstants.ACCOUNT_PICKLE_FILENAME); + } catch (Exception e) { + // Should never happen, but we really don't want to die in a background thread. + Logger.warn(LOG_TAG, "Got exception pickling current account details; ignoring.", e); + } + } + }); } fxAccount.setAuthoritiesToSyncAutomaticallyMap(authoritiesToSyncAutomaticallyMap);