Commit 09baa4da authored by Dominic Farolino's avatar Dominic Farolino Committed by Commit Bot

Add Async Script Count UKM

This CL adds UKM to count the number of async scripts associated with
a given mainframe document.

Google-internal UKM privacy review:
https://docs.google.com/document/d/1bKyDRF5BAQpPJ-bRyKs2dgqBTJI43b63kOULO-HIuXM/edit

Bug: 1086227
Change-Id: Iaaee8c756952613c2ea58416b453a98a0843773f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2209118
Commit-Queue: Dominic Farolino <dom@chromium.org>
Reviewed-by: default avatarRobert Kaplow <rkaplow@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Cr-Commit-Position: refs/heads/master@{#771611}
parent 152e039f
......@@ -42,6 +42,7 @@
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "mojo/public/mojom/base/text_direction.mojom-blink.h"
#include "services/metrics/public/cpp/metrics_utils.h"
#include "services/metrics/public/cpp/mojo_ukm_recorder.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "services/metrics/public/cpp/ukm_source_id.h"
......@@ -6855,9 +6856,24 @@ void SetOriginTrialFreezePolicy(
} // namespace
void Document::RecordAsyncScriptCount() {
// Only record async script count for mainframe documents, as per UKM policy.
if (!IsInMainFrame())
return;
auto* recorder = UkmRecorder();
DCHECK(recorder);
DCHECK(UkmSourceID() != ukm::kInvalidSourceId);
ukm::builders::Blink_Script_AsyncScripts(UkmSourceID())
.SetAsyncScriptCount(
ukm::GetExponentialBucketMin(async_script_count_, 1.3))
.Record(recorder);
}
void Document::FinishedParsing() {
DCHECK(!GetScriptableDocumentParser() || !parser_->IsParsing());
DCHECK(!GetScriptableDocumentParser() || ready_state_ != kLoading);
RecordAsyncScriptCount();
SetParsingState(kInDOMContentLoaded);
DocumentParserTiming::From(*this).MarkParserStop();
......
......@@ -1686,6 +1686,9 @@ class CORE_EXPORT Document : public ContainerNode,
FontPreloadManager& GetFontPreloadManager() { return font_preload_manager_; }
void FontPreloadingFinishedOrTimedOut();
void IncrementAsyncScriptCount() { async_script_count_++; }
void RecordAsyncScriptCount();
void SetFindInPageActiveMatchNode(Node*);
const Node* GetFindInPageActiveMatchNode() const;
......@@ -2269,6 +2272,8 @@ class CORE_EXPORT Document : public ContainerNode,
FontPreloadManager font_preload_manager_;
int async_script_count_ = 0;
WeakMember<Node> find_in_page_active_match_node_;
};
......
......@@ -842,6 +842,8 @@ bool ScriptLoader::PrepareScript(const TextPosition& script_start_position,
// script is ready, execute the script block and then remove the element
// from the set of scripts that will execute as soon as possible.</spec>
pending_script_ = TakePendingScript(ScriptSchedulingType::kAsync);
// This is for the UKM count of async scripts in a document.
context_window->document()->IncrementAsyncScriptCount();
// TODO(hiroshige): Here the context document is used as "node document"
// while Step 14 uses |elementDocument| as "node document". Fix this.
context_window->document()->GetScriptRunner()->QueueScriptForExecution(
......
......@@ -1835,6 +1835,21 @@ be describing additional metrics about the same event.
</metric>
</event>
<event name="Blink.Script.AsyncScripts" singular="True">
<owner>dom@chromium.org</owner>
<owner>chrome-loading@google.com</owner>
<summary>
Metrics associated with the async script count associated with a document,
recorded when the HTML parsing of a mainframe has completed.
</summary>
<metric name="AsyncScriptCount">
<summary>
The total number of async scripts associated with a document at the time
parsing has finished.
</summary>
</metric>
</event>
<event name="Blink.UpdateTime">
<owner>schenney@chromium.org</owner>
<owner>paint-dev@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