Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
| 4 * (C) 2001 Dirk Mueller (mueller@kde.org) | 4 * (C) 2001 Dirk Mueller (mueller@kde.org) |
| 5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org) | 5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org) |
| 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All | 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All |
| 7 * rights reserved. | 7 * rights reserved. |
| 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. | 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. |
| 9 * (http://www.torchmobile.com/) | 9 * (http://www.torchmobile.com/) |
| 10 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved. | 10 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved. |
| (...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 399 } | 399 } |
| 400 | 400 |
| 401 static void recordLoadReasonToHistogram(WouldLoadReason reason) { | 401 static void recordLoadReasonToHistogram(WouldLoadReason reason) { |
| 402 DEFINE_STATIC_LOCAL( | 402 DEFINE_STATIC_LOCAL( |
| 403 EnumerationHistogram, unseenFrameHistogram, | 403 EnumerationHistogram, unseenFrameHistogram, |
| 404 ("Navigation.DeferredDocumentLoading.StatesV3", WouldLoadReasonEnd)); | 404 ("Navigation.DeferredDocumentLoading.StatesV3", WouldLoadReasonEnd)); |
| 405 unseenFrameHistogram.count(reason); | 405 unseenFrameHistogram.count(reason); |
| 406 } | 406 } |
| 407 | 407 |
| 408 class Document::NetworkStateObserver final | 408 class Document::NetworkStateObserver final |
| 409 : public GarbageCollected<Document::NetworkStateObserver>, | 409 : public GarbageCollectedFinalized<Document::NetworkStateObserver>, |
| 410 public NetworkStateNotifier::NetworkStateObserver, | 410 public NetworkStateNotifier::NetworkStateObserver, |
| 411 public ContextLifecycleObserver { | 411 public ContextLifecycleObserver { |
| 412 USING_GARBAGE_COLLECTED_MIXIN(Document::NetworkStateObserver); | 412 USING_GARBAGE_COLLECTED_MIXIN(Document::NetworkStateObserver); |
| 413 USING_PRE_FINALIZER(Document::NetworkStateObserver, dispose); | |
|
jkarlin
2017/02/24 13:13:51
Why PRE_FINALIZER instead of normal destructor?
kinuko
2017/02/24 13:56:25
Removing observer touches on-heap object, so I thi
jkarlin
2017/02/24 14:20:06
What object does it touch that's on the oilpan hea
kinuko
2017/02/24 14:43:16
m_executionContext in contextLifecycleObserver, an
jkarlin
2017/02/24 15:31:27
Ah yes, thanks!
| |
| 413 | 414 |
| 414 public: | 415 public: |
| 415 explicit NetworkStateObserver(Document& document) | 416 explicit NetworkStateObserver(Document& document) |
| 416 : ContextLifecycleObserver(&document) { | 417 : ContextLifecycleObserver(&document) { |
| 417 networkStateNotifier().addOnLineObserver( | 418 networkStateNotifier().addOnLineObserver( |
| 418 this, | 419 this, |
| 419 TaskRunnerHelper::get(TaskType::Networking, getExecutionContext())); | 420 TaskRunnerHelper::get(TaskType::Networking, getExecutionContext())); |
| 420 } | 421 } |
| 421 | 422 |
| 422 void onLineStateChange(bool onLine) override { | 423 void onLineStateChange(bool onLine) override { |
| 423 AtomicString eventName = | 424 AtomicString eventName = |
| 424 onLine ? EventTypeNames::online : EventTypeNames::offline; | 425 onLine ? EventTypeNames::online : EventTypeNames::offline; |
| 425 Document* document = toDocument(getExecutionContext()); | 426 Document* document = toDocument(getExecutionContext()); |
| 426 if (!document->domWindow()) | 427 if (!document->domWindow()) |
| 427 return; | 428 return; |
| 428 document->domWindow()->dispatchEvent(Event::create(eventName)); | 429 document->domWindow()->dispatchEvent(Event::create(eventName)); |
| 429 InspectorInstrumentation::networkStateChanged(document->frame(), onLine); | 430 InspectorInstrumentation::networkStateChanged(document->frame(), onLine); |
| 430 } | 431 } |
| 431 | 432 |
| 432 void contextDestroyed(ExecutionContext* context) override { | 433 void contextDestroyed(ExecutionContext* context) override { dispose(); } |
| 434 | |
| 435 void dispose() { | |
| 436 if (detached) | |
| 437 return; | |
| 438 detached = true; | |
| 433 networkStateNotifier().removeOnLineObserver( | 439 networkStateNotifier().removeOnLineObserver( |
| 434 this, TaskRunnerHelper::get(TaskType::Networking, context)); | 440 this, |
| 441 TaskRunnerHelper::get(TaskType::Networking, getExecutionContext())); | |
| 435 } | 442 } |
| 436 | 443 |
| 437 DEFINE_INLINE_VIRTUAL_TRACE() { ContextLifecycleObserver::trace(visitor); } | 444 DEFINE_INLINE_VIRTUAL_TRACE() { ContextLifecycleObserver::trace(visitor); } |
| 445 | |
| 446 private: | |
| 447 bool detached = false; | |
|
jkarlin
2017/02/24 13:13:51
Forgot the m_.
nit: Perhaps m_isObserving?
kinuko
2017/02/24 13:56:25
Removed this flag in favor of checking getExecutio
| |
| 438 }; | 448 }; |
| 439 | 449 |
| 440 Document::Document(const DocumentInit& initializer, | 450 Document::Document(const DocumentInit& initializer, |
| 441 DocumentClassFlags documentClasses) | 451 DocumentClassFlags documentClasses) |
| 442 : ContainerNode(0, CreateDocument), | 452 : ContainerNode(0, CreateDocument), |
| 443 TreeScope(*this), | 453 TreeScope(*this), |
| 444 m_hasNodesWithPlaceholderStyle(false), | 454 m_hasNodesWithPlaceholderStyle(false), |
| 445 m_evaluateMediaQueriesOnStyleRecalc(false), | 455 m_evaluateMediaQueriesOnStyleRecalc(false), |
| 446 m_pendingSheetLayout(NoLayoutWithPendingSheets), | 456 m_pendingSheetLayout(NoLayoutWithPendingSheets), |
| 447 m_frame(initializer.frame()), | 457 m_frame(initializer.frame()), |
| (...skipping 6204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6652 } | 6662 } |
| 6653 | 6663 |
| 6654 void showLiveDocumentInstances() { | 6664 void showLiveDocumentInstances() { |
| 6655 WeakDocumentSet& set = liveDocumentSet(); | 6665 WeakDocumentSet& set = liveDocumentSet(); |
| 6656 fprintf(stderr, "There are %u documents currently alive:\n", set.size()); | 6666 fprintf(stderr, "There are %u documents currently alive:\n", set.size()); |
| 6657 for (blink::Document* document : set) | 6667 for (blink::Document* document : set) |
| 6658 fprintf(stderr, "- Document %p URL: %s\n", document, | 6668 fprintf(stderr, "- Document %p URL: %s\n", document, |
| 6659 document->url().getString().utf8().data()); | 6669 document->url().getString().utf8().data()); |
| 6660 } | 6670 } |
| 6661 #endif | 6671 #endif |
| OLD | NEW |