Skip to content

Commit

Permalink
[M100 Merge] Worker: Don't call WorkerReportingProxy::CountFeature() …
Browse files Browse the repository at this point in the history
…during context destruction

This CL avoids calling WorkerReportingProxy::CountFeature() during
context destruction.

Also, this makes sure that ExecutionContext::NotifyContextDestroyed() is
called for main thread worklets (PaintWorklet and LayoutWorklet). Before
this change, it was not called for them.

(cherry picked from commit e871285)

Bug: 1298450
Change-Id: If4d7ed2c45fe3a214380ade91b7a4f4f098d214e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3507933
Reviewed-by: Kenichi Ishibashi <bashi@chromium.org>
Reviewed-by: Kentaro Hara <haraken@chromium.org>
Commit-Queue: Hiroki Nakagawa <nhiroki@chromium.org>
Cr-Commit-Position: refs/branch-heads/4896@{#360}
Cr-Branched-From: 1f63ff4-refs/heads/main@{#972766}
  • Loading branch information
nhiroki authored and Chromium LUCI CQ committed Mar 8, 2022
1 parent ef7d1d8 commit b8a64c8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
Expand Up @@ -59,6 +59,8 @@ void LayoutWorkletGlobalScope::Dispose() {
ScriptController()->GetScriptState());

WorkletGlobalScope::Dispose();

NotifyContextDestroyed();
}

// https://drafts.css-houdini.org/css-layout-api/#dom-layoutworkletglobalscope-registerlayout
Expand Down
Expand Up @@ -257,6 +257,14 @@ bool WorkerOrWorkletGlobalScope::HasPendingActivity() const {

void WorkerOrWorkletGlobalScope::CountUse(WebFeature feature) {
DCHECK(IsContextThread());

// `reporting_proxy_` should outlive `this` but there seems a situation where
// the assumption is broken. Don't count features while the context is
// destroyed.
// TODO(https://crbug.com/1298450): Fix the lifetime of WorkerReportingProxy.
if (IsContextDestroyed())
return;

DCHECK_NE(WebFeature::kOBSOLETE_PageDestruction, feature);
DCHECK_GT(WebFeature::kNumberOfFeatures, feature);
if (used_features_[static_cast<size_t>(feature)])
Expand Down
Expand Up @@ -147,6 +147,12 @@ void PaintWorkletGlobalScope::Dispose() {
ScriptController()->GetScriptState());
}
WorkletGlobalScope::Dispose();

if (WTF::IsMainThread()) {
// For off-the-main-thread paint worklet, this will be called in
// WorkerThread::PrepareForShutdownOnWorkerThread().
NotifyContextDestroyed();
}
}

void PaintWorkletGlobalScope::registerPaint(const ScriptState* script_state,
Expand Down

0 comments on commit b8a64c8

Please sign in to comment.