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

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

Issue 1858583002: Simplify LifecycleNotifier and Observer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more removals Created 4 years, 8 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 14 matching lines...) Expand all
25 25
26 #include "core/frame/DOMWindowLifecycleNotifier.h" 26 #include "core/frame/DOMWindowLifecycleNotifier.h"
27 27
28 #include "core/frame/DOMWindowLifecycleObserver.h" 28 #include "core/frame/DOMWindowLifecycleObserver.h"
29 29
30 namespace blink { 30 namespace blink {
31 31
32 void DOMWindowLifecycleNotifier::notifyAddEventListener(LocalDOMWindow* window, const AtomicString& eventType) 32 void DOMWindowLifecycleNotifier::notifyAddEventListener(LocalDOMWindow* window, const AtomicString& eventType)
33 { 33 {
34 TemporaryChange<IterationType> scope(m_iterating, IteratingOverAll); 34 TemporaryChange<IterationType> scope(m_iterating, IteratingOverAll);
35 #if !ENABLE(OILPAN)
36 // Notifications perform unknown amounts of heap allocations,
37 // which might trigger (conservative) GCs. This will flush out
38 // dead observers, causing the _non-heap_ set be updated. Snapshot
39 // the observers and explicitly check if they're still alive before
40 // notifying.
41 Vector<RawPtr<DOMWindowLifecycleObserver>> snapshotOfObservers;
42 copyToVector(m_observers, snapshotOfObservers);
43 for (DOMWindowLifecycleObserver* observer : snapshotOfObservers) {
44 if (m_observers.contains(observer))
45 observer->didAddEventListener(window, eventType);
46 }
47 #else
48 for (DOMWindowLifecycleObserver* observer : m_observers) 35 for (DOMWindowLifecycleObserver* observer : m_observers)
49 observer->didAddEventListener(window, eventType); 36 observer->didAddEventListener(window, eventType);
50 #endif
51 } 37 }
52 38
53 void DOMWindowLifecycleNotifier::notifyRemoveEventListener(LocalDOMWindow* windo w, const AtomicString& eventType) 39 void DOMWindowLifecycleNotifier::notifyRemoveEventListener(LocalDOMWindow* windo w, const AtomicString& eventType)
54 { 40 {
55 TemporaryChange<IterationType> scope(m_iterating, IteratingOverAll); 41 TemporaryChange<IterationType> scope(m_iterating, IteratingOverAll);
56 #if !ENABLE(OILPAN)
57 // Notifications perform unknown amounts of heap allocations,
58 // which might trigger (conservative) GCs. This will flush out
59 // dead observers, causing the _non-heap_ set be updated. Snapshot
60 // the observers and explicitly check if they're still alive before
61 // notifying.
62 Vector<RawPtr<DOMWindowLifecycleObserver>> snapshotOfObservers;
63 copyToVector(m_observers, snapshotOfObservers);
64 for (DOMWindowLifecycleObserver* observer : snapshotOfObservers) {
65 if (m_observers.contains(observer))
66 observer->didRemoveEventListener(window, eventType);
67 }
68 #else
69 for (DOMWindowLifecycleObserver* observer : m_observers) 42 for (DOMWindowLifecycleObserver* observer : m_observers)
70 observer->didRemoveEventListener(window, eventType); 43 observer->didRemoveEventListener(window, eventType);
71 #endif
72 } 44 }
73 45
74 void DOMWindowLifecycleNotifier::notifyRemoveAllEventListeners(LocalDOMWindow* w indow) 46 void DOMWindowLifecycleNotifier::notifyRemoveAllEventListeners(LocalDOMWindow* w indow)
75 { 47 {
76 TemporaryChange<IterationType> scope(m_iterating, IteratingOverAll); 48 TemporaryChange<IterationType> scope(m_iterating, IteratingOverAll);
77 #if !ENABLE(OILPAN)
78 // Notifications perform unknown amounts of heap allocations,
79 // which might trigger (conservative) GCs. This will flush out
80 // dead observers, causing the _non-heap_ set be updated. Snapshot
81 // the observers and explicitly check if they're still alive before
82 // notifying.
83 Vector<RawPtr<DOMWindowLifecycleObserver>> snapshotOfObservers;
84 copyToVector(m_observers, snapshotOfObservers);
85 for (DOMWindowLifecycleObserver* observer : snapshotOfObservers) {
86 if (m_observers.contains(observer))
87 observer->didRemoveAllEventListeners(window);
88 }
89 #else
90 for (DOMWindowLifecycleObserver* observer : m_observers) 49 for (DOMWindowLifecycleObserver* observer : m_observers)
91 observer->didRemoveAllEventListeners(window); 50 observer->didRemoveAllEventListeners(window);
92 #endif
93 } 51 }
94 52
95 } // namespace blink 53 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698