Port AvatarToolbarButton away from GaiaCookieManagerService callbacks

It was observing the gaia cookie manager service to know whether the
list of gaia accounts in the cookie jar has changed. That can be
achieved observing IdentityManager as well.

Bug: 921008
Change-Id: Icad5a14f1288346b97d4d8ccc1eb4c0a901eae3b
Reviewed-on: https://chromium-review.googlesource.com/c/1408928
Commit-Queue: Sergio Villar <svillar@igalia.com>
Reviewed-by: Colin Blundell <blundell@chromium.org>
Reviewed-by: Thomas Tangl <tangltom@chromium.org>
Cr-Commit-Position: refs/heads/master@{#623187}
diff --git a/chrome/browser/ui/views/profiles/avatar_toolbar_button.cc b/chrome/browser/ui/views/profiles/avatar_toolbar_button.cc
index 2368399..d7149d05 100644
--- a/chrome/browser/ui/views/profiles/avatar_toolbar_button.cc
+++ b/chrome/browser/ui/views/profiles/avatar_toolbar_button.cc
@@ -15,9 +15,7 @@
 #include "chrome/browser/profiles/profiles_state.h"
 #include "chrome/browser/signin/account_consistency_mode_manager.h"
 #include "chrome/browser/signin/account_tracker_service_factory.h"
-#include "chrome/browser/signin/gaia_cookie_manager_service_factory.h"
 #include "chrome/browser/signin/identity_manager_factory.h"
-#include "chrome/browser/signin/signin_manager_factory.h"
 #include "chrome/browser/signin/signin_ui_util.h"
 #include "chrome/browser/sync/sync_ui_util.h"
 #include "chrome/browser/themes/theme_properties.h"
@@ -61,7 +59,7 @@
 #endif  // !defined(OS_CHROMEOS)
       browser_list_observer_(this),
       profile_observer_(this),
-      cookie_manager_service_observer_(this),
+      identity_manager_observer_(this),
       account_tracker_service_observer_(this) {
 
   if (IsIncognitoCounterActive())
@@ -71,8 +69,8 @@
       &g_browser_process->profile_manager()->GetProfileAttributesStorage());
 
   if (!IsIncognito() && !profile_->IsGuestSession()) {
-    cookie_manager_service_observer_.Add(
-        GaiaCookieManagerServiceFactory::GetForProfile(profile_));
+    identity_manager_observer_.Add(
+        IdentityManagerFactory::GetForProfile(profile_));
     account_tracker_service_observer_.Add(
         AccountTrackerServiceFactory::GetForProfile(profile_));
   }
@@ -218,9 +216,8 @@
   UpdateText();
 }
 
-void AvatarToolbarButton::OnGaiaAccountsInCookieUpdated(
-    const std::vector<gaia::ListedAccount>& accounts,
-    const std::vector<gaia::ListedAccount>& signed_out_accounts,
+void AvatarToolbarButton::OnAccountsInCookieUpdated(
+    const identity::AccountsInCookieJarInfo& accounts_in_cookie_jar_info,
     const GoogleServiceAuthError& error) {
   UpdateIcon();
 }
diff --git a/chrome/browser/ui/views/profiles/avatar_toolbar_button.h b/chrome/browser/ui/views/profiles/avatar_toolbar_button.h
index aff14df..b3e3ada 100644
--- a/chrome/browser/ui/views/profiles/avatar_toolbar_button.h
+++ b/chrome/browser/ui/views/profiles/avatar_toolbar_button.h
@@ -15,7 +15,7 @@
 #include "chrome/browser/ui/browser_list_observer.h"
 #include "chrome/browser/ui/views/toolbar/toolbar_button.h"
 #include "components/signin/core/browser/account_tracker_service.h"
-#include "components/signin/core/browser/gaia_cookie_manager_service.h"
+#include "services/identity/public/cpp/identity_manager.h"
 #include "ui/base/material_design/material_design_controller_observer.h"
 #include "ui/events/event.h"
 
@@ -25,7 +25,7 @@
                             public AvatarButtonErrorControllerDelegate,
                             public BrowserListObserver,
                             public ProfileAttributesStorage::Observer,
-                            public GaiaCookieManagerService::Observer,
+                            public identity::IdentityManager::Observer,
                             public AccountTrackerService::Observer,
                             public ui::MaterialDesignControllerObserver {
  public:
@@ -59,11 +59,10 @@
   void OnProfileNameChanged(const base::FilePath& profile_path,
                             const base::string16& old_profile_name) override;
 
-  // GaiaCookieManagerService::Observer:
+  // IdentityManager::Observer:
   // Needed if the first sync promo account should be displayed.
-  void OnGaiaAccountsInCookieUpdated(
-      const std::vector<gaia::ListedAccount>& accounts,
-      const std::vector<gaia::ListedAccount>& signed_out_accounts,
+  void OnAccountsInCookieUpdated(
+      const identity::AccountsInCookieJarInfo& accounts_in_cookie_jar_info,
       const GoogleServiceAuthError& error) override;
 
   // AccountTrackerService::Observer:
@@ -93,8 +92,8 @@
   ScopedObserver<BrowserList, BrowserListObserver> browser_list_observer_;
   ScopedObserver<ProfileAttributesStorage, AvatarToolbarButton>
       profile_observer_;
-  ScopedObserver<GaiaCookieManagerService, AvatarToolbarButton>
-      cookie_manager_service_observer_;
+  ScopedObserver<identity::IdentityManager, AvatarToolbarButton>
+      identity_manager_observer_;
   ScopedObserver<AccountTrackerService, AvatarToolbarButton>
       account_tracker_service_observer_;
   ScopedObserver<ui::MaterialDesignController, AvatarToolbarButton>