Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
| 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_CALLBACK_LIST_INTERNAL_H_ | |
| 6 #define BASE_CALLBACK_LIST_INTERNAL_H_ | |
| 7 | |
| 8 #include <limits> | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "base/base_export.h" | |
| 12 #include "base/basictypes.h" | |
| 13 #include "base/callback_internal.h" | |
| 14 #include "base/memory/scoped_ptr.h" | |
| 15 #include "base/memory/weak_ptr.h" | |
| 16 | |
| 17 namespace base { | |
| 18 // Enumeration of which callbacks are called. | |
| 19 enum CallbackNotificationType { | |
|
awong
2013/09/04 18:48:21
I would put this inside CallbackListImpl.
Cait (Slow)
2013/09/04 22:09:25
Done.
| |
| 20 // Specifies that any callbacks added during notification are called. | |
| 21 CALLBACKS_NOTIFY_ALL, | |
| 22 | |
| 23 // Specifies that callbacks added while sending out notifications are not | |
| 24 // called. | |
| 25 CALLBACKS_NOTIFY_EXISTING_ONLY | |
| 26 }; | |
| 27 | |
| 28 namespace internal { | |
| 29 | |
| 30 // Holds the CallbackList methods that don't require specialization to reduce | |
|
awong
2013/09/04 18:48:21
don't -> do not
Cait (Slow)
2013/09/04 22:09:25
Done.
| |
| 31 // template bloat. | |
| 32 // | |
| 33 // This class is meant as an implementation detail for CallbackList and | |
| 34 // CallbackListDetails. Do not use it directly. | |
| 35 | |
| 36 class BASE_EXPORT CallbackListImpl { | |
| 37 public: | |
| 38 typedef std::vector<base::internal::CallbackBase*> ListType; | |
| 39 | |
| 40 // An iterator class that can be used to access the list of callbacks. | |
| 41 class Iterator { | |
| 42 public: | |
| 43 explicit Iterator(const base::WeakPtr<CallbackListImpl>& list); | |
| 44 | |
| 45 ~Iterator(); | |
| 46 | |
| 47 base::internal::CallbackBase* GetNext(); | |
| 48 | |
| 49 private: | |
| 50 base::WeakPtr<CallbackListImpl> list_; | |
| 51 size_t index_; | |
| 52 size_t max_index_; | |
| 53 }; | |
| 54 | |
| 55 explicit CallbackListImpl(CallbackNotificationType type); | |
| 56 ~CallbackListImpl(); | |
| 57 | |
| 58 // Add a callback to the list, if it is not already in there. This method | |
| 59 // takes ownership of |cb|, and will handle deleting it upon removal from the | |
| 60 // list. | |
|
awong
2013/09/04 18:48:21
Add something about the meaning of the return valu
Cait (Slow)
2013/09/04 22:09:25
Done.
| |
| 61 base::Closure AddCallback(base::internal::CallbackBase* cb); | |
| 62 | |
| 63 // Delete (or nullify, if called during iteration), all callbacks in the list. | |
| 64 void Clear(); | |
| 65 | |
| 66 // Returns true if there is a chance that the list may still contain active | |
| 67 // callbacks. | |
|
awong
2013/09/04 18:48:21
Can you add a little more explaining how this how
Cait (Slow)
2013/09/04 22:09:25
Replacing this with AssertEmpty for clarity.
| |
| 68 bool might_have_callbacks() const { return size() != 0; } | |
| 69 | |
| 70 // Remove a callback from the list if it is in the list. | |
| 71 void RemoveCallback(base::internal::CallbackBase* cb); | |
|
awong
2013/09/04 18:48:21
I think all the following should be private.
Cait (Slow)
2013/09/04 22:09:25
Done.
| |
| 72 | |
| 73 // Get a weak pointer to the CallbackList. | |
| 74 base::WeakPtr<CallbackListImpl> GetWeakPtr(); | |
| 75 | |
| 76 // Compact the list (remove any elements which were nulled out during | |
| 77 // iteration). | |
| 78 void Compact(); | |
| 79 | |
| 80 // Returns the number of callbacks in the list. Note that if the list has not | |
| 81 // been compacted, some of these callbacks may be NULL. | |
| 82 size_t size() const { return callbacks_.size(); } | |
| 83 | |
| 84 private: | |
| 85 ListType callbacks_; | |
| 86 int active_iterator_count_; | |
| 87 CallbackNotificationType type_; | |
| 88 base::WeakPtrFactory<CallbackListImpl> weak_factory_; | |
| 89 | |
| 90 DISALLOW_COPY_AND_ASSIGN(CallbackListImpl); | |
| 91 }; | |
| 92 | |
| 93 } // namespace internal | |
| 94 } // namespace base | |
| 95 | |
| 96 #endif // BASE_CALLBACK_LIST_INTERNAL_H_ | |
| OLD | NEW |