OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 10 matching lines...) Expand all Loading... |
21 // OVERVIEW: | 21 // OVERVIEW: |
22 // | 22 // |
23 // A thread-safe container for a list of observers. | 23 // A thread-safe container for a list of observers. |
24 // This is similar to the observer_list (see observer_list.h), but it | 24 // This is similar to the observer_list (see observer_list.h), but it |
25 // is more robust for multi-threaded situations. | 25 // is more robust for multi-threaded situations. |
26 // | 26 // |
27 // The following use cases are supported: | 27 // The following use cases are supported: |
28 // * Observers can register for notifications from any thread. | 28 // * Observers can register for notifications from any thread. |
29 // Callbacks to the observer will occur on the same thread where | 29 // Callbacks to the observer will occur on the same thread where |
30 // the observer initially called AddObserver() from. | 30 // the observer initially called AddObserver() from. |
31 // * Any thread may trigger a notification via NOTIFY_OBSERVERS. | 31 // * Any thread may trigger a notification via Notify(). |
32 // * Observers can remove themselves from the observer list inside | 32 // * Observers can remove themselves from the observer list inside |
33 // of a callback. | 33 // of a callback. |
34 // * If one thread is notifying observers concurrently with an observer | 34 // * If one thread is notifying observers concurrently with an observer |
35 // removing itself from the observer list, the notifications will | 35 // removing itself from the observer list, the notifications will |
36 // be silently dropped. | 36 // be silently dropped. |
37 // | 37 // |
38 // The drawback of the threadsafe observer list is that notifications | 38 // The drawback of the threadsafe observer list is that notifications |
39 // are not as real-time as the non-threadsafe version of this class. | 39 // are not as real-time as the non-threadsafe version of this class. |
40 // Notifications will always be done via PostTask() to another thread, | 40 // Notifications will always be done via PostTask() to another thread, |
41 // whereas with the non-thread-safe observer_list, notifications happen | 41 // whereas with the non-thread-safe observer_list, notifications happen |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 typedef std::map<MessageLoop*, ObserverList<ObserverType>*> ObserversListMap; | 192 typedef std::map<MessageLoop*, ObserverList<ObserverType>*> ObserversListMap; |
193 | 193 |
194 // These are marked mutable to facilitate having NotifyAll be const. | 194 // These are marked mutable to facilitate having NotifyAll be const. |
195 Lock list_lock_; // Protects the observer_lists_. | 195 Lock list_lock_; // Protects the observer_lists_. |
196 ObserversListMap observer_lists_; | 196 ObserversListMap observer_lists_; |
197 | 197 |
198 DISALLOW_COPY_AND_ASSIGN(ObserverListThreadSafe); | 198 DISALLOW_COPY_AND_ASSIGN(ObserverListThreadSafe); |
199 }; | 199 }; |
200 | 200 |
201 #endif // BASE_OBSERVER_LIST_THREADSAFE_H_ | 201 #endif // BASE_OBSERVER_LIST_THREADSAFE_H_ |
OLD | NEW |