Skip to content

Commit

Permalink
Use HeapObserverList for ContextLifecycleObserver
Browse files Browse the repository at this point in the history
Use the HeapObserverList that was added in crrev.com/c/2054687 for
ContextLifecycleObserver.

Bug: 1052319
Change-Id: If501c2f969add4485675eb9c8d6a1bbe5cd11491
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2059349
Commit-Queue: Keishi Hattori <keishi@chromium.org>
Reviewed-by: Kentaro Hara <haraken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#741782}
  • Loading branch information
Keishi Hattori authored and Commit Bot committed Feb 16, 2020
1 parent 82f699d commit b0a2875
Show file tree
Hide file tree
Showing 255 changed files with 419 additions and 464 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class CORE_EXPORT ScriptPromiseResolver
}

// ContextLifecycleObserver implementation.
void ContextDestroyed(ExecutionContext*) override { Detach(); }
void ContextDestroyed() override { Detach(); }

// Calling this function makes the resolver release its internal resources.
// That means the associated promise will never be resolved or rejected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ v8::MaybeLocal<v8::Value> V8ScriptRunner::RunCompiledScript(
if (GetMicrotasksScopeDepth(isolate, microtask_queue) > kMaxRecursionDepth)
return ThrowStackOverflowExceptionIfNeeded(isolate, microtask_queue);

CHECK(!context->IsIteratingOverObservers());
CHECK(!context->ContextLifecycleObserverList().IsIteratingOverObservers());

// Run the script and keep track of the current recursion depth.
v8::MaybeLocal<v8::Value> result;
Expand Down Expand Up @@ -413,7 +413,7 @@ v8::MaybeLocal<v8::Value> V8ScriptRunner::CallAsConstructor(
if (depth >= kMaxRecursionDepth)
return ThrowStackOverflowExceptionIfNeeded(isolate, microtask_queue);

CHECK(!context->IsIteratingOverObservers());
CHECK(!context->ContextLifecycleObserverList().IsIteratingOverObservers());

if (ScriptForbiddenScope::IsScriptForbidden()) {
ThrowScriptForbiddenException(isolate);
Expand Down Expand Up @@ -466,7 +466,7 @@ v8::MaybeLocal<v8::Value> V8ScriptRunner::CallFunction(
if (depth >= kMaxRecursionDepth)
return ThrowStackOverflowExceptionIfNeeded(isolate, microtask_queue);

CHECK(!context->IsIteratingOverObservers());
CHECK(!context->ContextLifecycleObserverList().IsIteratingOverObservers());

if (ScriptForbiddenScope::IsScriptForbidden()) {
ThrowScriptForbiddenException(isolate);
Expand Down
2 changes: 1 addition & 1 deletion third_party/blink/renderer/core/animation/animation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1398,7 +1398,7 @@ bool Animation::HasPendingActivity() const {
(!finished_ && HasEventListeners(event_type_names::kFinish));
}

void Animation::ContextDestroyed(ExecutionContext*) {
void Animation::ContextDestroyed() {
finished_ = true;
pending_finished_event_ = nullptr;
pending_cancelled_event_ = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion third_party/blink/renderer/core/animation/animation.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class CORE_EXPORT Animation : public EventTargetWithInlineData,
const AtomicString& InterfaceName() const override;
ExecutionContext* GetExecutionContext() const override;
bool HasPendingActivity() const final;
void ContextDestroyed(ExecutionContext*) override;
void ContextDestroyed() override;

double playbackRate() const;
void setPlaybackRate(double, ExceptionState& = ASSERT_NO_EXCEPTION);
Expand Down
2 changes: 1 addition & 1 deletion third_party/blink/renderer/core/css/media_query_list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ bool MediaQueryList::HasPendingActivity() const {
(listeners_.size() || HasEventListeners(event_type_names::kChange));
}

void MediaQueryList::ContextDestroyed(ExecutionContext*) {
void MediaQueryList::ContextDestroyed() {
listeners_.clear();
RemoveAllEventListeners();
}
Expand Down
2 changes: 1 addition & 1 deletion third_party/blink/renderer/core/css/media_query_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class CORE_EXPORT MediaQueryList final
bool HasPendingActivity() const final;

// From ContextLifecycleObserver
void ContextDestroyed(ExecutionContext*) override;
void ContextDestroyed() override;

const AtomicString& InterfaceName() const override;
ExecutionContext* GetExecutionContext() const override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ TEST(MediaQueryListTest, CrashInStop) {
MakeGarbageCollected<MediaQueryMatcher>(*document),
MediaQuerySet::Create());
list->AddListener(MakeGarbageCollected<TestListener>());
list->ContextDestroyed(document->ToExecutionContext());
list->ContextDestroyed();
// This test passes if it's not crashed.
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ void DisplayLockContext::Dispose() {
state_ = kUnlocked;
}

void DisplayLockContext::ContextDestroyed(ExecutionContext*) {
void DisplayLockContext::ContextDestroyed() {
FinishUpdateResolver(kReject, rejection_names::kExecutionContextDestroyed);
state_ = kUnlocked;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class CORE_EXPORT DisplayLockContext final
void Dispose();

// ContextLifecycleObserver overrides.
void ContextDestroyed(ExecutionContext*) override;
void ContextDestroyed() override;

// Set which reasons activate, as a mask of DisplayLockActivationReason enums.
void SetActivatable(uint16_t activatable_mask);
Expand Down
4 changes: 2 additions & 2 deletions third_party/blink/renderer/core/dom/document.cc
Original file line number Diff line number Diff line change
Expand Up @@ -597,8 +597,8 @@ class Document::NetworkStateObserver final
probe::NetworkStateChanged(document->GetFrame(), on_line);
}

void ContextDestroyed(ExecutionContext* context) override {
UnregisterAsObserver(context);
void ContextDestroyed() override {
UnregisterAsObserver(GetExecutionContext());
}

void UnregisterAsObserver(ExecutionContext* context) {
Expand Down
4 changes: 2 additions & 2 deletions third_party/blink/renderer/core/dom/events/event_queue.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ void EventQueue::DispatchEvent(Event* event) {
target->DispatchEvent(*event);
}

void EventQueue::ContextDestroyed(ExecutionContext* context) {
Close(context);
void EventQueue::ContextDestroyed() {
Close(GetExecutionContext());
}

void EventQueue::Close(ExecutionContext* context) {
Expand Down
2 changes: 1 addition & 1 deletion third_party/blink/renderer/core/dom/events/event_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class CORE_EXPORT EventQueue final : public GarbageCollected<EventQueue>,
bool RemoveEvent(Event&);
void DispatchEvent(Event*);

void ContextDestroyed(ExecutionContext*) override;
void ContextDestroyed() override;
void Close(ExecutionContext*);
void DoCancelAllEvents(ExecutionContext*);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include "third_party/blink/renderer/core/dom/events/event_target_impl.h"

#include "third_party/blink/renderer/core/execution_context/execution_context.h"

namespace blink {

const AtomicString& EventTargetImpl::InterfaceName() const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ void ScriptedIdleTaskController::RunCallback(
idle_tasks_.erase(id);
}

void ScriptedIdleTaskController::ContextDestroyed(ExecutionContext*) {
void ScriptedIdleTaskController::ContextDestroyed() {
idle_tasks_.clear();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class CORE_EXPORT ScriptedIdleTaskController
void CancelCallback(CallbackId);

// ContextLifecycleStateObserver interface.
void ContextDestroyed(ExecutionContext*) override;
void ContextDestroyed() override;
void ContextLifecycleStateChanged(mojom::FrameLifecycleState) override;

void CallbackFired(CallbackId,
Expand Down
2 changes: 0 additions & 2 deletions third_party/blink/renderer/core/execution_context/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ blink_core_sources("execution_context") {
"agent.h",
"agent_metrics_collector.cc",
"agent_metrics_collector.h",
"context_lifecycle_notifier.cc",
"context_lifecycle_notifier.h",
"context_lifecycle_observer.cc",
"context_lifecycle_observer.h",
"context_lifecycle_state_observer.cc",
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,44 @@ void ContextClient::Trace(Visitor* visitor) {

ContextLifecycleObserver::ContextLifecycleObserver(Document* document,
Type type)
: LifecycleObserver(document ? document->ToExecutionContext() : nullptr),
observer_type_(type) {}
: ContextLifecycleObserver(
document ? document->ToExecutionContext() : nullptr,
type) {}

ContextLifecycleObserver::ContextLifecycleObserver(
ExecutionContext* execution_context,
Type type)
: observer_type_(type) {
SetExecutionContext(execution_context);
}

void ContextLifecycleObserver::ObserverListWillBeCleared() {
execution_context_ = nullptr;
}

void ContextLifecycleObserver::SetExecutionContext(
ExecutionContext* execution_context) {
if (execution_context == execution_context_)
return;

if (execution_context_)
execution_context_->ContextLifecycleObserverList().RemoveObserver(this);

execution_context_ = execution_context;

if (execution_context_)
execution_context_->ContextLifecycleObserverList().AddObserver(this);
}

LocalFrame* ContextLifecycleObserver::GetFrame() const {
auto* document = Document::DynamicFrom(GetExecutionContext());
return document ? document->GetFrame() : nullptr;
}

void ContextLifecycleObserver::Trace(Visitor* visitor) {
visitor->Trace(execution_context_);
}

DOMWindowClient::DOMWindowClient(LocalDOMWindow* window)
: dom_window_(window) {}

Expand Down
Loading

0 comments on commit b0a2875

Please sign in to comment.