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

Side by Side Diff: Source/platform/LifecycleNotifier.h

Issue 1006253002: Oilpan: have LifetimeNotifier<T> track its observers weakly. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: rebased Created 5 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 | Annotate | Revision Log
« no previous file with comments | « Source/modules/webmidi/MIDIAccessInitializer.cpp ('k') | Source/platform/LifecycleObserver.h » ('j') | 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) 2008 Apple Inc. All Rights Reserved. 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved.
3 * Copyright (C) 2013 Google Inc. All Rights Reserved. 3 * Copyright (C) 2013 Google Inc. All Rights Reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 30 matching lines...) Expand all
41 void addObserver(Observer*); 41 void addObserver(Observer*);
42 void removeObserver(Observer*); 42 void removeObserver(Observer*);
43 43
44 // notifyContextDestroyed() should be explicitly dispatched from an 44 // notifyContextDestroyed() should be explicitly dispatched from an
45 // observed context to notify observers that contextDestroyed(). 45 // observed context to notify observers that contextDestroyed().
46 // 46 //
47 // When contextDestroyed() is called, the observer's lifecycleContext() 47 // When contextDestroyed() is called, the observer's lifecycleContext()
48 // is still valid and safe to use during the notification. 48 // is still valid and safe to use during the notification.
49 virtual void notifyContextDestroyed(); 49 virtual void notifyContextDestroyed();
50 50
51 DEFINE_INLINE_VIRTUAL_TRACE() { } 51 DEFINE_INLINE_VIRTUAL_TRACE()
52 {
53 #if ENABLE(OILPAN)
54 visitor->trace(m_observers);
55 #endif
56 }
52 57
53 bool isIteratingOverObservers() const { return m_iterating != IteratingNone; } 58 bool isIteratingOverObservers() const { return m_iterating != IteratingNone; }
54 59
55 protected: 60 protected:
56 LifecycleNotifier() 61 LifecycleNotifier()
57 : m_iterating(IteratingNone) 62 : m_iterating(IteratingNone)
58 , m_didCallContextDestroyed(false) 63 , m_didCallContextDestroyed(false)
59 { 64 {
60 } 65 }
61 66
62 enum IterationType { 67 enum IterationType {
63 IteratingNone, 68 IteratingNone,
64 IteratingOverAll, 69 IteratingOverAll,
65 IteratingOverActiveDOMObjects, 70 IteratingOverActiveDOMObjects,
66 }; 71 };
67 72
68 IterationType m_iterating; 73 IterationType m_iterating;
69 74
70 protected: 75 protected:
71 using ObserverSet = HashSet<Observer*>; 76 using ObserverSet = WillBeHeapHashSet<RawPtrWillBeWeakMember<Observer>>;
72 77
78 // FIXME: Oilpan: make LifecycleNotifier<> a GC mixin, somehow. ExecutionCon text
79 // is the problematic case, as it would then be a class with two GC mixin
80 // bases, but cannot itself derive from a GC base class also.
81 GC_PLUGIN_IGNORE("467502")
73 ObserverSet m_observers; 82 ObserverSet m_observers;
74 83
75 #if ENABLE(ASSERT) 84 #if ENABLE(ASSERT)
76 T* context() { return static_cast<T*>(this); } 85 T* context() { return static_cast<T*>(this); }
77 #endif 86 #endif
78 87
79 private: 88 private:
80 bool m_didCallContextDestroyed; 89 bool m_didCallContextDestroyed;
81 }; 90 };
82 91
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 137
129 template<typename T, typename Observer> 138 template<typename T, typename Observer>
130 inline void LifecycleNotifier<T, Observer>::removeObserver(Observer* observer) 139 inline void LifecycleNotifier<T, Observer>::removeObserver(Observer* observer)
131 { 140 {
132 m_observers.remove(observer); 141 m_observers.remove(observer);
133 } 142 }
134 143
135 } // namespace blink 144 } // namespace blink
136 145
137 #endif // LifecycleNotifier_h 146 #endif // LifecycleNotifier_h
OLDNEW
« no previous file with comments | « Source/modules/webmidi/MIDIAccessInitializer.cpp ('k') | Source/platform/LifecycleObserver.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698