base: use ObserverList::Notify() in ui/message_center

This CL was uploaded by git cl split.

[email protected]

Bug: 40727208
Change-Id: I531d8825d6f1b1a4ce3a75ac5aded749389d150d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5893968
Auto-Submit: Keren Zhu <[email protected]>
Reviewed-by: Yoshiki Iguchi <[email protected]>
Commit-Queue: Yoshiki Iguchi <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1361250}
diff --git a/ui/message_center/fake_message_center.cc b/ui/message_center/fake_message_center.cc
index 17bf1d9..4c3cefe 100644
--- a/ui/message_center/fake_message_center.cc
+++ b/ui/message_center/fake_message_center.cc
@@ -110,9 +110,7 @@
   std::string id = notification->id();
   notifications_.AddNotification(std::move(notification));
   visible_notifications_ = notifications_.GetVisibleNotifications(blockers_);
-  for (auto& observer : observers_) {
-    observer.OnNotificationAdded(id);
-  }
+  observers_.Notify(&MessageCenterObserver::OnNotificationAdded, id);
 }
 
 void FakeMessageCenter::UpdateNotification(
@@ -135,9 +133,7 @@
                                            bool by_user) {
   notifications_.RemoveNotification(id);
   visible_notifications_ = notifications_.GetVisibleNotifications(blockers_);
-  for (auto& observer : observers_) {
-    observer.OnNotificationRemoved(id, by_user);
-  }
+  observers_.Notify(&MessageCenterObserver::OnNotificationRemoved, id, by_user);
 }
 
 void FakeMessageCenter::RemoveNotificationsForNotifierId(
diff --git a/ui/message_center/message_center_impl.cc b/ui/message_center/message_center_impl.cc
index bc95203..234429c 100644
--- a/ui/message_center/message_center_impl.cc
+++ b/ui/message_center/message_center_impl.cc
@@ -141,13 +141,11 @@
       notification_list_->GetVisibleNotifications(blockers_);
 
   for (const std::string& notification_id : blocked) {
-    for (MessageCenterObserver& observer : observer_list_) {
-      observer.OnNotificationUpdated(notification_id);
-    }
+    observer_list_.Notify(&MessageCenterObserver::OnNotificationUpdated,
+                          notification_id);
   }
-  for (MessageCenterObserver& observer : observer_list_) {
-    observer.OnBlockingStateChanged(blocker);
-  }
+  observer_list_.Notify(&MessageCenterObserver::OnBlockingStateChanged,
+                        blocker);
 }
 
 void MessageCenterImpl::SetVisibility(Visibility visibility) {
@@ -159,9 +157,7 @@
     notification_list_->SetNotificationsShown(blockers_, &updated_ids);
 
     for (const auto& id : updated_ids) {
-      for (MessageCenterObserver& observer : observer_list_) {
-        observer.OnNotificationUpdated(id);
-      }
+      observer_list_.Notify(&MessageCenterObserver::OnNotificationUpdated, id);
     }
 
     for (Notification* notification : GetPopupNotifications()) {
@@ -169,9 +165,8 @@
     }
   }
 
-  for (MessageCenterObserver& observer : observer_list_) {
-    observer.OnCenterVisibilityChanged(visibility);
-  }
+  observer_list_.Notify(&MessageCenterObserver::OnCenterVisibilityChanged,
+                        visibility);
 }
 
 bool MessageCenterImpl::IsMessageCenterVisible() const {
@@ -398,9 +393,7 @@
 
   visible_notifications_ =
       notification_list_->GetVisibleNotifications(blockers_);
-  for (MessageCenterObserver& observer : observer_list_) {
-    observer.OnNotificationAdded(id);
-  }
+  observer_list_.Notify(&MessageCenterObserver::OnNotificationAdded, id);
 
 #if BUILDFLAG(IS_CHROMEOS_ASH)
   ScheduleCleaningTaskIfCountOverLimit();
diff --git a/ui/message_center/notification_blocker.cc b/ui/message_center/notification_blocker.cc
index 5ea0af1..807e599 100644
--- a/ui/message_center/notification_blocker.cc
+++ b/ui/message_center/notification_blocker.cc
@@ -41,8 +41,7 @@
 }
 
 void NotificationBlocker::NotifyBlockingStateChanged() {
-  for (auto& observer : observers_)
-    observer.OnBlockingStateChanged(this);
+  observers_.Notify(&Observer::OnBlockingStateChanged, this);
 }
 
 }  // namespace message_center
diff --git a/ui/message_center/views/message_view.cc b/ui/message_center/views/message_view.cc
index b2d2f6f..1320d0db 100644
--- a/ui/message_center/views/message_view.cc
+++ b/ui/message_center/views/message_view.cc
@@ -351,9 +351,7 @@
 }
 
 void MessageView::OnSlideStarted() {
-  for (auto& observer : observers_) {
-    observer.OnSlideStarted(notification_id_);
-  }
+  observers_.Notify(&Observer::OnSlideStarted, notification_id_);
 }
 
 void MessageView::OnSlideChanged(bool in_progress) {
@@ -372,11 +370,10 @@
         views::ScrollView::ScrollBarMode::kEnabled);
   }
 
-  for (auto& observer : observers_) {
-    if (in_progress)
-      observer.OnSlideChanged(notification_id_);
-    else
-      observer.OnSlideEnded(notification_id_);
+  if (in_progress) {
+    observers_.Notify(&Observer::OnSlideChanged, notification_id_);
+  } else {
+    observers_.Notify(&Observer::OnSlideEnded, notification_id_);
   }
 }
 
@@ -394,18 +391,14 @@
 
   // The notification may be deleted after slide out, so give observers a
   // chance to handle the notification before fulling sliding out.
-  for (auto& observer : observers_) {
-    observer.OnPreSlideOut(notification_id_);
-  }
+  observers_.Notify(&Observer::OnPreSlideOut, notification_id_);
 
   // Copy the |notification_id| here as calling OnSlideOut() might destroy
   // |this| but we still want to call RemoveNotification(). Note that the
   // iteration over |observers_| is still safe and will simply stop.
   std::string notification_id_copy = notification_id_;
 
-  for (auto& observer : observers_) {
-    observer.OnSlideOut(notification_id_);
-  }
+  observers_.Notify(&Observer::OnSlideOut, notification_id_);
 
   auto* message_center = MessageCenter::Get();
   if (message_center->FindPopupNotificationById(notification_id_copy)) {
@@ -496,15 +489,13 @@
 }
 
 void MessageView::OnCloseButtonPressed() {
-  for (auto& observer : observers_)
-    observer.OnCloseButtonPressed(notification_id_);
+  observers_.Notify(&Observer::OnCloseButtonPressed, notification_id_);
   MessageCenter::Get()->RemoveNotification(notification_id_,
                                            true /* by_user */);
 }
 
 void MessageView::OnSettingsButtonPressed(const ui::Event& event) {
-  for (auto& observer : observers_)
-    observer.OnSettingsButtonPressed(notification_id_);
+  observers_.Notify(&Observer::OnSettingsButtonPressed, notification_id_);
 
   if (inline_settings_enabled_) {
     ToggleInlineSettings(event);
@@ -514,8 +505,7 @@
 }
 
 void MessageView::OnSnoozeButtonPressed(const ui::Event& event) {
-  for (auto& observer : observers_)
-    observer.OnSnoozeButtonPressed(notification_id_);
+  observers_.Notify(&Observer::OnSnoozeButtonPressed, notification_id_);
 
   if (snooze_settings_enabled_) {
     ToggleSnoozeSettings(event);