Commit cd9c0f48 authored by arthursonzogni's avatar arthursonzogni Committed by Commit Bot

Record if the navigation's initiator is available.

In NavigationRequest::BeginNavigation(), records whether the
navigation's initiator can be found using its ID or not.

We suspect not finding it is a very rare event. This histogram will help
us figure out what kind of solution should be used to support
PolicyContainer for this edge case.

Bug:1129416

Change-Id: I501bf0150935679667d5bd2a4cc351a70b6653ab
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2416450Reviewed-by: default avatarCamille Lamy <clamy@chromium.org>
Reviewed-by: default avatarPâris Meuleman <pmeuleman@chromium.org>
Reviewed-by: default avatarIlya Sherman <isherman@chromium.org>
Reviewed-by: default avatarAntonio Sartori <antoniosartori@chromium.org>
Commit-Queue: Arthur Sonzogni <arthursonzogni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#812124}
parent 6ebabdce
......@@ -13,6 +13,7 @@
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/bind_test_util.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/test_timeouts.h"
#include "base/threading/thread_restrictions.h"
......@@ -3788,4 +3789,46 @@ IN_PROC_BROWSER_TEST_F(DocumentPolicyBrowserTest,
EXPECT_FALSE(last_metadata.is_scroll_offset_at_top);
}
IN_PROC_BROWSER_TEST_F(NavigationBrowserTest, RecordInitiatorRfh) {
base::HistogramTester histograms;
GURL url(embedded_test_server()->GetURL("/empty.html"));
// First navigation with no initiator.
EXPECT_TRUE(NavigateToURL(shell(), url));
ShellAddedObserver new_shell_observer;
{
std::vector<base::Bucket> samples =
histograms.GetAllSamples("Navigation.InitiatorRFH");
EXPECT_EQ(1u, samples.size());
EXPECT_EQ(1, samples[0].count); // InitiatorRFH::NONE
}
// Second navigation with an initiator and a matching RenderFrameHost.
EXPECT_TRUE(ExecJs(shell(), JsReplace("window.open($1);", url)));
Shell* openee_shell = new_shell_observer.GetShell();
{
std::vector<base::Bucket> samples =
histograms.GetAllSamples("Navigation.InitiatorRFH");
EXPECT_EQ(1, samples[0].count); // InitiatorRFH::NONE
EXPECT_EQ(1, samples[1].count); // InitiatorRFH::EXISTING_RFH
}
// Third navigation with an initiator and no matching RenderFrameHost.
TestNavigationObserver observer(shell()->web_contents());
EXPECT_TRUE(ExecJs(openee_shell, R"(
onunload = () => opener.location.href = "about:blank";
)"));
openee_shell->Close();
observer.Wait();
{
std::vector<base::Bucket> samples =
histograms.GetAllSamples("Navigation.InitiatorRFH");
EXPECT_EQ(3u, samples.size());
EXPECT_EQ(1, samples[0].count); // InitiatorRFH::NONE
EXPECT_EQ(1, samples[1].count); // InitiatorRFH::EXISTING_RFH
EXPECT_EQ(1, samples[2].count); // InitiatorRFH::DELETED_RFH
}
}
} // namespace content
......@@ -728,6 +728,28 @@ url::Origin GetOriginForURLLoaderFactoryUnchecked(
common_params.initiator_origin.value_or(url::Origin()));
}
void RecordInitiatorRFH(GlobalFrameRoutingId id) {
// Corresponds to the "InitiatorRFH" histogram enumeration type in
// tools/metrics/histograms/enums.xml.
//
// DO NOT REORDER OR CHANGE THE MEANING OF THESE VALUES.
enum InitiatorRFH {
NONE = 0,
EXISTING_RFH = 1,
DELETED_RFH = 2,
kMaxValue = DELETED_RFH,
} value;
if (!id)
value = NONE;
else if (RenderFrameHost::FromID(id))
value = EXISTING_RFH;
else
value = DELETED_RFH;
UMA_HISTOGRAM_ENUMERATION("Navigation.InitiatorRFH", value);
}
} // namespace
// static
......@@ -1076,6 +1098,8 @@ NavigationRequest::NavigationRequest(
base::trace_event::ToTracedValue(this));
TRACE_EVENT_NESTABLE_ASYNC_BEGIN0("navigation", "Initializing",
navigation_id_);
RecordInitiatorRFH(GetInitiatorRoutingId());
NavigationControllerImpl* controller = GetNavigationController();
if (frame_entry) {
......
......@@ -36821,6 +36821,16 @@ Called by update_gpu_driver_bug_workaround_entries.py.-->
<int value="3" label="Has access"/>
</enum>
<enum name="InitiatorRFH">
<int value="0" label="No initiator"/>
<int value="1"
label="Initiator RenderFrameHost existed when the NavigationRequest was
created"/>
<int value="2"
label="Initiator RenderFrameHost did not exist anymore when the
NavigationRequest was created"/>
</enum>
<enum name="InjectedAdType">
<int value="0" label="Invalid"/>
<int value="1" label="IFrame"/>
......@@ -256,6 +256,18 @@ reviews. Googlers can read more about this at go/gwsq-gerrit.
</summary>
</histogram>
<histogram name="Navigation.InitiatorRFH" enum="InitiatorRFH"
expires_after="M89">
<owner>arthursonzogni@chromium.org</owner>
<owner>pmeuleman@chromium.org</owner>
<owner>antoniosartori@chromium.org</owner>
<owner>clamy@chromium.org</owner>
<summary>
Count how many NavigationRequests can find their associated initiator's
RenderFrameHost.
</summary>
</histogram>
<histogram name="Navigation.IOSNullContextInDidFailProvisionalNavigation"
enum="Boolean" expires_after="M85">
<owner>ajuma@chromium.org</owner>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment