[UB] Clean up animation logic to help crrev.com/c/5868910

Change-Id: I1027a892dae1bff34d2e6b446b09d43b9434e9fd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5890107
Auto-Submit: Fiona Macintosh <fmacintosh@google.com>
Commit-Queue: Fiona Macintosh <fmacintosh@google.com>
Reviewed-by: Michelle Abreo <michelleabreo@google.com>
Cr-Commit-Position: refs/heads/main@{#1359955}
diff --git a/chrome/browser/ui/views/location_bar/cookie_controls/cookie_controls_icon_view.cc b/chrome/browser/ui/views/location_bar/cookie_controls/cookie_controls_icon_view.cc
index 8d38267..f9c597e 100644
--- a/chrome/browser/ui/views/location_bar/cookie_controls/cookie_controls_icon_view.cc
+++ b/chrome/browser/ui/views/location_bar/cookie_controls/cookie_controls_icon_view.cc
@@ -113,25 +113,31 @@
   }
 }
 
-bool CookieControlsIconView::MaybeShowIPH() {
+void CookieControlsIconView::MaybeShowIPH() {
   CHECK(browser_->window());
-  // Need to make element visible or calls to show IPH will fail.
-  SetVisible(true);
-
-  if (blocking_status_ != CookieBlocking3pcdStatus::kNotIn3pcd ||
-      !should_highlight_) {
-    return false;
-  }
-
   user_education::FeaturePromoParams params(
       feature_engagement::kIPHCookieControlsFeature);
   params.close_callback = base::BindOnce(&CookieControlsIconView::OnIPHClosed,
                                          weak_ptr_factory_.GetWeakPtr());
   if (!browser_->window()->MaybeShowFeaturePromo(std::move(params))) {
-    return false;
+    MaybeAnimateIcon();
+    return;
   }
   SetHighlighted(true);
-  return true;
+}
+
+void CookieControlsIconView::OnShowPromoResult(
+    user_education::FeaturePromoResult result) {
+  if (result) {
+    SetHighlighted(true);
+    return;
+  }
+  // If we attempted to show the IPH but failed, instead try animating.
+  MaybeAnimateIcon();
+}
+
+void CookieControlsIconView::OnIPHClosed() {
+  SetHighlighted(false);
 }
 
 bool CookieControlsIconView::IsManagedIPHActive() const {
@@ -140,10 +146,6 @@
       feature_engagement::kIPHCookieControlsFeature);
 }
 
-void CookieControlsIconView::OnIPHClosed() {
-  SetHighlighted(false);
-}
-
 void CookieControlsIconView::SetLabelAndTooltip() {
   int icon_label = GetLabelForStatus();
   // Only use "Tracking Protection" and verbose accessibility description if the
@@ -188,10 +190,10 @@
   }
 }
 
-bool CookieControlsIconView::MaybeAnimateIcon() {
-  if (!should_highlight_ || GetAssociatedBubble() || IsManagedIPHActive() ||
+void CookieControlsIconView::MaybeAnimateIcon() {
+  if (GetAssociatedBubble() || IsManagedIPHActive() ||
       slide_animation_.is_animating()) {
-    return false;
+    return;
   }
 
   int label = blocking_status_ == CookieBlocking3pcdStatus::kNotIn3pcd
@@ -207,7 +209,9 @@
   } else {
     CHECK_IS_TEST();
   }
-  return true;
+  did_animate_ = true;
+  base::RecordAction(
+      base::UserMetricsAction("TrackingProtection.UserBypass.Animated"));
 }
 
 void CookieControlsIconView::UpdateIcon() {
@@ -219,10 +223,12 @@
   UpdateIconImage();
   SetVisible(true);
   SetLabelAndTooltip();
-  if (protections_on_ && !MaybeShowIPH() && MaybeAnimateIcon()) {
-    did_animate_ = true;
-    base::RecordAction(
-        base::UserMetricsAction("TrackingProtection.UserBypass.Animated"));
+  if (protections_on_ && should_highlight_) {
+    if (blocking_status_ == CookieBlocking3pcdStatus::kNotIn3pcd) {
+      MaybeShowIPH();
+    } else {
+      MaybeAnimateIcon();
+    }
   } else {
     base::RecordAction(
         base::UserMetricsAction("TrackingProtection.UserBypass.Shown"));
diff --git a/chrome/browser/ui/views/location_bar/cookie_controls/cookie_controls_icon_view.h b/chrome/browser/ui/views/location_bar/cookie_controls/cookie_controls_icon_view.h
index fc73d0d..600d678 100644
--- a/chrome/browser/ui/views/location_bar/cookie_controls/cookie_controls_icon_view.h
+++ b/chrome/browser/ui/views/location_bar/cookie_controls/cookie_controls_icon_view.h
@@ -66,9 +66,11 @@
 
   // Attempts to show IPH for the cookie controls icon.
   // Returns whether IPH was successfully shown.
-  bool MaybeShowIPH();
+  void MaybeShowIPH();
+  // Callback for when we try to show the IPH.
+  void OnShowPromoResult(user_education::FeaturePromoResult result);
 
-  bool MaybeAnimateIcon();
+  void MaybeAnimateIcon();
   void UpdateIcon();
 
   int GetLabelForStatus() const;