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..4e42946ae0a51bb9a5ef564ad8f619b79f5647b4 |
--- /dev/null |
+++ b/base/callback_list_internal.h |
@@ -0,0 +1,80 @@ |
+// 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 { |
+ |
+namespace internal { |
+ |
+// Holds the CallbackList methods that do not require specialization to reduce |
+// template bloat. |
+// |
+// This class is meant as an implementation detail for CallbackList and |
+// CallbackListWithDetails. Do not use it directly. |
+ |
+class BASE_EXPORT CallbackListImpl { |
+ public: |
+ typedef std::vector<base::internal::CallbackBase*> ListType; |
awong
2013/09/04 23:20:07
This typedef can be private.
Cait (Slow)
2013/09/06 18:41:46
Done.
|
+ |
+ // 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_; |
+ }; |
+ |
+ CallbackListImpl(); |
+ ~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. The returned closure is used to remove the callback from the list. |
+ base::Closure Add(base::internal::CallbackBase* cb); |
+ |
+ // Delete all callbacks in the list. |
+ void Clear(); |
+ |
+ // Assert that the list is empty and no iterators are active. |
+ void AssertEmpty(); |
awong
2013/09/04 23:20:07
This is missing an implementation.
Cait (Slow)
2013/09/06 18:41:46
Done.
|
+ |
+ // Get an iterator to the CallbackList. |
+ scoped_ptr<CallbackListImpl::Iterator> GetIterator(); |
awong
2013/09/04 23:20:07
What about returning the Iterator by copy like eri
Cait (Slow)
2013/09/06 18:41:46
Done.
|
+ |
+ // Compact the list (remove any elements which were nulled out during |
awong
2013/09/04 23:20:07
nulled -> NULLed
Cait (Slow)
2013/09/06 18:41:46
Done.
|
+ // iteration). |
+ void Compact(); |
+ |
+ private: |
+ // Remove a callback from the list if it is in the list. |
+ void Remove(base::internal::CallbackBase* cb); |
+ |
+ ListType callbacks_; |
+ int active_iterator_count_; |
+ base::WeakPtrFactory<CallbackListImpl> weak_factory_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(CallbackListImpl); |
+}; |
+ |
+} // namespace internal |
+} // namespace base |
+ |
+#endif // BASE_CALLBACK_LIST_INTERNAL_H_ |