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

Side by Side 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: fix comment, and disable tests for browser side navigation Created 4 years, 2 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 unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/page_load_metrics/page_load_metrics_browsertest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/page_load_metrics/metrics_web_contents_observer.h" 5 #include "chrome/browser/page_load_metrics/metrics_web_contents_observer.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <ostream> 8 #include <ostream>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
(...skipping 830 matching lines...) Expand 10 before | Expand all | Expand 10 after
841 std::move(provisional_loads_[navigation_handle])); 841 std::move(provisional_loads_[navigation_handle]));
842 provisional_loads_.erase(navigation_handle); 842 provisional_loads_.erase(navigation_handle);
843 843
844 // Ignore same-page navigations. 844 // Ignore same-page navigations.
845 if (navigation_handle->HasCommitted() && navigation_handle->IsSamePage()) { 845 if (navigation_handle->HasCommitted() && navigation_handle->IsSamePage()) {
846 if (finished_nav) 846 if (finished_nav)
847 finished_nav->StopTracking(); 847 finished_nav->StopTracking();
848 return; 848 return;
849 } 849 }
850 850
851 // Ignore internally generated aborts for navigations with HTTP responses that
852 // don't commit, such as HTTP 204 responses and downloads.
853 if (!navigation_handle->HasCommitted() &&
854 navigation_handle->GetNetErrorCode() == net::ERR_ABORTED &&
855 navigation_handle->GetResponseHeaders()) {
856 if (finished_nav)
857 finished_nav->StopTracking();
858 return;
859 }
860
851 const bool should_track = 861 const bool should_track =
852 finished_nav && ShouldTrackNavigation(navigation_handle); 862 finished_nav && ShouldTrackNavigation(navigation_handle);
853 863
854 if (finished_nav && !should_track) 864 if (finished_nav && !should_track)
855 finished_nav->StopTracking(); 865 finished_nav->StopTracking();
856 866
857 if (navigation_handle->HasCommitted()) { 867 if (navigation_handle->HasCommitted()) {
858 // Notify other loads that they may have been aborted by this committed 868 // Notify other loads that they may have been aborted by this committed
859 // load. is_certainly_browser_timestamp is set to false because 869 // load. is_certainly_browser_timestamp is set to false because
860 // NavigationStart() could be set in either the renderer or browser process. 870 // NavigationStart() could be set in either the renderer or browser process.
861 NotifyAbortAllLoadsWithTimestamp( 871 NotifyAbortAllLoadsWithTimestamp(
862 AbortTypeForPageTransition(navigation_handle->GetPageTransition()), 872 AbortTypeForPageTransition(navigation_handle->GetPageTransition()),
863 IsNavigationUserInitiated(navigation_handle), 873 IsNavigationUserInitiated(navigation_handle),
864 navigation_handle->NavigationStart(), false); 874 navigation_handle->NavigationStart(), false);
865 875
866 if (should_track) { 876 if (should_track) {
867 HandleCommittedNavigationForTrackedLoad(navigation_handle, 877 HandleCommittedNavigationForTrackedLoad(navigation_handle,
868 std::move(finished_nav)); 878 std::move(finished_nav));
869 } else { 879 } else {
870 committed_load_.reset(); 880 committed_load_.reset();
871 } 881 }
872 } else if (should_track) { 882 } else if (should_track) {
873 HandleFailedNavigationForTrackedLoad(navigation_handle, 883 HandleFailedNavigationForTrackedLoad(navigation_handle,
874 std::move(finished_nav)); 884 std::move(finished_nav));
875 } 885 }
876 } 886 }
877 887
878 // Handle a pre-commit error. Navigations that result in an error page will be 888 // Handle a pre-commit error. Navigations that result in an error page will be
879 // ignored. Note that downloads/204s will result in HasCommitted() returning 889 // ignored.
880 // false.
881 // TODO(csharrison): Track changes to NavigationHandle for signals when this is
882 // the case (HTTP response headers).
883 void MetricsWebContentsObserver::HandleFailedNavigationForTrackedLoad( 890 void MetricsWebContentsObserver::HandleFailedNavigationForTrackedLoad(
884 content::NavigationHandle* navigation_handle, 891 content::NavigationHandle* navigation_handle,
885 std::unique_ptr<PageLoadTracker> tracker) { 892 std::unique_ptr<PageLoadTracker> tracker) {
886 tracker->FailedProvisionalLoad(navigation_handle); 893 tracker->FailedProvisionalLoad(navigation_handle);
887 894
888 net::Error error = navigation_handle->GetNetErrorCode(); 895 net::Error error = navigation_handle->GetNetErrorCode();
889 896
890 // net::OK: This case occurs when the NavigationHandle finishes and reports 897 // net::OK: This case occurs when the NavigationHandle finishes and reports
891 // !HasCommitted(), but reports no net::Error. This should not occur 898 // !HasCommitted(), but reports no net::Error. This should not occur
892 // pre-PlzNavigate, but afterwards it should represent the navigation stopped 899 // pre-PlzNavigate, but afterwards it should represent the navigation stopped
893 // by the user before it was ready to commit. 900 // by the user before it was ready to commit.
894 // net::ERR_ABORTED: An aborted provisional load has error 901 // net::ERR_ABORTED: An aborted provisional load has error
895 // net::ERR_ABORTED. Note that this can come from some non user-initiated 902 // net::ERR_ABORTED.
896 // errors, such as downloads, or 204 responses. See crbug.com/542369.
897 if ((error == net::OK) || (error == net::ERR_ABORTED)) { 903 if ((error == net::OK) || (error == net::ERR_ABORTED)) {
898 tracker->NotifyAbort(ABORT_OTHER, false, base::TimeTicks::Now(), true); 904 tracker->NotifyAbort(ABORT_OTHER, false, base::TimeTicks::Now(), true);
899 aborted_provisional_loads_.push_back(std::move(tracker)); 905 aborted_provisional_loads_.push_back(std::move(tracker));
900 } 906 }
901 } 907 }
902 908
903 void MetricsWebContentsObserver::HandleCommittedNavigationForTrackedLoad( 909 void MetricsWebContentsObserver::HandleCommittedNavigationForTrackedLoad(
904 content::NavigationHandle* navigation_handle, 910 content::NavigationHandle* navigation_handle,
905 std::unique_ptr<PageLoadTracker> tracker) { 911 std::unique_ptr<PageLoadTracker> tracker) {
906 if (!navigation_handle->HasUserGesture() && 912 if (!navigation_handle->HasUserGesture() &&
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
1092 content::NavigationHandle* navigation_handle) const { 1098 content::NavigationHandle* navigation_handle) const {
1093 DCHECK(navigation_handle->IsInMainFrame()); 1099 DCHECK(navigation_handle->IsInMainFrame());
1094 DCHECK(!navigation_handle->HasCommitted() || 1100 DCHECK(!navigation_handle->HasCommitted() ||
1095 !navigation_handle->IsSamePage()); 1101 !navigation_handle->IsSamePage());
1096 1102
1097 return BrowserPageTrackDecider(embedder_interface_.get(), web_contents(), 1103 return BrowserPageTrackDecider(embedder_interface_.get(), web_contents(),
1098 navigation_handle).ShouldTrack(); 1104 navigation_handle).ShouldTrack();
1099 } 1105 }
1100 1106
1101 } // namespace page_load_metrics 1107 } // namespace page_load_metrics
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/page_load_metrics/page_load_metrics_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698