Bug 1341125 - Clear accounts in-memory cache when necessary. r=nalexander
authorGrigory Kruglov <gkruglov@mozilla.com>
Mon, 27 Feb 2017 17:38:15 -0800
changeset 376491 8d1fb3b386b737d7962f02e392d238fcaea8ce5f
parent 376490 f56e8387be84518f9547479b945d259b9b9b5fdf
child 376492 34e95ff8e264d1589dc9c317be041a3ea9616acd
push id6996
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 20:48:21 +0000
treeherdermozilla-beta@d89512dab048 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnalexander
bugs1341125
milestone53.0a2
Bug 1341125 - Clear accounts in-memory cache when necessary. r=nalexander
mobile/android/base/java/org/mozilla/gecko/AccountsHelper.java
mobile/android/services/src/main/java/org/mozilla/gecko/fxa/receivers/FxAccountDeletedService.java
--- a/mobile/android/base/java/org/mozilla/gecko/AccountsHelper.java
+++ b/mobile/android/base/java/org/mozilla/gecko/AccountsHelper.java
@@ -81,16 +81,20 @@ public class AccountsHelper implements N
             Log.e(LOGTAG, "Profile is not allowed to modify accounts!  Ignoring event: " + event);
             if (callback != null) {
                 callback.sendError("Profile is not allowed to modify accounts!");
             }
             return;
         }
 
         if ("Accounts:CreateFirefoxAccountFromJSON".equals(event)) {
+            // As we are about to create a new account, let's ensure our in-memory accounts cache
+            // is empty so that there are no undesired side-effects.
+            AndroidFxAccount.invalidateCaches();
+
             AndroidFxAccount fxAccount = null;
             try {
                 final NativeJSObject json = message.getObject("json");
                 final String email = json.getString("email");
                 final String uid = json.getString("uid");
                 final boolean verified = json.optBoolean("verified", false);
                 final byte[] unwrapkB = Utils.hex2Byte(json.getString("unwrapBKey"));
                 final byte[] sessionToken = Utils.hex2Byte(json.getString("sessionToken"));
@@ -138,16 +142,20 @@ public class AccountsHelper implements N
                     return;
                 }
             }
             if (callback != null) {
                 callback.sendSuccess(fxAccount != null);
             }
 
         } else if ("Accounts:UpdateFirefoxAccountFromJSON".equals(event)) {
+            // We might be significantly changing state of the account; let's ensure our in-memory
+            // accounts cache is empty so that there are no undesired side-effects.
+            AndroidFxAccount.invalidateCaches();
+
             try {
                 final Account account = FirefoxAccounts.getFirefoxAccount(mContext);
                 if (account == null) {
                     if (callback != null) {
                         callback.sendError("Could not update Firefox Account since none exists");
                     }
                     return;
                 }
--- a/mobile/android/services/src/main/java/org/mozilla/gecko/fxa/receivers/FxAccountDeletedService.java
+++ b/mobile/android/services/src/main/java/org/mozilla/gecko/fxa/receivers/FxAccountDeletedService.java
@@ -33,16 +33,21 @@ public class FxAccountDeletedService ext
   public static final String LOG_TAG = FxAccountDeletedService.class.getSimpleName();
 
   public FxAccountDeletedService() {
     super(LOG_TAG);
   }
 
   @Override
   protected void onHandleIntent(final Intent intent) {
+    // We have an in-memory accounts cache which we use for a variety of tasks; it needs to be cleared.
+    // It should be fine to invalidate it before doing anything else, as the tasks below do not rely
+    // on this data.
+    AndroidFxAccount.invalidateCaches();
+
     // Intent can, in theory, be null. Bug 1025937.
     if (intent == null) {
       Logger.debug(LOG_TAG, "Short-circuiting on null intent.");
       return;
     }
 
     final Context context = this;