Record the maximum number of frames in WebContents
This CL records the maximum number of frames present in web contents.
The records will help us better predict the cost of improving
SupervisedUserNavigationThrottle to filter at the iframe level.
The will help us predict the following two information:
1. By how much will the requests for the kids management servers
to classify urls will increase as a result of iframe filtering.
2. By how much will we delay the overall page load time?
Bug: 850328
Change-Id: I01cf33305a67aa01e3ab416d1659e027156bedef
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1769663
Commit-Queue: Yilkal Abe <[email protected]>
Reviewed-by: Alex Moshchuk <[email protected]>
Reviewed-by: Alexei Svitkine <[email protected]>
Reviewed-by: Michael Giuffrida <[email protected]>
Cr-Commit-Position: refs/heads/master@{#702248}
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
index 5c9557b3..a153a814 100644
--- a/content/browser/web_contents/web_contents_impl.cc
+++ b/content/browser/web_contents/web_contents_impl.cc
@@ -300,6 +300,11 @@
return true;
}
+void RecordMaxFrameCountUMA(size_t max_frame_count) {
+ UMA_HISTOGRAM_COUNTS_10000("Navigation.MainFrame.MaxFrameCount",
+ max_frame_count);
+}
+
} // namespace
std::unique_ptr<WebContents> WebContents::Create(
@@ -4397,6 +4402,13 @@
NavigationHandle* navigation_handle) {
TRACE_EVENT1("navigation", "WebContentsImpl::ReadyToCommitNavigation",
"navigation_handle", navigation_handle);
+
+ if (!navigation_handle->GetParentFrame() &&
+ record_max_frame_count_when_leaving_current_page_) {
+ RecordMaxFrameCountUMA(max_frame_count_);
+ record_max_frame_count_when_leaving_current_page_ = false;
+ }
+
for (auto& observer : observers_)
observer.ReadyToCommitNavigation(navigation_handle);
@@ -4484,6 +4496,17 @@
navigation_handle->GetURL() != url::kAboutBlankURL) {
should_focus_location_bar_by_default_ = false;
}
+
+ // If navigation has successfully finished in the main page, set
+ // |record_max_frame_count_when_leaving_current_page_| to true so that when
+ // the main frame navigates away from this page we know to record this page's
+ // max frame count.
+ if (navigation_handle->IsInMainFrame() && !navigation_handle->IsErrorPage()) {
+ record_max_frame_count_when_leaving_current_page_ = true;
+
+ // Navigation has completed in main frame. Reset |max_frame_count_| to 1.
+ max_frame_count_ = 1;
+ }
}
void WebContentsImpl::DidFailLoadWithError(
@@ -5289,6 +5312,12 @@
void WebContentsImpl::NotifyFrameSwapped(RenderFrameHost* old_host,
RenderFrameHost* new_host,
bool is_main_frame) {
+ if (!old_host) {
+ frame_count_++;
+ if (max_frame_count_ < frame_count_)
+ max_frame_count_ = frame_count_;
+ }
+
#if defined(OS_ANDROID)
// Copy importance from |old_host| if |new_host| is a main frame.
if (old_host && !new_host->GetParent()) {
@@ -5393,6 +5422,12 @@
}
void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) {
+ if (!render_frame_host->GetParent() && IsBeingDestroyed() &&
+ record_max_frame_count_when_leaving_current_page_) {
+ // Main frame has been deleted because WebContents is being destroyed.
+ RecordMaxFrameCountUMA(max_frame_count_);
+ }
+
is_notifying_observers_ = true;
for (auto& observer : observers_)
observer.RenderFrameDeleted(render_frame_host);
@@ -6813,6 +6848,8 @@
}
void WebContentsImpl::OnFrameRemoved(RenderFrameHost* render_frame_host) {
+ frame_count_--;
+
for (auto& observer : observers_)
observer.FrameDeleted(render_frame_host);
}