Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(995)

Unified Diff: chrome/browser/page_load_metrics/metrics_web_contents_observer.cc

Issue 2372573005: Update OnCommit to return ObservePolicy. (Closed)
Patch Set: restore missing private: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/page_load_metrics/metrics_web_contents_observer_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/page_load_metrics/metrics_web_contents_observer.cc
diff --git a/chrome/browser/page_load_metrics/metrics_web_contents_observer.cc b/chrome/browser/page_load_metrics/metrics_web_contents_observer.cc
index 0a1bf48d2475c23ef94aaf2c9fa5c120d7301306..1ca66e37badf183e35d83311e16ae78205437a41 100644
--- a/chrome/browser/page_load_metrics/metrics_web_contents_observer.cc
+++ b/chrome/browser/page_load_metrics/metrics_web_contents_observer.cc
@@ -33,6 +33,19 @@
DEFINE_WEB_CONTENTS_USER_DATA_KEY(
page_load_metrics::MetricsWebContentsObserver);
+// This macro invokes the specified method on each observer, passing the
+// variable length arguments as the method's arguments, and removes the observer
+// from the list of observers if the given method returns STOP_OBSERVING.
+#define INVOKE_AND_PRUNE_OBSERVERS(observers, Method, ...) \
+ for (auto it = observers.begin(); it != observers.end();) { \
+ if ((*it)->Method(__VA_ARGS__) == \
+ PageLoadMetricsObserver::STOP_OBSERVING) { \
+ it = observers.erase(it); \
+ } else { \
+ ++it; \
+ } \
+ }
+
namespace page_load_metrics {
namespace internal {
@@ -442,9 +455,8 @@ void PageLoadTracker::Commit(content::NavigationHandle* navigation_handle) {
// Some transitions (like CLIENT_REDIRECT) are only known at commit time.
page_transition_ = navigation_handle->GetPageTransition();
user_gesture_ = navigation_handle->HasUserGesture();
- for (const auto& observer : observers_) {
- observer->OnCommit(navigation_handle);
- }
+
+ INVOKE_AND_PRUNE_OBSERVERS(observers_, OnCommit, navigation_handle);
LogAbortChainHistograms(navigation_handle);
}
@@ -475,14 +487,8 @@ void PageLoadTracker::FlushMetricsOnAppEnterBackground() {
}
const PageLoadExtraInfo info = ComputePageLoadExtraInfo();
- for (auto it = observers_.begin(); it != observers_.end();) {
- if ((*it)->FlushMetricsOnAppEnterBackground(timing_, info) ==
- PageLoadMetricsObserver::STOP_OBSERVING) {
- it = observers_.erase(it);
- } else {
- ++it;
- }
- }
+ INVOKE_AND_PRUNE_OBSERVERS(observers_, FlushMetricsOnAppEnterBackground,
+ timing_, info);
}
void PageLoadTracker::NotifyClientRedirectTo(
« no previous file with comments | « no previous file | chrome/browser/page_load_metrics/metrics_web_contents_observer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698