OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef BASE_OBSERVER_LIST_THREADSAFE_H_ | 5 #ifndef BASE_OBSERVER_LIST_THREADSAFE_H_ |
6 #define BASE_OBSERVER_LIST_THREADSAFE_H_ | 6 #define BASE_OBSERVER_LIST_THREADSAFE_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 // TODO(mbelshe): Add more wrappers for Notify() with more arguments. | 130 // TODO(mbelshe): Add more wrappers for Notify() with more arguments. |
131 | 131 |
132 private: | 132 private: |
133 template <class Method, class Params> | 133 template <class Method, class Params> |
134 void Notify(const UnboundMethod<ObserverType, Method, Params>& method) { | 134 void Notify(const UnboundMethod<ObserverType, Method, Params>& method) { |
135 AutoLock lock(list_lock_); | 135 AutoLock lock(list_lock_); |
136 typename ObserversListMap::iterator it; | 136 typename ObserversListMap::iterator it; |
137 for (it = observer_lists_.begin(); it != observer_lists_.end(); ++it) { | 137 for (it = observer_lists_.begin(); it != observer_lists_.end(); ++it) { |
138 MessageLoop* loop = (*it).first; | 138 MessageLoop* loop = (*it).first; |
139 ObserverList<ObserverType>* list = (*it).second; | 139 ObserverList<ObserverType>* list = (*it).second; |
140 loop->PostTask(FROM_HERE, | 140 loop->PostTask( |
| 141 FROM_HERE, |
141 NewRunnableMethod(this, | 142 NewRunnableMethod(this, |
142 &ObserverListThreadSafe<ObserverType>:: | 143 &ObserverListThreadSafe<ObserverType>:: |
143 template NotifyWrapper<Method, Params>, list, method)); | 144 template NotifyWrapper<Method, Params>, list, method)); |
144 } | 145 } |
145 } | 146 } |
146 | 147 |
147 // Wrapper which is called to fire the notifications for each thread's | 148 // Wrapper which is called to fire the notifications for each thread's |
148 // ObserverList. This function MUST be called on the thread which owns | 149 // ObserverList. This function MUST be called on the thread which owns |
149 // the unsafe ObserverList. | 150 // the unsafe ObserverList. |
150 template <class Method, class Params> | 151 template <class Method, class Params> |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 typedef std::map<MessageLoop*, ObserverList<ObserverType>*> ObserversListMap; | 191 typedef std::map<MessageLoop*, ObserverList<ObserverType>*> ObserversListMap; |
191 | 192 |
192 // These are marked mutable to facilitate having NotifyAll be const. | 193 // These are marked mutable to facilitate having NotifyAll be const. |
193 Lock list_lock_; // Protects the observer_lists_. | 194 Lock list_lock_; // Protects the observer_lists_. |
194 ObserversListMap observer_lists_; | 195 ObserversListMap observer_lists_; |
195 | 196 |
196 DISALLOW_EVIL_CONSTRUCTORS(ObserverListThreadSafe); | 197 DISALLOW_EVIL_CONSTRUCTORS(ObserverListThreadSafe); |
197 }; | 198 }; |
198 | 199 |
199 #endif // BASE_OBSERVER_LIST_THREADSAFE_H_ | 200 #endif // BASE_OBSERVER_LIST_THREADSAFE_H_ |
OLD | NEW |