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

Side by Side Diff: Source/core/frame/DOMWindowLifecycleNotifier.cpp

Issue 1214963002: Oilpan: support observer retirement during lifetime notifications. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 5 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All Rights Reserved. 2 * Copyright (C) 2013 Google Inc. All Rights Reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 16 matching lines...) Expand all
27 #include "config.h" 27 #include "config.h"
28 #include "core/frame/DOMWindowLifecycleNotifier.h" 28 #include "core/frame/DOMWindowLifecycleNotifier.h"
29 29
30 #include "core/frame/DOMWindowLifecycleObserver.h" 30 #include "core/frame/DOMWindowLifecycleObserver.h"
31 31
32 namespace blink { 32 namespace blink {
33 33
34 void DOMWindowLifecycleNotifier::notifyAddEventListener(LocalDOMWindow* window, const AtomicString& eventType) 34 void DOMWindowLifecycleNotifier::notifyAddEventListener(LocalDOMWindow* window, const AtomicString& eventType)
35 { 35 {
36 TemporaryChange<IterationType> scope(m_iterating, IteratingOverAll); 36 TemporaryChange<IterationType> scope(m_iterating, IteratingOverAll);
37 #if !ENABLE(OILPAN)
38 // Notifications perform unknown amounts of heap allocations,
39 // which might trigger (conservative) GCs. This will flush out
40 // dead observers, causing the _non-heap_ set be updated. Snapshot
41 // the observers and explicitly check if they're still alive before
42 // notifying.
43 Vector<RawPtr<DOMWindowLifecycleObserver>> snapshotOfObservers;
44 copyToVector(m_observers, snapshotOfObservers);
45 for (DOMWindowLifecycleObserver* observer : snapshotOfObservers) {
46 if (m_observers.contains(observer))
47 observer->didAddEventListener(window, eventType);
48 }
49 #else
37 for (DOMWindowLifecycleObserver* observer : m_observers) 50 for (DOMWindowLifecycleObserver* observer : m_observers)
38 observer->didAddEventListener(window, eventType); 51 observer->didAddEventListener(window, eventType);
52 #endif
39 } 53 }
40 54
41 void DOMWindowLifecycleNotifier::notifyRemoveEventListener(LocalDOMWindow* windo w, const AtomicString& eventType) 55 void DOMWindowLifecycleNotifier::notifyRemoveEventListener(LocalDOMWindow* windo w, const AtomicString& eventType)
42 { 56 {
43 TemporaryChange<IterationType> scope(m_iterating, IteratingOverAll); 57 TemporaryChange<IterationType> scope(m_iterating, IteratingOverAll);
58 #if !ENABLE(OILPAN)
59 // Notifications perform unknown amounts of heap allocations,
60 // which might trigger (conservative) GCs. This will flush out
61 // dead observers, causing the _non-heap_ set be updated. Snapshot
62 // the observers and explicitly check if they're still alive before
63 // notifying.
64 Vector<RawPtr<DOMWindowLifecycleObserver>> snapshotOfObservers;
65 copyToVector(m_observers, snapshotOfObservers);
66 for (DOMWindowLifecycleObserver* observer : snapshotOfObservers) {
67 if (m_observers.contains(observer))
68 observer->didRemoveEventListener(window, eventType);
69 }
70 #else
44 for (DOMWindowLifecycleObserver* observer : m_observers) 71 for (DOMWindowLifecycleObserver* observer : m_observers)
45 observer->didRemoveEventListener(window, eventType); 72 observer->didRemoveEventListener(window, eventType);
73 #endif
46 } 74 }
47 75
48 void DOMWindowLifecycleNotifier::notifyRemoveAllEventListeners(LocalDOMWindow* w indow) 76 void DOMWindowLifecycleNotifier::notifyRemoveAllEventListeners(LocalDOMWindow* w indow)
49 { 77 {
50 TemporaryChange<IterationType> scope(m_iterating, IteratingOverAll); 78 TemporaryChange<IterationType> scope(m_iterating, IteratingOverAll);
79 #if !ENABLE(OILPAN)
80 // Notifications perform unknown amounts of heap allocations,
81 // which might trigger (conservative) GCs. This will flush out
82 // dead observers, causing the _non-heap_ set be updated. Snapshot
83 // the observers and explicitly check if they're still alive before
84 // notifying.
85 Vector<RawPtr<DOMWindowLifecycleObserver>> snapshotOfObservers;
86 copyToVector(m_observers, snapshotOfObservers);
87 for (DOMWindowLifecycleObserver* observer : snapshotOfObservers) {
88 if (m_observers.contains(observer))
89 observer->didRemoveAllEventListeners(window);
90 }
91 #else
51 for (DOMWindowLifecycleObserver* observer : m_observers) 92 for (DOMWindowLifecycleObserver* observer : m_observers)
52 observer->didRemoveAllEventListeners(window); 93 observer->didRemoveAllEventListeners(window);
94 #endif
53 } 95 }
54 96
55 } // namespace blink 97 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/dom/DocumentLifecycleNotifier.cpp ('k') | Source/core/frame/LocalFrameLifecycleNotifier.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698