| 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <map> | 10 #include <map> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/callback.h" | 13 #include "base/callback.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/memory/ref_counted.h" |
| 15 #include "base/message_loop.h" | 16 #include "base/message_loop.h" |
| 16 #include "base/observer_list.h" | 17 #include "base/observer_list.h" |
| 17 #include "base/ref_counted.h" | |
| 18 #include "base/task.h" | 18 #include "base/task.h" |
| 19 | 19 |
| 20 /////////////////////////////////////////////////////////////////////////////// | 20 /////////////////////////////////////////////////////////////////////////////// |
| 21 // | 21 // |
| 22 // OVERVIEW: | 22 // OVERVIEW: |
| 23 // | 23 // |
| 24 // A thread-safe container for a list of observers. | 24 // A thread-safe container for a list of observers. |
| 25 // This is similar to the observer_list (see observer_list.h), but it | 25 // This is similar to the observer_list (see observer_list.h), but it |
| 26 // is more robust for multi-threaded situations. | 26 // is more robust for multi-threaded situations. |
| 27 // | 27 // |
| (...skipping 22 matching lines...) Expand all Loading... |
| 50 // | 50 // |
| 51 /////////////////////////////////////////////////////////////////////////////// | 51 /////////////////////////////////////////////////////////////////////////////// |
| 52 | 52 |
| 53 // Forward declaration for ObserverListThreadSafeTraits. | 53 // Forward declaration for ObserverListThreadSafeTraits. |
| 54 template <class ObserverType> | 54 template <class ObserverType> |
| 55 class ObserverListThreadSafe; | 55 class ObserverListThreadSafe; |
| 56 | 56 |
| 57 // This class is used to work around VS2005 not accepting: | 57 // This class is used to work around VS2005 not accepting: |
| 58 // | 58 // |
| 59 // friend class | 59 // friend class |
| 60 // base::RefCountedThreadSafe<ObserverListThreadSafe<ObserverType> >; | 60 // base::RefCountedThreadSafe<ObserverListThreadSafe<ObserverType> >; |
| 61 // | 61 // |
| 62 // Instead of friending the class, we could friend the actual function | 62 // Instead of friending the class, we could friend the actual function |
| 63 // which calls delete. However, this ends up being | 63 // which calls delete. However, this ends up being |
| 64 // RefCountedThreadSafe::DeleteInternal(), which is private. So we | 64 // RefCountedThreadSafe::DeleteInternal(), which is private. So we |
| 65 // define our own templated traits class so we can friend it. | 65 // define our own templated traits class so we can friend it. |
| 66 template <class T> | 66 template <class T> |
| 67 struct ObserverListThreadSafeTraits { | 67 struct ObserverListThreadSafeTraits { |
| 68 static void Destruct(const ObserverListThreadSafe<T>* x) { | 68 static void Destruct(const ObserverListThreadSafe<T>* x) { |
| 69 delete x; | 69 delete x; |
| 70 } | 70 } |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 | 226 |
| 227 // These are marked mutable to facilitate having NotifyAll be const. | 227 // These are marked mutable to facilitate having NotifyAll be const. |
| 228 base::Lock list_lock_; // Protects the observer_lists_. | 228 base::Lock list_lock_; // Protects the observer_lists_. |
| 229 ObserversListMap observer_lists_; | 229 ObserversListMap observer_lists_; |
| 230 const NotificationType type_; | 230 const NotificationType type_; |
| 231 | 231 |
| 232 DISALLOW_COPY_AND_ASSIGN(ObserverListThreadSafe); | 232 DISALLOW_COPY_AND_ASSIGN(ObserverListThreadSafe); |
| 233 }; | 233 }; |
| 234 | 234 |
| 235 #endif // BASE_OBSERVER_LIST_THREADSAFE_H_ | 235 #endif // BASE_OBSERVER_LIST_THREADSAFE_H_ |
| OLD | NEW |