Commit 3880b655 authored by Hiroki Nakagawa's avatar Hiroki Nakagawa Committed by Commit Bot

Worker: Add use counters for WorkerOptions#type

This CL adds WebFeature::kClassicDedicatedWorker and
WebFeature::kModuleDedicatedWorker for WorkerOptions#type. These are
recorded in following cases.

(1) When a dedicated worker is constructed using classic scripts,
kClassicDedicatedWorker is recorded:

  const worker1 = new Worker('worker.js');  // or
  const worker2 = new Worker('worker.js', { type: 'classic' });

(2) When a dedicated worker is constructed using module scripts,
kModuleDedicatedWorker is recorded:

  const worker3 = new Worker('worker.js', { type: 'module' });

This CL adds web_tests for these cases.

In addition to that, this CL adds tests for existing kWorkerStart and
kNestedDedicatedWorker. kWorkerStart is recorded when a dedicated worker is
constructed regardless of given options (e.g., 'type') and creator's execution
context. kNestedDedicatedWorker is recorded when a dedicated worker is
constructed from another dedicated worker:

  const worker4 = new Worker('nested-worker.js');

  // In nested-worker.js
  const nested_worker = new Worker('worker.js');

Bug: 680046
Change-Id: Ic8aed3f9f43f6ceafeb5eac4a11382c7a21ea9b7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1906855
Commit-Queue: Hiroki Nakagawa <nhiroki@chromium.org>
Reviewed-by: default avatarMatt Falkenhagen <falken@chromium.org>
Reviewed-by: default avatarKenichi Ishibashi <bashi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#714148}
parent 671597ef
...@@ -2465,6 +2465,8 @@ enum WebFeature { ...@@ -2465,6 +2465,8 @@ enum WebFeature {
kHasGlyphRelativeUnits = 3081, kHasGlyphRelativeUnits = 3081,
kCountQueuingStrategyConstructor = 3082, kCountQueuingStrategyConstructor = 3082,
kByteLengthQueuingStrategyConstructor = 3083, kByteLengthQueuingStrategyConstructor = 3083,
kClassicDedicatedWorker = 3084,
kModuleDedicatedWorker = 3085,
// Add new features immediately above this line. Don't change assigned // Add new features immediately above this line. Don't change assigned
// numbers of any item, and don't reuse removed slots. // numbers of any item, and don't reuse removed slots.
......
...@@ -112,6 +112,10 @@ There are some fundamental metrics. ...@@ -112,6 +112,10 @@ There are some fundamental metrics.
- [WorkerStart](https://www.chromestatus.com/metrics/feature/timeline/popularity/4) - [WorkerStart](https://www.chromestatus.com/metrics/feature/timeline/popularity/4)
: Counts of `new DedicatedWorker()` calls in `Document` and : Counts of `new DedicatedWorker()` calls in `Document` and
`DedicatedWorkerGlobalScope`. `DedicatedWorkerGlobalScope`.
- [ClassicDedicatedWorker](https://www.chromestatus.com/metrics/feature/timeline/popularity/3084)
: Counts of new DedicatedWorker() calls with `{ type: 'classic' }` or without `WorkerOptions#type` argument.
- [ModuleDedicatedWorker](https://www.chromestatus.com/metrics/feature/timeline/popularity/3085)
: Counts of new DedicatedWorker() calls with `{ type: 'module' }`.
- [NestedDedicatedWorker](https://www.chromestatus.com/metrics/feature/timeline/popularity/2499) - [NestedDedicatedWorker](https://www.chromestatus.com/metrics/feature/timeline/popularity/2499)
: Counts of `new DedicatedWorker()` calls in `DedicatedWorkerGlobalScope`. : Counts of `new DedicatedWorker()` calls in `DedicatedWorkerGlobalScope`.
- [SharedWorkerStart](https://www.chromestatus.com/metrics/feature/timeline/popularity/5) - [SharedWorkerStart](https://www.chromestatus.com/metrics/feature/timeline/popularity/5)
......
...@@ -64,6 +64,8 @@ void DedicatedWorkerMessagingProxy::StartWorkerGlobalScope( ...@@ -64,6 +64,8 @@ void DedicatedWorkerMessagingProxy::StartWorkerGlobalScope(
if (options->type() == "classic") { if (options->type() == "classic") {
// "classic: Fetch a classic worker script given url, outside settings, // "classic: Fetch a classic worker script given url, outside settings,
// destination, and inside settings." // destination, and inside settings."
UseCounter::Count(GetExecutionContext(),
WebFeature::kClassicDedicatedWorker);
switch (off_main_thread_fetch_option) { switch (off_main_thread_fetch_option) {
case OffMainThreadWorkerScriptFetchOption::kEnabled: { case OffMainThreadWorkerScriptFetchOption::kEnabled: {
auto* resource_timing_notifier = auto* resource_timing_notifier =
...@@ -86,6 +88,8 @@ void DedicatedWorkerMessagingProxy::StartWorkerGlobalScope( ...@@ -86,6 +88,8 @@ void DedicatedWorkerMessagingProxy::StartWorkerGlobalScope(
// "module: Fetch a module worker script graph given url, outside settings, // "module: Fetch a module worker script graph given url, outside settings,
// destination, the value of the credentials member of options, and inside // destination, the value of the credentials member of options, and inside
// settings." // settings."
UseCounter::Count(GetExecutionContext(),
WebFeature::kModuleDedicatedWorker);
network::mojom::CredentialsMode credentials_mode; network::mojom::CredentialsMode credentials_mode;
bool result = Request::ParseCredentialsMode(options->credentials(), bool result = Request::ParseCredentialsMode(options->credentials(),
&credentials_mode); &credentials_mode);
......
i<!DOCTYPE html>
<title>Dedicated Worker: UseCounter</title>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<body>
</body>
<script>
// From web_feature.mojom
const kFeatureWorkerStart = 4;
const kFeatureNestedDedicatedWorker = 2499;
const kFeatureClassicDedicatedWorker = 3084;
const kFeatureModuleDedicatedWorker = 3085;
function isUseCounted(feature) {
return internals.isUseCounted(document, feature);
}
function observeUseCounter(feature) {
return internals.observeUseCounter(document, feature);
}
promise_test(async t => {
// Start a dedicated worker using classic scripts.
assert_false(isUseCounted(kFeatureWorkerStart));
assert_false(isUseCounted(kFeatureClassicDedicatedWorker));
const classic_worker = new Worker('resources/empty.js');
await Promise.all([
observeUseCounter(kFeatureWorkerStart),
observeUseCounter(kFeatureClassicDedicatedWorker)
]);
assert_true(isUseCounted(kFeatureWorkerStart));
assert_true(isUseCounted(kFeatureClassicDedicatedWorker));
// Start a dedicated worker using module scripts.
assert_false(isUseCounted(kFeatureModuleDedicatedWorker));
const module_worker = new Worker('resources/empty.js', { type: 'module' });
await observeUseCounter(kFeatureModuleDedicatedWorker);
assert_true(isUseCounted(kFeatureModuleDedicatedWorker));
// Start a nested dedicated worker.
assert_false(isUseCounted(kFeatureNestedDedicatedWorker));
const nested_worker = new Worker('resources/nested-worker.js');
await observeUseCounter(kFeatureNestedDedicatedWorker);
assert_true(isUseCounted(kFeatureNestedDedicatedWorker));
}, 'UseCounter on dedicated workers');
</script>
</html>
...@@ -25404,6 +25404,8 @@ Called by update_net_error_codes.py.--> ...@@ -25404,6 +25404,8 @@ Called by update_net_error_codes.py.-->
<int value="3081" label="HasGlyphRelativeUnits"/> <int value="3081" label="HasGlyphRelativeUnits"/>
<int value="3082" label="CountQueuingStrategyConstructor"/> <int value="3082" label="CountQueuingStrategyConstructor"/>
<int value="3083" label="ByteLengthQueuingStrategyConstructor"/> <int value="3083" label="ByteLengthQueuingStrategyConstructor"/>
<int value="3084" label="ClassicDedicatedWorker"/>
<int value="3085" label="ModuleDedicatedWorker"/>
</enum> </enum>
<enum name="FeaturePolicyAllowlistType"> <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