Index: base/callback_list_internal.h |
diff --git a/base/callback_list_internal.h b/base/callback_list_internal.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..8baf689738fc92f0432e3b8611a4a0667572c7c7 |
--- /dev/null |
+++ b/base/callback_list_internal.h |
@@ -0,0 +1,96 @@ |
+// Copyright 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef BASE_CALLBACK_LIST_INTERNAL_H_ |
+#define BASE_CALLBACK_LIST_INTERNAL_H_ |
+ |
+#include <limits> |
+#include <vector> |
+ |
+#include "base/base_export.h" |
+#include "base/basictypes.h" |
+#include "base/callback_internal.h" |
+#include "base/memory/scoped_ptr.h" |
+#include "base/memory/weak_ptr.h" |
+ |
+namespace base { |
+ // Enumeration of which callbacks are called. |
+ enum CallbackNotificationType { |
awong
2013/09/04 18:48:21
I would put this inside CallbackListImpl.
Cait (Slow)
2013/09/04 22:09:25
Done.
|
+ // Specifies that any callbacks added during notification are called. |
+ CALLBACKS_NOTIFY_ALL, |
+ |
+ // Specifies that callbacks added while sending out notifications are not |
+ // called. |
+ CALLBACKS_NOTIFY_EXISTING_ONLY |
+ }; |
+ |
+namespace internal { |
+ |
+// 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.
|
+// template bloat. |
+// |
+// This class is meant as an implementation detail for CallbackList and |
+// CallbackListDetails. Do not use it directly. |
+ |
+class BASE_EXPORT CallbackListImpl { |
+ public: |
+ typedef std::vector<base::internal::CallbackBase*> ListType; |
+ |
+ // An iterator class that can be used to access the list of callbacks. |
+ class Iterator { |
+ public: |
+ explicit Iterator(const base::WeakPtr<CallbackListImpl>& list); |
+ |
+ ~Iterator(); |
+ |
+ base::internal::CallbackBase* GetNext(); |
+ |
+ private: |
+ base::WeakPtr<CallbackListImpl> list_; |
+ size_t index_; |
+ size_t max_index_; |
+ }; |
+ |
+ explicit CallbackListImpl(CallbackNotificationType type); |
+ ~CallbackListImpl(); |
+ |
+ // Add a callback to the list, if it is not already in there. This method |
+ // takes ownership of |cb|, and will handle deleting it upon removal from the |
+ // 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.
|
+ base::Closure AddCallback(base::internal::CallbackBase* cb); |
+ |
+ // Delete (or nullify, if called during iteration), all callbacks in the list. |
+ void Clear(); |
+ |
+ // Returns true if there is a chance that the list may still contain active |
+ // 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.
|
+ bool might_have_callbacks() const { return size() != 0; } |
+ |
+ // Remove a callback from the list if it is in the list. |
+ 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.
|
+ |
+ // Get a weak pointer to the CallbackList. |
+ base::WeakPtr<CallbackListImpl> GetWeakPtr(); |
+ |
+ // Compact the list (remove any elements which were nulled out during |
+ // iteration). |
+ void Compact(); |
+ |
+ // Returns the number of callbacks in the list. Note that if the list has not |
+ // been compacted, some of these callbacks may be NULL. |
+ size_t size() const { return callbacks_.size(); } |
+ |
+ private: |
+ ListType callbacks_; |
+ int active_iterator_count_; |
+ CallbackNotificationType type_; |
+ base::WeakPtrFactory<CallbackListImpl> weak_factory_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(CallbackListImpl); |
+}; |
+ |
+} // namespace internal |
+} // namespace base |
+ |
+#endif // BASE_CALLBACK_LIST_INTERNAL_H_ |