Changing OAuth2TokenService functions and its subclasses to use CoreAccountId instead of std::string

This cl is part of the effort to use CoreAccountId instead of std::string
to denote account_id.

Bug: 959157
Change-Id: I28981c590e7fb306fe1786d23139550ef0e65b05
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1628620
Commit-Queue: Tanmoy Mollik <triploblastic@google.com>
Reviewed-by: David Roger <droger@chromium.org>
Reviewed-by: Scott Violet <sky@chromium.org>
Reviewed-by: Denis Kuznetsov <antrim@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#666657}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: 74ea90fb9b16aa6dd0747affc537318339ca9093
diff --git a/gaia/fake_oauth2_token_service.cc b/gaia/fake_oauth2_token_service.cc
index 413a421..0704ab2 100644
--- a/gaia/fake_oauth2_token_service.cc
+++ b/gaia/fake_oauth2_token_service.cc
@@ -23,7 +23,7 @@
 
 void FakeOAuth2TokenService::FetchOAuth2Token(
     RequestImpl* request,
-    const std::string& account_id,
+    const CoreAccountId& account_id,
     scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
     const std::string& client_id,
     const std::string& client_secret,
@@ -37,13 +37,6 @@
   pending_requests_.push_back(pending_request);
 }
 
-void FakeOAuth2TokenService::InvalidateAccessTokenImpl(
-    const std::string& account_id,
-    const std::string& client_id,
-    const ScopeSet& scopes,
-    const std::string& access_token) {
-}
-
 void FakeOAuth2TokenService::AddAccount(const std::string& account_id) {
   GetDelegate()->UpdateCredentials(account_id, "fake_refresh_token");
 }
diff --git a/gaia/fake_oauth2_token_service.h b/gaia/fake_oauth2_token_service.h
index 032a709..1e8f96a 100644
--- a/gaia/fake_oauth2_token_service.h
+++ b/gaia/fake_oauth2_token_service.h
@@ -32,7 +32,7 @@
       const std::string& account_id,
       const GoogleServiceAuthError& auth_error);
 
-  void InvalidateTokenForMultilogin(const std::string& account_id,
+  void InvalidateTokenForMultilogin(const CoreAccountId& account_id,
                                     const std::string& token) override {}
 
   FakeOAuth2TokenServiceDelegate* GetFakeOAuth2TokenServiceDelegate();
@@ -41,16 +41,16 @@
   // OAuth2TokenService overrides.
   void FetchOAuth2Token(
       RequestImpl* request,
-      const std::string& account_id,
+      const CoreAccountId& account_id,
       scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
       const std::string& client_id,
       const std::string& client_secret,
       const ScopeSet& scopes) override;
 
-  void InvalidateAccessTokenImpl(const std::string& account_id,
+  void InvalidateAccessTokenImpl(const CoreAccountId& account_id,
                                  const std::string& client_id,
                                  const ScopeSet& scopes,
-                                 const std::string& access_token) override;
+                                 const std::string& access_token) override {}
 
  private:
   struct PendingRequest {
diff --git a/gaia/oauth2_token_service.cc b/gaia/oauth2_token_service.cc
index 1f449aa..5fdc3b9 100644
--- a/gaia/oauth2_token_service.cc
+++ b/gaia/oauth2_token_service.cc
@@ -427,7 +427,7 @@
 
 std::unique_ptr<OAuth2TokenService::Request>
 OAuth2TokenService::StartRequestForMultilogin(
-    const std::string& account_id,
+    const CoreAccountId& account_id,
     OAuth2TokenService::Consumer* consumer) {
   const std::string refresh_token =
       delegate_->GetTokenForMultilogin(account_id);
@@ -453,7 +453,7 @@
 }
 
 std::unique_ptr<OAuth2TokenService::Request> OAuth2TokenService::StartRequest(
-    const std::string& account_id,
+    const CoreAccountId& account_id,
     const OAuth2TokenService::ScopeSet& scopes,
     OAuth2TokenService::Consumer* consumer) {
   return StartRequestForClientWithContext(
@@ -464,7 +464,7 @@
 
 std::unique_ptr<OAuth2TokenService::Request>
 OAuth2TokenService::StartRequestForClient(
-    const std::string& account_id,
+    const CoreAccountId& account_id,
     const std::string& client_id,
     const std::string& client_secret,
     const OAuth2TokenService::ScopeSet& scopes,
@@ -481,7 +481,7 @@
 
 std::unique_ptr<OAuth2TokenService::Request>
 OAuth2TokenService::StartRequestWithContext(
-    const std::string& account_id,
+    const CoreAccountId& account_id,
     scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
     const ScopeSet& scopes,
     Consumer* consumer) {
@@ -493,7 +493,7 @@
 
 std::unique_ptr<OAuth2TokenService::Request>
 OAuth2TokenService::StartRequestForClientWithContext(
-    const std::string& account_id,
+    const CoreAccountId& account_id,
     scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
     const std::string& client_id,
     const std::string& client_secret,
@@ -537,7 +537,7 @@
 
 void OAuth2TokenService::FetchOAuth2Token(
     RequestImpl* request,
-    const std::string& account_id,
+    const CoreAccountId& account_id,
     scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
     const std::string& client_id,
     const std::string& client_secret,
@@ -560,7 +560,7 @@
 }
 
 OAuth2AccessTokenFetcher* OAuth2TokenService::CreateAccessTokenFetcher(
-    const std::string& account_id,
+    const CoreAccountId& account_id,
     scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
     OAuth2AccessTokenConsumer* consumer) {
   return delegate_->CreateAccessTokenFetcher(account_id, url_loader_factory,
@@ -590,24 +590,24 @@
 }
 
 bool OAuth2TokenService::RefreshTokenIsAvailable(
-    const std::string& account_id) const {
+    const CoreAccountId& account_id) const {
   return delegate_->RefreshTokenIsAvailable(account_id);
 }
 
 bool OAuth2TokenService::RefreshTokenHasError(
-    const std::string& account_id) const {
+    const CoreAccountId& account_id) const {
   return GetAuthError(account_id) != GoogleServiceAuthError::AuthErrorNone();
 }
 
 GoogleServiceAuthError OAuth2TokenService::GetAuthError(
-    const std::string& account_id) const {
+    const CoreAccountId& account_id) const {
   GoogleServiceAuthError error = delegate_->GetAuthError(account_id);
   DCHECK(!error.IsTransientError());
   return error;
 }
 
 void OAuth2TokenService::InvalidateAccessToken(
-    const std::string& account_id,
+    const CoreAccountId& account_id,
     const ScopeSet& scopes,
     const std::string& access_token) {
   InvalidateAccessTokenImpl(account_id,
@@ -616,7 +616,7 @@
 }
 
 void OAuth2TokenService::InvalidateTokenForMultilogin(
-    const std::string& failed_account,
+    const CoreAccountId& failed_account,
     const std::string& token) {
   OAuth2TokenService::ScopeSet scopes;
   scopes.insert(GaiaConstants::kOAuth1LoginScope);
@@ -629,7 +629,7 @@
 }
 
 void OAuth2TokenService::InvalidateAccessTokenForClient(
-    const std::string& account_id,
+    const CoreAccountId& account_id,
     const std::string& client_id,
     const ScopeSet& scopes,
     const std::string& access_token) {
@@ -637,7 +637,7 @@
 }
 
 void OAuth2TokenService::InvalidateAccessTokenImpl(
-    const std::string& account_id,
+    const CoreAccountId& account_id,
     const std::string& client_id,
     const ScopeSet& scopes,
     const std::string& access_token) {
@@ -735,14 +735,14 @@
   }
   return false;
 }
-void OAuth2TokenService::UpdateAuthError(const std::string& account_id,
+void OAuth2TokenService::UpdateAuthError(const CoreAccountId& account_id,
                                          const GoogleServiceAuthError& error) {
   delegate_->UpdateAuthError(account_id, error);
 }
 
 void OAuth2TokenService::RegisterTokenResponse(
     const std::string& client_id,
-    const std::string& account_id,
+    const CoreAccountId& account_id,
     const ScopeSet& scopes,
     const OAuth2AccessTokenConsumer::TokenResponse& token_response) {
   DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
@@ -761,7 +761,7 @@
   token_cache_.clear();
 }
 
-void OAuth2TokenService::ClearCacheForAccount(const std::string& account_id) {
+void OAuth2TokenService::ClearCacheForAccount(const CoreAccountId& account_id) {
   DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
   for (TokenCache::iterator iter = token_cache_.begin();
        iter != token_cache_.end();
@@ -784,7 +784,7 @@
 }
 
 void OAuth2TokenService::CancelRequestsForAccount(
-    const std::string& account_id) {
+    const CoreAccountId& account_id) {
   std::vector<Fetcher*> fetchers_to_cancel;
   for (const auto& pending_fetcher : pending_fetchers_) {
     if (pending_fetcher.first.account_id == account_id)
@@ -807,7 +807,7 @@
 
 size_t OAuth2TokenService::GetNumPendingRequestsForTesting(
     const std::string& client_id,
-    const std::string& account_id,
+    const CoreAccountId& account_id,
     const ScopeSet& scopes) const {
   auto iter = pending_fetchers_.find(
       OAuth2TokenService::RequestParameters(client_id, account_id, scopes));
diff --git a/gaia/oauth2_token_service.h b/gaia/oauth2_token_service.h
index 90157f7..56239fb 100644
--- a/gaia/oauth2_token_service.h
+++ b/gaia/oauth2_token_service.h
@@ -179,7 +179,7 @@
   // |scopes| is the set of scopes to get an access token for, |consumer| is
   // the object that will be called back with results if the returned request
   // is not deleted. Virtual for mocking.
-  virtual std::unique_ptr<Request> StartRequest(const std::string& account_id,
+  virtual std::unique_ptr<Request> StartRequest(const CoreAccountId& account_id,
                                                 const ScopeSet& scopes,
                                                 Consumer* consumer);
 
@@ -187,14 +187,14 @@
   // empty), return it directly, otherwise start request to get access token.
   // Used for getting tokens to send to Gaia Multilogin endpoint.
   std::unique_ptr<OAuth2TokenService::Request> StartRequestForMultilogin(
-      const std::string& account_id,
+      const CoreAccountId& account_id,
       OAuth2TokenService::Consumer* consumer);
 
   // This method does the same as |StartRequest| except it uses |client_id| and
   // |client_secret| to identify OAuth client app instead of using
   // Chrome's default values.
   std::unique_ptr<Request> StartRequestForClient(
-      const std::string& account_id,
+      const CoreAccountId& account_id,
       const std::string& client_id,
       const std::string& client_secret,
       const ScopeSet& scopes,
@@ -204,7 +204,7 @@
   // URLLoaderfactory given by |url_loader_factory| instead of using the one
   // returned by |GetURLLoaderFactory| implemented by derived classes.
   std::unique_ptr<Request> StartRequestWithContext(
-      const std::string& account_id,
+      const CoreAccountId& account_id,
       scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
       const ScopeSet& scopes,
       Consumer* consumer);
@@ -220,28 +220,28 @@
   // |StartRequest| will result in a Consumer::OnGetTokenFailure callback.
   // Note: This will return |true| if and only if |account_id| is contained in
   // the list returned by |GetAccounts|.
-  bool RefreshTokenIsAvailable(const std::string& account_id) const;
+  bool RefreshTokenIsAvailable(const CoreAccountId& account_id) const;
 
   // Returns true if a refresh token exists for |account_id| and it is in a
   // persistent error state.
-  bool RefreshTokenHasError(const std::string& account_id) const;
+  bool RefreshTokenHasError(const CoreAccountId& account_id) const;
 
   // Returns the auth error associated with |account_id|. Only persistent errors
   // will be returned.
-  GoogleServiceAuthError GetAuthError(const std::string& account_id) const;
+  GoogleServiceAuthError GetAuthError(const CoreAccountId& account_id) const;
 
   // Mark an OAuth2 |access_token| issued for |account_id| and |scopes| as
   // invalid. This should be done if the token was received from this class,
   // but was not accepted by the server (e.g., the server returned
   // 401 Unauthorized). The token will be removed from the cache for the given
   // scopes.
-  void InvalidateAccessToken(const std::string& account_id,
+  void InvalidateAccessToken(const CoreAccountId& account_id,
                              const ScopeSet& scopes,
                              const std::string& access_token);
 
   // Like |InvalidateToken| except is uses |client_id| to identity OAuth2 client
   // app that issued the request instead of Chrome's default values.
-  void InvalidateAccessTokenForClient(const std::string& account_id,
+  void InvalidateAccessTokenForClient(const CoreAccountId& account_id,
                                       const std::string& client_id,
                                       const ScopeSet& scopes,
                                       const std::string& access_token);
@@ -250,15 +250,14 @@
   // InvalidateTokenForMultilogin method of the delegate. This should be done if
   // the token was received from this class, but was not accepted by the server
   // (e.g., the server returned 401 Unauthorized).
-  virtual void InvalidateTokenForMultilogin(const std::string& failed_account,
+  virtual void InvalidateTokenForMultilogin(const CoreAccountId& failed_account,
                                             const std::string& token);
 
   void set_max_authorization_token_fetch_retries_for_testing(int max_retries);
   // Returns the current number of pending fetchers matching given params.
-  size_t GetNumPendingRequestsForTesting(
-      const std::string& client_id,
-      const std::string& account_id,
-      const ScopeSet& scopes) const;
+  size_t GetNumPendingRequestsForTesting(const std::string& client_id,
+                                         const CoreAccountId& account_id,
+                                         const ScopeSet& scopes) const;
 
   OAuth2TokenServiceDelegate* GetDelegate();
   const OAuth2TokenServiceDelegate* GetDelegate() const;
@@ -293,7 +292,7 @@
   };
 
   // Implement it in delegates if they want to report errors to the user.
-  void UpdateAuthError(const std::string& account_id,
+  void UpdateAuthError(const CoreAccountId& account_id,
                        const GoogleServiceAuthError& error);
 
   // Add a new entry to the cache.
@@ -301,7 +300,7 @@
   // that an access token should ever not be cached.
   virtual void RegisterTokenResponse(
       const std::string& client_id,
-      const std::string& account_id,
+      const CoreAccountId& account_id,
       const ScopeSet& scopes,
       const OAuth2AccessTokenConsumer::TokenResponse& token_response);
 
@@ -311,7 +310,7 @@
   // Clears all of the tokens belonging to |account_id| from the internal token
   // cache. It does not matter what other parameters, like |client_id| were
   // used to request the tokens.
-  void ClearCacheForAccount(const std::string& account_id);
+  void ClearCacheForAccount(const CoreAccountId& account_id);
 
   // Cancels all requests that are currently in progress. Virtual so it can be
   // overridden for tests.
@@ -319,13 +318,13 @@
 
   // Cancels all requests related to a given |account_id|. Virtual so it can be
   // overridden for tests.
-  virtual void CancelRequestsForAccount(const std::string& account_id);
+  virtual void CancelRequestsForAccount(const CoreAccountId& account_id);
 
   // Fetches an OAuth token for the specified client/scopes. Virtual so it can
   // be overridden for tests and for platform-specific behavior.
   virtual void FetchOAuth2Token(
       RequestImpl* request,
-      const std::string& account_id,
+      const CoreAccountId& account_id,
       scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
       const std::string& client_id,
       const std::string& client_secret,
@@ -333,14 +332,14 @@
 
   // Create an access token fetcher for the given account id.
   OAuth2AccessTokenFetcher* CreateAccessTokenFetcher(
-      const std::string& account_id,
+      const CoreAccountId& account_id,
       scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
       OAuth2AccessTokenConsumer* consumer);
 
   // Invalidates the |access_token| issued for |account_id|, |client_id| and
   // |scopes|. Virtual so it can be overriden for tests and for platform-
   // specifc behavior.
-  virtual void InvalidateAccessTokenImpl(const std::string& account_id,
+  virtual void InvalidateAccessTokenImpl(const CoreAccountId& account_id,
                                          const std::string& client_id,
                                          const ScopeSet& scopes,
                                          const std::string& access_token);
@@ -380,7 +379,7 @@
   // uses |client_id| and |client_secret| to identify OAuth
   // client app instead of using Chrome's default values.
   std::unique_ptr<Request> StartRequestForClientWithContext(
-      const std::string& account_id,
+      const CoreAccountId& account_id,
       scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
       const std::string& client_id,
       const std::string& client_secret,
diff --git a/gaia/oauth2_token_service_request_unittest.cc b/gaia/oauth2_token_service_request_unittest.cc
index 509f28a..264873c 100644
--- a/gaia/oauth2_token_service_request_unittest.cc
+++ b/gaia/oauth2_token_service_request_unittest.cc
@@ -91,13 +91,13 @@
  protected:
   void FetchOAuth2Token(
       RequestImpl* request,
-      const std::string& account_id,
+      const CoreAccountId& account_id,
       scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
       const std::string& client_id,
       const std::string& client_secret,
       const ScopeSet& scopes) override;
 
-  void InvalidateAccessTokenImpl(const std::string& account_id,
+  void InvalidateAccessTokenImpl(const CoreAccountId& account_id,
                                  const std::string& client_id,
                                  const ScopeSet& scopes,
                                  const std::string& access_token) override;
@@ -133,7 +133,7 @@
 
 void MockOAuth2TokenService::FetchOAuth2Token(
     RequestImpl* request,
-    const std::string& account_id,
+    const CoreAccountId& account_id,
     scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
     const std::string& client_id,
     const std::string& client_secret,
@@ -148,7 +148,7 @@
 }
 
 void MockOAuth2TokenService::InvalidateAccessTokenImpl(
-    const std::string& account_id,
+    const CoreAccountId& account_id,
     const std::string& client_id,
     const ScopeSet& scopes,
     const std::string& access_token) {