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

Side by Side Diff: third_party/WebKit/Source/core/dom/Document.cpp

Issue 2714643008: NetworkStateNotifier: also remove NetworkStateObserver in finalizer too (Closed)
Patch Set: add comment + another method Created 3 years, 9 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 EAGERLY_FINALIZE();
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
423 // We eagerly finalize, so it's safe to touch getExecutionContext() here.
424 ~NetworkStateObserver() { unregisterAsObserver(getExecutionContext()); }
425
422 void onLineStateChange(bool onLine) override { 426 void onLineStateChange(bool onLine) override {
423 AtomicString eventName = 427 AtomicString eventName =
424 onLine ? EventTypeNames::online : EventTypeNames::offline; 428 onLine ? EventTypeNames::online : EventTypeNames::offline;
425 Document* document = toDocument(getExecutionContext()); 429 Document* document = toDocument(getExecutionContext());
426 if (!document->domWindow()) 430 if (!document->domWindow())
427 return; 431 return;
428 document->domWindow()->dispatchEvent(Event::create(eventName)); 432 document->domWindow()->dispatchEvent(Event::create(eventName));
429 InspectorInstrumentation::networkStateChanged(document->frame(), onLine); 433 InspectorInstrumentation::networkStateChanged(document->frame(), onLine);
430 } 434 }
431 435
432 void contextDestroyed(ExecutionContext* context) override { 436 void contextDestroyed(ExecutionContext* context) override {
437 unregisterAsObserver(context);
438 }
439
440 void unregisterAsObserver(ExecutionContext* context) {
441 if (!context)
442 return;
433 networkStateNotifier().removeOnLineObserver( 443 networkStateNotifier().removeOnLineObserver(
434 this, TaskRunnerHelper::get(TaskType::Networking, context)); 444 this, TaskRunnerHelper::get(TaskType::Networking, context));
435 } 445 }
436 446
437 DEFINE_INLINE_VIRTUAL_TRACE() { ContextLifecycleObserver::trace(visitor); } 447 DEFINE_INLINE_VIRTUAL_TRACE() { ContextLifecycleObserver::trace(visitor); }
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),
(...skipping 6209 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
OLDNEW
« 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