jhawkins@chromium.org | 4a31021 | 2012-01-04 04:36:57 +0900 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
mbelshe@google.com | 877d203 | 2008-10-23 08:09:21 +0900 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef BASE_OBSERVER_LIST_THREADSAFE_H_ |
| 6 | #define BASE_OBSERVER_LIST_THREADSAFE_H_ |
| 7 | |
erg@chromium.org | 6f206e7 | 2010-07-15 03:58:17 +0900 | [diff] [blame] | 8 | #include <algorithm> |
erg@chromium.org | a752852 | 2010-07-16 02:23:23 +0900 | [diff] [blame] | 9 | #include <map> |
mbelshe@google.com | 877d203 | 2008-10-23 08:09:21 +0900 | [diff] [blame] | 10 | |
| 11 | #include "base/basictypes.h" |
jhawkins@chromium.org | 22d6756 | 2011-10-13 05:26:50 +0900 | [diff] [blame] | 12 | #include "base/bind.h" |
ajwong@chromium.org | 8e2e300 | 2011-09-22 03:05:41 +0900 | [diff] [blame] | 13 | #include "base/location.h" |
mbelshe@google.com | 877d203 | 2008-10-23 08:09:21 +0900 | [diff] [blame] | 14 | #include "base/logging.h" |
levin@chromium.org | 5c52868 | 2011-03-28 10:54:15 +0900 | [diff] [blame] | 15 | #include "base/memory/ref_counted.h" |
avi@chromium.org | a043a86 | 2013-07-18 17:12:40 +0900 | [diff] [blame] | 16 | #include "base/message_loop/message_loop.h" |
mbelshe@google.com | 877d203 | 2008-10-23 08:09:21 +0900 | [diff] [blame] | 17 | #include "base/observer_list.h" |
skyostil | 97aefe1 | 2015-05-01 04:06:15 +0900 | [diff] [blame] | 18 | #include "base/single_thread_task_runner.h" |
tfarina@chromium.org | e2903a5 | 2013-03-17 14:52:05 +0900 | [diff] [blame] | 19 | #include "base/stl_util.h" |
skyostil | 97aefe1 | 2015-05-01 04:06:15 +0900 | [diff] [blame] | 20 | #include "base/thread_task_runner_handle.h" |
rsesek@chromium.org | 1aab77c | 2011-11-24 05:34:04 +0900 | [diff] [blame] | 21 | #include "base/threading/platform_thread.h" |
mbelshe@google.com | 877d203 | 2008-10-23 08:09:21 +0900 | [diff] [blame] | 22 | |
| 23 | /////////////////////////////////////////////////////////////////////////////// |
| 24 | // |
| 25 | // OVERVIEW: |
| 26 | // |
| 27 | // A thread-safe container for a list of observers. |
maruel@chromium.org | 8fe7adc | 2009-03-04 00:01:12 +0900 | [diff] [blame] | 28 | // This is similar to the observer_list (see observer_list.h), but it |
mbelshe@google.com | 877d203 | 2008-10-23 08:09:21 +0900 | [diff] [blame] | 29 | // is more robust for multi-threaded situations. |
maruel@chromium.org | 8fe7adc | 2009-03-04 00:01:12 +0900 | [diff] [blame] | 30 | // |
mbelshe@google.com | 877d203 | 2008-10-23 08:09:21 +0900 | [diff] [blame] | 31 | // The following use cases are supported: |
| 32 | // * Observers can register for notifications from any thread. |
| 33 | // Callbacks to the observer will occur on the same thread where |
| 34 | // the observer initially called AddObserver() from. |
pkasting@chromium.org | aed4e58 | 2010-06-26 06:30:38 +0900 | [diff] [blame] | 35 | // * Any thread may trigger a notification via Notify(). |
mbelshe@google.com | 877d203 | 2008-10-23 08:09:21 +0900 | [diff] [blame] | 36 | // * Observers can remove themselves from the observer list inside |
| 37 | // of a callback. |
| 38 | // * If one thread is notifying observers concurrently with an observer |
| 39 | // removing itself from the observer list, the notifications will |
| 40 | // be silently dropped. |
| 41 | // |
| 42 | // The drawback of the threadsafe observer list is that notifications |
| 43 | // are not as real-time as the non-threadsafe version of this class. |
| 44 | // Notifications will always be done via PostTask() to another thread, |
| 45 | // whereas with the non-thread-safe observer_list, notifications happen |
| 46 | // synchronously and immediately. |
| 47 | // |
| 48 | // IMPLEMENTATION NOTES |
| 49 | // The ObserverListThreadSafe maintains an ObserverList for each thread |
maruel@chromium.org | 8fe7adc | 2009-03-04 00:01:12 +0900 | [diff] [blame] | 50 | // which uses the ThreadSafeObserver. When Notifying the observers, |
mbelshe@google.com | 877d203 | 2008-10-23 08:09:21 +0900 | [diff] [blame] | 51 | // we simply call PostTask to each registered thread, and then each thread |
| 52 | // will notify its regular ObserverList. |
| 53 | // |
| 54 | /////////////////////////////////////////////////////////////////////////////// |
akalin@chromium.org | e43be3d | 2011-01-12 06:19:54 +0900 | [diff] [blame] | 55 | |
brettw | cf58460 | 2015-06-02 14:34:43 +0900 | [diff] [blame] | 56 | namespace base { |
| 57 | |
akalin@chromium.org | e43be3d | 2011-01-12 06:19:54 +0900 | [diff] [blame] | 58 | // Forward declaration for ObserverListThreadSafeTraits. |
| 59 | template <class ObserverType> |
| 60 | class ObserverListThreadSafe; |
| 61 | |
brettw | cf58460 | 2015-06-02 14:34:43 +0900 | [diff] [blame] | 62 | namespace internal { |
| 63 | |
jhawkins@chromium.org | 4a31021 | 2012-01-04 04:36:57 +0900 | [diff] [blame] | 64 | // An UnboundMethod is a wrapper for a method where the actual object is |
| 65 | // provided at Run dispatch time. |
| 66 | template <class T, class Method, class Params> |
| 67 | class UnboundMethod { |
| 68 | public: |
| 69 | UnboundMethod(Method m, const Params& p) : m_(m), p_(p) { |
| 70 | COMPILE_ASSERT( |
brettw | cf58460 | 2015-06-02 14:34:43 +0900 | [diff] [blame] | 71 | (internal::ParamsUseScopedRefptrCorrectly<Params>::value), |
jhawkins@chromium.org | 4a31021 | 2012-01-04 04:36:57 +0900 | [diff] [blame] | 72 | badunboundmethodparams); |
| 73 | } |
| 74 | void Run(T* obj) const { |
| 75 | DispatchToMethod(obj, m_, p_); |
| 76 | } |
| 77 | private: |
| 78 | Method m_; |
| 79 | Params p_; |
| 80 | }; |
| 81 | |
brettw | cf58460 | 2015-06-02 14:34:43 +0900 | [diff] [blame] | 82 | } // namespace internal |
| 83 | |
akalin@chromium.org | e43be3d | 2011-01-12 06:19:54 +0900 | [diff] [blame] | 84 | // This class is used to work around VS2005 not accepting: |
| 85 | // |
| 86 | // friend class |
brettw | cf58460 | 2015-06-02 14:34:43 +0900 | [diff] [blame] | 87 | // base::RefCountedThreadSafe<ObserverListThreadSafe<ObserverType>>; |
akalin@chromium.org | e43be3d | 2011-01-12 06:19:54 +0900 | [diff] [blame] | 88 | // |
| 89 | // Instead of friending the class, we could friend the actual function |
| 90 | // which calls delete. However, this ends up being |
| 91 | // RefCountedThreadSafe::DeleteInternal(), which is private. So we |
| 92 | // define our own templated traits class so we can friend it. |
| 93 | template <class T> |
| 94 | struct ObserverListThreadSafeTraits { |
| 95 | static void Destruct(const ObserverListThreadSafe<T>* x) { |
| 96 | delete x; |
| 97 | } |
| 98 | }; |
| 99 | |
mbelshe@google.com | 877d203 | 2008-10-23 08:09:21 +0900 | [diff] [blame] | 100 | template <class ObserverType> |
maruel@chromium.org | 8fe7adc | 2009-03-04 00:01:12 +0900 | [diff] [blame] | 101 | class ObserverListThreadSafe |
brettw | cf58460 | 2015-06-02 14:34:43 +0900 | [diff] [blame] | 102 | : public RefCountedThreadSafe< |
akalin@chromium.org | e43be3d | 2011-01-12 06:19:54 +0900 | [diff] [blame] | 103 | ObserverListThreadSafe<ObserverType>, |
brettw | cf58460 | 2015-06-02 14:34:43 +0900 | [diff] [blame] | 104 | ObserverListThreadSafeTraits<ObserverType>> { |
mbelshe@google.com | 877d203 | 2008-10-23 08:09:21 +0900 | [diff] [blame] | 105 | public: |
willchan@chromium.org | 4c7f03e | 2010-09-01 07:54:21 +0900 | [diff] [blame] | 106 | typedef typename ObserverList<ObserverType>::NotificationType |
| 107 | NotificationType; |
| 108 | |
| 109 | ObserverListThreadSafe() |
| 110 | : type_(ObserverListBase<ObserverType>::NOTIFY_ALL) {} |
| 111 | explicit ObserverListThreadSafe(NotificationType type) : type_(type) {} |
mbelshe@google.com | 877d203 | 2008-10-23 08:09:21 +0900 | [diff] [blame] | 112 | |
akalin@chromium.org | cbec5fb | 2011-06-05 16:07:12 +0900 | [diff] [blame] | 113 | // Add an observer to the list. An observer should not be added to |
| 114 | // the same list more than once. |
mbelshe@google.com | 877d203 | 2008-10-23 08:09:21 +0900 | [diff] [blame] | 115 | void AddObserver(ObserverType* obs) { |
rsesek@chromium.org | 1aab77c | 2011-11-24 05:34:04 +0900 | [diff] [blame] | 116 | // If there is not a current MessageLoop, it is impossible to notify on it, |
| 117 | // so do not add the observer. |
brettw | cf58460 | 2015-06-02 14:34:43 +0900 | [diff] [blame] | 118 | if (!MessageLoop::current()) |
rsesek@chromium.org | 1aab77c | 2011-11-24 05:34:04 +0900 | [diff] [blame] | 119 | return; |
| 120 | |
robliao | 3c02ea2 | 2015-04-24 07:45:32 +0900 | [diff] [blame] | 121 | ObserverList<ObserverType>* list = nullptr; |
brettw | cf58460 | 2015-06-02 14:34:43 +0900 | [diff] [blame] | 122 | PlatformThreadId thread_id = PlatformThread::CurrentId(); |
mbelshe@google.com | 877d203 | 2008-10-23 08:09:21 +0900 | [diff] [blame] | 123 | { |
brettw | cf58460 | 2015-06-02 14:34:43 +0900 | [diff] [blame] | 124 | AutoLock lock(list_lock_); |
rsesek@chromium.org | 1aab77c | 2011-11-24 05:34:04 +0900 | [diff] [blame] | 125 | if (observer_lists_.find(thread_id) == observer_lists_.end()) |
| 126 | observer_lists_[thread_id] = new ObserverListContext(type_); |
| 127 | list = &(observer_lists_[thread_id]->list); |
mbelshe@google.com | 877d203 | 2008-10-23 08:09:21 +0900 | [diff] [blame] | 128 | } |
| 129 | list->AddObserver(obs); |
| 130 | } |
| 131 | |
akalin@chromium.org | cbec5fb | 2011-06-05 16:07:12 +0900 | [diff] [blame] | 132 | // Remove an observer from the list if it is in the list. |
mbelshe@google.com | 877d203 | 2008-10-23 08:09:21 +0900 | [diff] [blame] | 133 | // If there are pending notifications in-transit to the observer, they will |
| 134 | // be aborted. |
akalin@chromium.org | cbec5fb | 2011-06-05 16:07:12 +0900 | [diff] [blame] | 135 | // If the observer to be removed is in the list, RemoveObserver MUST |
| 136 | // be called from the same thread which called AddObserver. |
mbelshe@google.com | 877d203 | 2008-10-23 08:09:21 +0900 | [diff] [blame] | 137 | void RemoveObserver(ObserverType* obs) { |
robliao | 3c02ea2 | 2015-04-24 07:45:32 +0900 | [diff] [blame] | 138 | ObserverListContext* context = nullptr; |
| 139 | ObserverList<ObserverType>* list = nullptr; |
brettw | cf58460 | 2015-06-02 14:34:43 +0900 | [diff] [blame] | 140 | PlatformThreadId thread_id = PlatformThread::CurrentId(); |
mbelshe@google.com | 877d203 | 2008-10-23 08:09:21 +0900 | [diff] [blame] | 141 | { |
brettw | cf58460 | 2015-06-02 14:34:43 +0900 | [diff] [blame] | 142 | AutoLock lock(list_lock_); |
rsesek@chromium.org | 1aab77c | 2011-11-24 05:34:04 +0900 | [diff] [blame] | 143 | typename ObserversListMap::iterator it = observer_lists_.find(thread_id); |
akalin@chromium.org | cbec5fb | 2011-06-05 16:07:12 +0900 | [diff] [blame] | 144 | if (it == observer_lists_.end()) { |
adamk@chromium.org | 2bc73e7 | 2011-08-10 06:29:59 +0900 | [diff] [blame] | 145 | // This will happen if we try to remove an observer on a thread |
akalin@chromium.org | cbec5fb | 2011-06-05 16:07:12 +0900 | [diff] [blame] | 146 | // we never added an observer for. |
mbelshe@google.com | 2d95cab | 2008-11-04 02:15:07 +0900 | [diff] [blame] | 147 | return; |
| 148 | } |
adamk@chromium.org | 2bc73e7 | 2011-08-10 06:29:59 +0900 | [diff] [blame] | 149 | context = it->second; |
| 150 | list = &context->list; |
mbelshe@google.com | 877d203 | 2008-10-23 08:09:21 +0900 | [diff] [blame] | 151 | |
| 152 | // If we're about to remove the last observer from the list, |
| 153 | // then we can remove this observer_list entirely. |
akalin@chromium.org | cbec5fb | 2011-06-05 16:07:12 +0900 | [diff] [blame] | 154 | if (list->HasObserver(obs) && list->size() == 1) |
| 155 | observer_lists_.erase(it); |
mbelshe@google.com | 877d203 | 2008-10-23 08:09:21 +0900 | [diff] [blame] | 156 | } |
| 157 | list->RemoveObserver(obs); |
| 158 | |
| 159 | // If RemoveObserver is called from a notification, the size will be |
| 160 | // nonzero. Instead of deleting here, the NotifyWrapper will delete |
| 161 | // when it finishes iterating. |
| 162 | if (list->size() == 0) |
adamk@chromium.org | 2bc73e7 | 2011-08-10 06:29:59 +0900 | [diff] [blame] | 163 | delete context; |
mbelshe@google.com | 877d203 | 2008-10-23 08:09:21 +0900 | [diff] [blame] | 164 | } |
| 165 | |
sergeyu@chromium.org | 86992ef | 2012-02-08 09:22:11 +0900 | [diff] [blame] | 166 | // Verifies that the list is currently empty (i.e. there are no observers). |
| 167 | void AssertEmpty() const { |
brettw | cf58460 | 2015-06-02 14:34:43 +0900 | [diff] [blame] | 168 | AutoLock lock(list_lock_); |
sergeyu@chromium.org | 86992ef | 2012-02-08 09:22:11 +0900 | [diff] [blame] | 169 | DCHECK(observer_lists_.empty()); |
| 170 | } |
| 171 | |
mbelshe@google.com | 877d203 | 2008-10-23 08:09:21 +0900 | [diff] [blame] | 172 | // Notify methods. |
| 173 | // Make a thread-safe callback to each Observer in the list. |
| 174 | // Note, these calls are effectively asynchronous. You cannot assume |
| 175 | // that at the completion of the Notify call that all Observers have |
| 176 | // been Notified. The notification may still be pending delivery. |
thakis | d5c8587 | 2014-12-23 11:02:57 +0900 | [diff] [blame] | 177 | template <class Method, class... Params> |
reillyg | 57b1bc5 | 2015-02-10 05:18:33 +0900 | [diff] [blame] | 178 | void Notify(const tracked_objects::Location& from_here, |
| 179 | Method m, |
| 180 | const Params&... params) { |
brettw | cf58460 | 2015-06-02 14:34:43 +0900 | [diff] [blame] | 181 | internal::UnboundMethod<ObserverType, Method, Tuple<Params...>> method( |
| 182 | m, MakeTuple(params...)); |
mbelshe@google.com | 877d203 | 2008-10-23 08:09:21 +0900 | [diff] [blame] | 183 | |
brettw | cf58460 | 2015-06-02 14:34:43 +0900 | [diff] [blame] | 184 | AutoLock lock(list_lock_); |
thakis | d5c8587 | 2014-12-23 11:02:57 +0900 | [diff] [blame] | 185 | for (const auto& entry : observer_lists_) { |
| 186 | ObserverListContext* context = entry.second; |
skyostil | 97aefe1 | 2015-05-01 04:06:15 +0900 | [diff] [blame] | 187 | context->task_runner->PostTask( |
reillyg | 57b1bc5 | 2015-02-10 05:18:33 +0900 | [diff] [blame] | 188 | from_here, |
brettw | cf58460 | 2015-06-02 14:34:43 +0900 | [diff] [blame] | 189 | Bind(&ObserverListThreadSafe<ObserverType>::template NotifyWrapper< |
| 190 | Method, Tuple<Params...>>, |
thakis | d5c8587 | 2014-12-23 11:02:57 +0900 | [diff] [blame] | 191 | this, context, method)); |
| 192 | } |
mbelshe@google.com | 877d203 | 2008-10-23 08:09:21 +0900 | [diff] [blame] | 193 | } |
| 194 | |
mbelshe@google.com | 877d203 | 2008-10-23 08:09:21 +0900 | [diff] [blame] | 195 | private: |
akalin@chromium.org | e43be3d | 2011-01-12 06:19:54 +0900 | [diff] [blame] | 196 | // See comment above ObserverListThreadSafeTraits' definition. |
| 197 | friend struct ObserverListThreadSafeTraits<ObserverType>; |
| 198 | |
adamk@chromium.org | 2bc73e7 | 2011-08-10 06:29:59 +0900 | [diff] [blame] | 199 | struct ObserverListContext { |
| 200 | explicit ObserverListContext(NotificationType type) |
brettw | cf58460 | 2015-06-02 14:34:43 +0900 | [diff] [blame] | 201 | : task_runner(ThreadTaskRunnerHandle::Get()), list(type) {} |
adamk@chromium.org | 2bc73e7 | 2011-08-10 06:29:59 +0900 | [diff] [blame] | 202 | |
brettw | cf58460 | 2015-06-02 14:34:43 +0900 | [diff] [blame] | 203 | scoped_refptr<SingleThreadTaskRunner> task_runner; |
adamk@chromium.org | 2bc73e7 | 2011-08-10 06:29:59 +0900 | [diff] [blame] | 204 | ObserverList<ObserverType> list; |
| 205 | |
danakj | de6142a | 2015-03-08 08:04:23 +0900 | [diff] [blame] | 206 | private: |
adamk@chromium.org | 2bc73e7 | 2011-08-10 06:29:59 +0900 | [diff] [blame] | 207 | DISALLOW_COPY_AND_ASSIGN(ObserverListContext); |
| 208 | }; |
| 209 | |
akalin@chromium.org | 982d9d5 | 2011-01-11 05:40:36 +0900 | [diff] [blame] | 210 | ~ObserverListThreadSafe() { |
tfarina@chromium.org | e2903a5 | 2013-03-17 14:52:05 +0900 | [diff] [blame] | 211 | STLDeleteValues(&observer_lists_); |
akalin@chromium.org | 982d9d5 | 2011-01-11 05:40:36 +0900 | [diff] [blame] | 212 | } |
| 213 | |
mbelshe@google.com | 877d203 | 2008-10-23 08:09:21 +0900 | [diff] [blame] | 214 | // Wrapper which is called to fire the notifications for each thread's |
| 215 | // ObserverList. This function MUST be called on the thread which owns |
| 216 | // the unsafe ObserverList. |
| 217 | template <class Method, class Params> |
brettw | cf58460 | 2015-06-02 14:34:43 +0900 | [diff] [blame] | 218 | void NotifyWrapper( |
| 219 | ObserverListContext* context, |
| 220 | const internal::UnboundMethod<ObserverType, Method, Params>& method) { |
mbelshe@google.com | 877d203 | 2008-10-23 08:09:21 +0900 | [diff] [blame] | 221 | // Check that this list still needs notifications. |
| 222 | { |
brettw | cf58460 | 2015-06-02 14:34:43 +0900 | [diff] [blame] | 223 | AutoLock lock(list_lock_); |
mbelshe@google.com | 877d203 | 2008-10-23 08:09:21 +0900 | [diff] [blame] | 224 | typename ObserversListMap::iterator it = |
brettw | cf58460 | 2015-06-02 14:34:43 +0900 | [diff] [blame] | 225 | observer_lists_.find(PlatformThread::CurrentId()); |
mbelshe@google.com | 877d203 | 2008-10-23 08:09:21 +0900 | [diff] [blame] | 226 | |
| 227 | // The ObserverList could have been removed already. In fact, it could |
| 228 | // have been removed and then re-added! If the master list's loop |
| 229 | // does not match this one, then we do not need to finish this |
| 230 | // notification. |
adamk@chromium.org | 2bc73e7 | 2011-08-10 06:29:59 +0900 | [diff] [blame] | 231 | if (it == observer_lists_.end() || it->second != context) |
mbelshe@google.com | 877d203 | 2008-10-23 08:09:21 +0900 | [diff] [blame] | 232 | return; |
| 233 | } |
| 234 | |
| 235 | { |
danakj | 1023589 | 2015-03-10 02:45:39 +0900 | [diff] [blame] | 236 | typename ObserverList<ObserverType>::Iterator it(&context->list); |
mbelshe@google.com | 877d203 | 2008-10-23 08:09:21 +0900 | [diff] [blame] | 237 | ObserverType* obs; |
robliao | 3c02ea2 | 2015-04-24 07:45:32 +0900 | [diff] [blame] | 238 | while ((obs = it.GetNext()) != nullptr) |
mbelshe@google.com | 877d203 | 2008-10-23 08:09:21 +0900 | [diff] [blame] | 239 | method.Run(obs); |
| 240 | } |
| 241 | |
| 242 | // If there are no more observers on the list, we can now delete it. |
adamk@chromium.org | 2bc73e7 | 2011-08-10 06:29:59 +0900 | [diff] [blame] | 243 | if (context->list.size() == 0) { |
mbelshe@google.com | 877d203 | 2008-10-23 08:09:21 +0900 | [diff] [blame] | 244 | { |
brettw | cf58460 | 2015-06-02 14:34:43 +0900 | [diff] [blame] | 245 | AutoLock lock(list_lock_); |
willchan@chromium.org | 2777ca5 | 2010-09-18 04:33:06 +0900 | [diff] [blame] | 246 | // Remove |list| if it's not already removed. |
| 247 | // This can happen if multiple observers got removed in a notification. |
| 248 | // See http://crbug.com/55725. |
mbelshe@google.com | 877d203 | 2008-10-23 08:09:21 +0900 | [diff] [blame] | 249 | typename ObserversListMap::iterator it = |
brettw | cf58460 | 2015-06-02 14:34:43 +0900 | [diff] [blame] | 250 | observer_lists_.find(PlatformThread::CurrentId()); |
adamk@chromium.org | 2bc73e7 | 2011-08-10 06:29:59 +0900 | [diff] [blame] | 251 | if (it != observer_lists_.end() && it->second == context) |
willchan@chromium.org | 2777ca5 | 2010-09-18 04:33:06 +0900 | [diff] [blame] | 252 | observer_lists_.erase(it); |
mbelshe@google.com | 877d203 | 2008-10-23 08:09:21 +0900 | [diff] [blame] | 253 | } |
adamk@chromium.org | 2bc73e7 | 2011-08-10 06:29:59 +0900 | [diff] [blame] | 254 | delete context; |
mbelshe@google.com | 877d203 | 2008-10-23 08:09:21 +0900 | [diff] [blame] | 255 | } |
| 256 | } |
| 257 | |
rsesek@chromium.org | 1aab77c | 2011-11-24 05:34:04 +0900 | [diff] [blame] | 258 | // Key by PlatformThreadId because in tests, clients can attempt to remove |
| 259 | // observers without a MessageLoop. If this were keyed by MessageLoop, that |
| 260 | // operation would be silently ignored, leaving garbage in the ObserverList. |
brettw | cf58460 | 2015-06-02 14:34:43 +0900 | [diff] [blame] | 261 | typedef std::map<PlatformThreadId, ObserverListContext*> |
rsesek@chromium.org | 1aab77c | 2011-11-24 05:34:04 +0900 | [diff] [blame] | 262 | ObserversListMap; |
mbelshe@google.com | 877d203 | 2008-10-23 08:09:21 +0900 | [diff] [blame] | 263 | |
brettw | cf58460 | 2015-06-02 14:34:43 +0900 | [diff] [blame] | 264 | mutable Lock list_lock_; // Protects the observer_lists_. |
mbelshe@google.com | 877d203 | 2008-10-23 08:09:21 +0900 | [diff] [blame] | 265 | ObserversListMap observer_lists_; |
willchan@chromium.org | 4c7f03e | 2010-09-01 07:54:21 +0900 | [diff] [blame] | 266 | const NotificationType type_; |
mbelshe@google.com | 877d203 | 2008-10-23 08:09:21 +0900 | [diff] [blame] | 267 | |
tfarina@chromium.org | 0aad842 | 2010-06-05 01:13:51 +0900 | [diff] [blame] | 268 | DISALLOW_COPY_AND_ASSIGN(ObserverListThreadSafe); |
mbelshe@google.com | 877d203 | 2008-10-23 08:09:21 +0900 | [diff] [blame] | 269 | }; |
| 270 | |
brettw | cf58460 | 2015-06-02 14:34:43 +0900 | [diff] [blame] | 271 | } // namespace base |
| 272 | |
mbelshe@google.com | 877d203 | 2008-10-23 08:09:21 +0900 | [diff] [blame] | 273 | #endif // BASE_OBSERVER_LIST_THREADSAFE_H_ |