[identity] Save user's choice of an account in the remote consent flow

At the end of the remote consent flow, Gaia returns Chrome a gaia id of
an account chosen by the user. This change makes Chrome reuse this
account for the next getAuthToken() calls for the same extension.

For now, accounts are stored in memory with a TODO to migrate them to
the user preferences.

Bug: 1026237
Change-Id: Ibe52424b7131fbe44324ecb7b1a0e54d04cdf747
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2119520
Commit-Queue: Alex Ilin <[email protected]>
Reviewed-by: David Roger <[email protected]>
Cr-Commit-Position: refs/heads/master@{#754934}
diff --git a/chrome/browser/extensions/api/identity/identity_api.h b/chrome/browser/extensions/api/identity/identity_api.h
index ac001438..f3d8a8f 100644
--- a/chrome/browser/extensions/api/identity/identity_api.h
+++ b/chrome/browser/extensions/api/identity/identity_api.h
@@ -88,6 +88,7 @@
                     public signin::IdentityManager::Observer {
  public:
   using CachedTokens = std::map<ExtensionTokenKey, IdentityTokenCacheValue>;
+  using CachedGaiaIds = std::map<std::string, std::string>;
   using OnSetConsentResultSignature = void(const std::string&,
                                            const std::string&);
 
@@ -97,16 +98,22 @@
   // Request serialization queue for getAuthToken.
   IdentityMintRequestQueue* mint_queue();
 
-  // Token cache
+  // Token cache.
   void SetCachedToken(const ExtensionTokenKey& key,
                       const IdentityTokenCacheValue& token_data);
   void EraseCachedToken(const std::string& extension_id,
                         const std::string& token);
   void EraseAllCachedTokens();
   const IdentityTokenCacheValue& GetCachedToken(const ExtensionTokenKey& key);
-
   const CachedTokens& GetAllCachedTokens();
 
+  // GAIA id cache.
+  // TODO(https://crbug.com/1026237): migrate storage to the user preferences.
+  void SetGaiaIdForExtension(const std::string& extension_id,
+                             const std::string& gaia_id);
+  const std::string& GetGaiaIdForExtension(const std::string& extension_id);
+  void EraseAllGaiaIds();
+
   // Consent result.
   void SetConsentResult(const std::string& result,
                         const std::string& window_id);
@@ -156,6 +163,7 @@
   Profile* profile_;
   IdentityMintRequestQueue mint_queue_;
   CachedTokens token_cache_;
+  CachedGaiaIds gaia_id_cache_;
 
   OnSignInChangedCallback on_signin_changed_callback_for_testing_;