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

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

Issue 2380773002: Prevent tracking metrics for cases such as 204s and downloads. (Closed)
Patch Set: use existing test file 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
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 1ca66e37badf183e35d83311e16ae78205437a41..6ddde73c8424d259206eb19f50c4d8ea320efc93 100644
--- a/chrome/browser/page_load_metrics/metrics_web_contents_observer.cc
+++ b/chrome/browser/page_load_metrics/metrics_web_contents_observer.cc
@@ -850,6 +850,16 @@ void MetricsWebContentsObserver::DidFinishNavigation(
return;
}
+ // Ignore internally generated aborts for navigations with HTTP responses that
+ // don't commit, such as HTTP 204 responses and downloads.
+ if (!navigation_handle->HasCommitted() &&
+ navigation_handle->GetNetErrorCode() == net::ERR_ABORTED &&
+ navigation_handle->GetResponseHeaders()) {
+ if (finished_nav)
+ finished_nav->StopTracking();
+ return;
+ }
+
const bool should_track =
finished_nav && ShouldTrackNavigation(navigation_handle);
@@ -878,10 +888,7 @@ void MetricsWebContentsObserver::DidFinishNavigation(
}
// Handle a pre-commit error. Navigations that result in an error page will be
-// ignored. Note that downloads/204s will result in HasCommitted() returning
-// false.
-// TODO(csharrison): Track changes to NavigationHandle for signals when this is
-// the case (HTTP response headers).
+// ignored.
void MetricsWebContentsObserver::HandleFailedNavigationForTrackedLoad(
content::NavigationHandle* navigation_handle,
std::unique_ptr<PageLoadTracker> tracker) {
@@ -894,8 +901,7 @@ void MetricsWebContentsObserver::HandleFailedNavigationForTrackedLoad(
// pre-PlzNavigate, but afterwards it should represent the navigation stopped
// by the user before it was ready to commit.
// net::ERR_ABORTED: An aborted provisional load has error
- // net::ERR_ABORTED. Note that this can come from some non user-initiated
- // errors, such as downloads, or 204 responses. See crbug.com/542369.
+ // net::ERR_ABORTED.
if ((error == net::OK) || (error == net::ERR_ABORTED)) {
tracker->NotifyAbort(ABORT_OTHER, false, base::TimeTicks::Now(), true);
aborted_provisional_loads_.push_back(std::move(tracker));

Powered by Google App Engine
This is Rietveld 408576698