OLD | NEW |
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> |
11 | 11 |
12 #include "base/location.h" | 12 #include "base/location.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
15 #include "base/metrics/histogram_macros.h" | 15 #include "base/metrics/histogram_macros.h" |
16 #include "base/metrics/user_metrics.h" | 16 #include "base/metrics/user_metrics.h" |
| 17 #include "chrome/browser/page_load_metrics/browser_page_track_decider.h" |
17 #include "chrome/browser/page_load_metrics/page_load_metrics_util.h" | 18 #include "chrome/browser/page_load_metrics/page_load_metrics_util.h" |
18 #include "chrome/common/page_load_metrics/page_load_metrics_messages.h" | 19 #include "chrome/common/page_load_metrics/page_load_metrics_messages.h" |
19 #include "chrome/common/page_load_metrics/page_load_timing.h" | 20 #include "chrome/common/page_load_metrics/page_load_timing.h" |
20 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
21 #include "content/public/browser/navigation_details.h" | 22 #include "content/public/browser/navigation_details.h" |
22 #include "content/public/browser/navigation_handle.h" | 23 #include "content/public/browser/navigation_handle.h" |
23 #include "content/public/browser/render_frame_host.h" | 24 #include "content/public/browser/render_frame_host.h" |
24 #include "content/public/browser/render_view_host.h" | 25 #include "content/public/browser/render_view_host.h" |
25 #include "content/public/browser/web_contents.h" | 26 #include "content/public/browser/web_contents.h" |
26 #include "content/public/browser/web_contents_observer.h" | 27 #include "content/public/browser/web_contents_observer.h" |
(...skipping 785 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
812 | 813 |
813 void MetricsWebContentsObserver::DidFinishNavigation( | 814 void MetricsWebContentsObserver::DidFinishNavigation( |
814 content::NavigationHandle* navigation_handle) { | 815 content::NavigationHandle* navigation_handle) { |
815 if (!navigation_handle->IsInMainFrame()) | 816 if (!navigation_handle->IsInMainFrame()) |
816 return; | 817 return; |
817 | 818 |
818 std::unique_ptr<PageLoadTracker> finished_nav( | 819 std::unique_ptr<PageLoadTracker> finished_nav( |
819 std::move(provisional_loads_[navigation_handle])); | 820 std::move(provisional_loads_[navigation_handle])); |
820 provisional_loads_.erase(navigation_handle); | 821 provisional_loads_.erase(navigation_handle); |
821 | 822 |
| 823 // Ignore same-page navigations. |
| 824 if (navigation_handle->HasCommitted() && navigation_handle->IsSamePage()) { |
| 825 if (finished_nav) |
| 826 finished_nav->StopTracking(); |
| 827 return; |
| 828 } |
| 829 |
822 const bool should_track = | 830 const bool should_track = |
823 finished_nav && ShouldTrackNavigation(navigation_handle); | 831 finished_nav && ShouldTrackNavigation(navigation_handle); |
824 | 832 |
825 if (finished_nav && !should_track) | 833 if (finished_nav && !should_track) |
826 finished_nav->StopTracking(); | 834 finished_nav->StopTracking(); |
827 | 835 |
828 if (navigation_handle->HasCommitted()) { | 836 if (navigation_handle->HasCommitted()) { |
829 // Ignore same-page navigations. | |
830 if (navigation_handle->IsSamePage()) | |
831 return; | |
832 | |
833 // Notify other loads that they may have been aborted by this committed | 837 // Notify other loads that they may have been aborted by this committed |
834 // load. is_certainly_browser_timestamp is set to false because | 838 // load. is_certainly_browser_timestamp is set to false because |
835 // NavigationStart() could be set in either the renderer or browser process. | 839 // NavigationStart() could be set in either the renderer or browser process. |
836 NotifyAbortAllLoadsWithTimestamp( | 840 NotifyAbortAllLoadsWithTimestamp( |
837 AbortTypeForPageTransition(navigation_handle->GetPageTransition()), | 841 AbortTypeForPageTransition(navigation_handle->GetPageTransition()), |
838 IsNavigationUserInitiated(navigation_handle), | 842 IsNavigationUserInitiated(navigation_handle), |
839 navigation_handle->NavigationStart(), false); | 843 navigation_handle->NavigationStart(), false); |
840 | 844 |
841 if (should_track) { | 845 if (should_track) { |
842 HandleCommittedNavigationForTrackedLoad(navigation_handle, | 846 HandleCommittedNavigationForTrackedLoad(navigation_handle, |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1054 // If the page load tracker cannot update its timing, something is wrong | 1058 // If the page load tracker cannot update its timing, something is wrong |
1055 // with the IPC (it's from another load, or it's invalid in some other way). | 1059 // with the IPC (it's from another load, or it's invalid in some other way). |
1056 // We expect this to be a rare occurrence. | 1060 // We expect this to be a rare occurrence. |
1057 RecordInternalError(ERR_BAD_TIMING_IPC); | 1061 RecordInternalError(ERR_BAD_TIMING_IPC); |
1058 } | 1062 } |
1059 } | 1063 } |
1060 | 1064 |
1061 bool MetricsWebContentsObserver::ShouldTrackNavigation( | 1065 bool MetricsWebContentsObserver::ShouldTrackNavigation( |
1062 content::NavigationHandle* navigation_handle) const { | 1066 content::NavigationHandle* navigation_handle) const { |
1063 DCHECK(navigation_handle->IsInMainFrame()); | 1067 DCHECK(navigation_handle->IsInMainFrame()); |
1064 if (!navigation_handle->GetURL().SchemeIsHTTPOrHTTPS()) | 1068 DCHECK(!navigation_handle->HasCommitted() || |
1065 return false; | 1069 !navigation_handle->IsSamePage()); |
1066 if (embedder_interface_->IsNewTabPageUrl(navigation_handle->GetURL())) | 1070 |
1067 return false; | 1071 return BrowserPageTrackDecider(embedder_interface_.get(), web_contents(), |
1068 if (navigation_handle->HasCommitted()) { | 1072 navigation_handle).ShouldTrack(); |
1069 if (navigation_handle->IsSamePage() || navigation_handle->IsErrorPage()) | |
1070 return false; | |
1071 const std::string& mime_type = web_contents()->GetContentsMimeType(); | |
1072 if (mime_type != "text/html" && mime_type != "application/xhtml+xml") | |
1073 return false; | |
1074 } | |
1075 return true; | |
1076 } | 1073 } |
1077 | 1074 |
1078 } // namespace page_load_metrics | 1075 } // namespace page_load_metrics |
OLD | NEW |