Commit 5c8ea0ba authored by Eriko Kurimoto's avatar Eriko Kurimoto Committed by Commit Bot

SharedWorker: Add use counter to shared worker module script loadings

This CL adds use counter.
When SharedWorker constructor is called with 'classic' type,
ClassicSharedWorker is counted. If not, ModuleSharedWorker is counted.
If type attribute is not defined, it is regarded as ClassicScript.

Bug: 1023338
Change-Id: Ia126a51df040d363c66cbe0a7ff91a5e59849eaa
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2018354
Commit-Queue: Eriko Kurimoto <elkurin@google.com>
Reviewed-by: default avatarKenichi Ishibashi <bashi@chromium.org>
Reviewed-by: default avatarHiroki Nakagawa <nhiroki@chromium.org>
Reviewed-by: default avatarMakoto Shimazu <shimazu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#735782}
parent 1bfaa08c
......@@ -2510,6 +2510,8 @@ enum WebFeature {
kSchedulerPostTask = 3145,
kV8Animation_Onremove_AttributeGetter = 3146,
kV8Animation_Onremove_AttributeSetter = 3147,
kClassicSharedWorker = 3148,
kModuleSharedWorker = 3149,
// Add new features immediately above this line. Don't change assigned
// numbers of any item, and don't reuse removed slots.
......
......@@ -120,6 +120,10 @@ There are some fundamental metrics.
: Counts of `new DedicatedWorker()` calls in `DedicatedWorkerGlobalScope`.
- [SharedWorkerStart](https://www.chromestatus.com/metrics/feature/timeline/popularity/5)
: Counts of `new SharedWorker()` calls in `Document`.
- [ClassicSharedWorker](https://www.chromestatus.com/metrics/feature/timeline/popularity/3148)
: Counts of new SharedWorker() calls with `{ type: 'classic' }` or without `WorkerOptions#type` argument.
- [ModuleSharedWorker](https://www.chromestatus.com/metrics/feature/timeline/popularity/3149)
: Counts of new SharedWorker() calls with `{ type: 'module' }`.
- [WorkletAddModule](https://www.chromestatus.com/metrics/feature/timeline/popularity/2364)
: Counts of `Worklet#addModule()` calls in `Document`. This includes all worklet
types. Each worklet type has its own counter, too.
......
......@@ -135,6 +135,10 @@ SharedWorker* SharedWorker::Create(ExecutionContext* context,
NOTREACHED();
}
DCHECK(!options->name.IsNull());
if (options->type == mojom::blink::ScriptType::kClassic)
UseCounter::Count(document, WebFeature::kClassicSharedWorker);
else if (options->type == mojom::blink::ScriptType::kModule)
UseCounter::Count(document, WebFeature::kModuleSharedWorker);
SharedWorkerClientHolder::From(*document)->Connect(
worker, std::move(remote_port), script_url, std::move(blob_url_token),
......
......@@ -2,7 +2,14 @@
<title>Shared Worker: UseCounter</title>
<script>
self.connectToWorker = () => {
var worker = new SharedWorker('shared-worker-usecounter.js');
const worker = new SharedWorker('shared-worker-usecounter.js');
};
self.connectToWorkerWithScriptType = type => {
const worker = new SharedWorker('empty.js',
{ name: type + '-worker', type });
};
self.connectToWorkerWithoutScriptType = () => {
const worker = new SharedWorker('empty.js', 'notype-worker');
};
window.opener.postMessage('LOADED', '*');
</script>
......@@ -6,6 +6,10 @@
</body>
<script>
// From web_feature.mojom
const kFeatureClassicSharedWorker = 3148;
const kFeatureModuleSharedWorker = 3149;
const kFeature = 675; // From UseCounter.h
const kDeprecatedFeature = 166; // From Deprecation.h
......@@ -28,9 +32,35 @@ function openWindow(url) {
});
}
promise_test(t => {
const kWindowUrl = 'resources/shared-worker-usecounter-window.html';
const kWindowUrl = 'resources/shared-worker-usecounter-window.html';
promise_test(async t => {
// Start a shared worker using classic scripts.
const win1 = await openWindow(kWindowUrl);
assert_false(isUseCounted(win1, kFeatureClassicSharedWorker));
win1.connectToWorkerWithScriptType('classic');
await observeUseCounter(win1, kFeatureClassicSharedWorker);
assert_true(isUseCounted(win1, kFeatureClassicSharedWorker));
assert_false(isUseCounted(win1, kFeatureModuleSharedWorker));
// Start a shared worker using module scripts.
const win2 = await openWindow(kWindowUrl);
assert_false(isUseCounted(win2, kFeatureModuleSharedWorker));
win2.connectToWorkerWithScriptType('module');
await observeUseCounter(win2, kFeatureModuleSharedWorker);
assert_true(isUseCounted(win2, kFeatureModuleSharedWorker));
assert_false(isUseCounted(win2, kFeatureClassicSharedWorker));
// Start a shared worker without type attribute.
const win3 = await openWindow(kWindowUrl);
assert_false(isUseCounted(win3, kFeatureClassicSharedWorker));
win3.connectToWorkerWithoutScriptType();
await observeUseCounter(win3, kFeatureClassicSharedWorker);
assert_true(isUseCounted(win3, kFeatureClassicSharedWorker));
assert_false(isUseCounted(win3, kFeatureModuleSharedWorker));
}, 'UseCounter for script types on a shared worker');
promise_test(t => {
let win1;
let win2;
let win3;
......
......@@ -26130,6 +26130,8 @@ to ensure that the crash string is shown properly on the user-facing crash UI.
<int value="3145" label="SchedulerPostTask"/>
<int value="3146" label="V8Animation_Onremove_AttributeGetter"/>
<int value="3147" label="V8Animation_Onremove_AttributeSetter"/>
<int value="3148" label="ClassicSharedWorker"/>
<int value="3149" label="ModuleSharedWorker"/>
</enum>
<enum name="FeaturePolicyAllowlistType">
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