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

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

Issue 1740403002: Suppress spurious foreground/background notifications (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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 | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/page_load_metrics/browser/metrics_web_contents_observer.cc
diff --git a/components/page_load_metrics/browser/metrics_web_contents_observer.cc b/components/page_load_metrics/browser/metrics_web_contents_observer.cc
index 21130fa48e099d66c5a0a96865dcc28282b0fb88..539e2cd1bc33be2a5fbb03de2bed1bf9604fcf05 100644
--- a/components/page_load_metrics/browser/metrics_web_contents_observer.cc
+++ b/components/page_load_metrics/browser/metrics_web_contents_observer.cc
@@ -159,14 +159,24 @@ void PageLoadTracker::LogAbortChainHistograms(
void PageLoadTracker::WebContentsHidden() {
// Only log the first time we background in a given page load.
- if (background_time_.is_null())
+ if (background_time_.is_null()) {
+ // Make sure we either started in the foreground and haven't been
+ // foregrounded yet, or started in the background and have already been
+ // foregrounded.
+ DCHECK_EQ(started_in_foreground_, foreground_time_.is_null());
background_time_ = base::TimeTicks::Now();
+ }
}
void PageLoadTracker::WebContentsShown() {
// Only log the first time we foreground in a given page load.
- if (foreground_time_.is_null())
+ if (foreground_time_.is_null()) {
+ // Make sure we either started in the background and haven't been
+ // backgrounded yet, or started in the foreground and have already been
+ // backgrounded.
+ DCHECK_NE(started_in_foreground_, background_time_.is_null());
foreground_time_ = base::TimeTicks::Now();
+ }
}
void PageLoadTracker::Commit(content::NavigationHandle* navigation_handle) {
@@ -439,6 +449,8 @@ void MetricsWebContentsObserver::DidRedirectNavigation(
}
void MetricsWebContentsObserver::WasShown() {
+ if (in_foreground_)
+ return;
in_foreground_ = true;
if (committed_load_)
committed_load_->WebContentsShown();
@@ -448,6 +460,8 @@ void MetricsWebContentsObserver::WasShown() {
}
void MetricsWebContentsObserver::WasHidden() {
+ if (!in_foreground_)
+ return;
in_foreground_ = false;
if (committed_load_)
committed_load_->WebContentsHidden();
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698