Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3157)

Unified Diff: base/callback_list_internal.h

Issue 22877038: Add a CallbackRegistry class to base/ to manage callbacks (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Much clean up and removal of unneeded bits Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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_
« base/callback_list.h ('K') | « base/callback_list.h ('k') | base/callback_list_internal.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698