Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(162)

Unified Diff: third_party/WebKit/Source/core/dom/Document.cpp

Issue 2719873002: Don't attach NetworkStateObserver until Document is initialized/attached (Closed)
Patch Set: comment Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/dom/Document.cpp
diff --git a/third_party/WebKit/Source/core/dom/Document.cpp b/third_party/WebKit/Source/core/dom/Document.cpp
index d8fc1a43d6f1d65b869cedef6bcf79b60cd5eb2d..99d4e4828b7c6bf58fb35b3ea00796a49df14713 100644
--- a/third_party/WebKit/Source/core/dom/Document.cpp
+++ b/third_party/WebKit/Source/core/dom/Document.cpp
@@ -410,7 +410,6 @@ class Document::NetworkStateObserver final
public NetworkStateNotifier::NetworkStateObserver,
public ContextLifecycleObserver {
USING_GARBAGE_COLLECTED_MIXIN(Document::NetworkStateObserver);
- EAGERLY_FINALIZE();
public:
explicit NetworkStateObserver(Document& document)
@@ -420,9 +419,6 @@ class Document::NetworkStateObserver final
TaskRunnerHelper::get(TaskType::Networking, getExecutionContext()));
}
- // We eagerly finalize, so it's safe to touch getExecutionContext() here.
- ~NetworkStateObserver() { unregisterAsObserver(getExecutionContext()); }
-
void onLineStateChange(bool onLine) override {
AtomicString eventName =
onLine ? EventTypeNames::online : EventTypeNames::offline;
@@ -438,8 +434,7 @@ class Document::NetworkStateObserver final
}
void unregisterAsObserver(ExecutionContext* context) {
- if (!context)
- return;
+ DCHECK(context);
networkStateNotifier().removeOnLineObserver(
this, TaskRunnerHelper::get(TaskType::Networking, context));
}
@@ -539,8 +534,7 @@ Document::Document(const DocumentInit& initializer,
m_nodeCount(0),
m_wouldLoadReason(Created),
m_passwordCount(0),
- m_engagementLevel(mojom::blink::EngagementLevel::NONE),
- m_networkStateObserver(new NetworkStateObserver(*this)) {
+ m_engagementLevel(mojom::blink::EngagementLevel::NONE) {
if (m_frame) {
DCHECK(m_frame->page());
provideContextFeaturesToDocumentFrom(*this, *m_frame->page());
@@ -2450,6 +2444,11 @@ void Document::initialize() {
if (view())
view()->didAttachDocument();
+
+ // Observer(s) should not be initialized until the document is initialized /
+ // attached to a frame. Otherwise ContextLifecycleObserver::contextDestroyed
+ // wouldn't be fired.
+ m_networkStateObserver = new NetworkStateObserver(*this);
}
void Document::shutdown() {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698