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
This commit is contained in:
Grigory Kruglov 2017-09-28 18:44:59 -04:00
Родитель a4e7f674a0
Коммит cd3e129cfc
1 изменённых файлов: 18 добавлений и 1 удалений

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

@ -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);