Commit 762a427c authored by Austin Tankiang's avatar Austin Tankiang Committed by Commit Bot

Add an InterfaceInvalidator to ExecutionContexts

This allows the lifetime of WeakInterfacePtrs to be tied to an
ExecutionContext, as now the interface can be tied to an invalidator whose
lifetime is bound to an ExecutionContext.

Bug: 800641
Change-Id: I0c922c90a89108f56c179b74170a8e0e2a5f666f
Reviewed-on: https://chromium-review.googlesource.com/872470
Commit-Queue: Austin Tankiang <austinct@google.com>
Reviewed-by: default avatarSam McNally <sammc@chromium.org>
Reviewed-by: default avatarNoel Gordon <noel@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#532310}
parent 41d50fb4
...@@ -945,6 +945,27 @@ TEST_F(DocumentTest, ViewportPropagationNoRecalc) { ...@@ -945,6 +945,27 @@ TEST_F(DocumentTest, ViewportPropagationNoRecalc) {
EXPECT_EQ(1, new_element_count - old_element_count); EXPECT_EQ(1, new_element_count - old_element_count);
} }
class InvalidatorObserver : public InterfaceInvalidator::Observer {
public:
void OnInvalidate() { ++invalidate_called_counter_; }
int CountInvalidateCalled() const { return invalidate_called_counter_; }
private:
int invalidate_called_counter_ = 0;
};
TEST_F(DocumentTest, InterfaceInvalidatorDestruction) {
InvalidatorObserver obs;
InterfaceInvalidator* invalidator = GetDocument().GetInterfaceInvalidator();
invalidator->AddObserver(&obs);
EXPECT_EQ(obs.CountInvalidateCalled(), 0);
GetDocument().Shutdown();
EXPECT_FALSE(GetDocument().GetInterfaceInvalidator());
EXPECT_EQ(1, obs.CountInvalidateCalled());
}
typedef bool TestParamRootLayerScrolling; typedef bool TestParamRootLayerScrolling;
class ParameterizedDocumentTest class ParameterizedDocumentTest
: public ::testing::WithParamInterface<TestParamRootLayerScrolling>, : public ::testing::WithParamInterface<TestParamRootLayerScrolling>,
......
...@@ -51,7 +51,8 @@ ExecutionContext::ExecutionContext() ...@@ -51,7 +51,8 @@ ExecutionContext::ExecutionContext()
is_context_paused_(false), is_context_paused_(false),
is_context_destroyed_(false), is_context_destroyed_(false),
window_interaction_tokens_(0), window_interaction_tokens_(0),
referrer_policy_(kReferrerPolicyDefault) {} referrer_policy_(kReferrerPolicyDefault),
invalidator_(std::make_unique<InterfaceInvalidator>()) {}
ExecutionContext::~ExecutionContext() = default; ExecutionContext::~ExecutionContext() = default;
...@@ -87,6 +88,7 @@ void ExecutionContext::UnpausePausableObjects() { ...@@ -87,6 +88,7 @@ void ExecutionContext::UnpausePausableObjects() {
void ExecutionContext::NotifyContextDestroyed() { void ExecutionContext::NotifyContextDestroyed() {
is_context_destroyed_ = true; is_context_destroyed_ = true;
invalidator_.reset();
ContextLifecycleNotifier::NotifyContextDestroyed(); ContextLifecycleNotifier::NotifyContextDestroyed();
} }
......
...@@ -55,6 +55,7 @@ class DOMTimerCoordinator; ...@@ -55,6 +55,7 @@ class DOMTimerCoordinator;
class ErrorEvent; class ErrorEvent;
class EventQueue; class EventQueue;
class EventTarget; class EventTarget;
class InterfaceInvalidator;
class LocalDOMWindow; class LocalDOMWindow;
class PausableObject; class PausableObject;
class PublicURLManager; class PublicURLManager;
...@@ -205,6 +206,8 @@ class CORE_EXPORT ExecutionContext : public ContextLifecycleNotifier, ...@@ -205,6 +206,8 @@ class CORE_EXPORT ExecutionContext : public ContextLifecycleNotifier,
virtual scoped_refptr<WebTaskRunner> GetTaskRunner(TaskType) = 0; virtual scoped_refptr<WebTaskRunner> GetTaskRunner(TaskType) = 0;
InterfaceInvalidator* GetInterfaceInvalidator() { return invalidator_.get(); }
protected: protected:
ExecutionContext(); ExecutionContext();
virtual ~ExecutionContext(); virtual ~ExecutionContext();
...@@ -229,6 +232,9 @@ class CORE_EXPORT ExecutionContext : public ContextLifecycleNotifier, ...@@ -229,6 +232,9 @@ class CORE_EXPORT ExecutionContext : public ContextLifecycleNotifier,
int window_interaction_tokens_; int window_interaction_tokens_;
ReferrerPolicy referrer_policy_; ReferrerPolicy referrer_policy_;
std::unique_ptr<InterfaceInvalidator> invalidator_;
DISALLOW_COPY_AND_ASSIGN(ExecutionContext); DISALLOW_COPY_AND_ASSIGN(ExecutionContext);
}; };
......
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