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

Unified Diff: base/callback_list.cc

Issue 22877038: Add a CallbackRegistry class to base/ to manage callbacks (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Better documentation of test invariants Created 7 years, 4 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.cc
diff --git a/base/callback_list.cc b/base/callback_list.cc
new file mode 100644
index 0000000000000000000000000000000000000000..283b6cf0b96d2d6a63c5e1bcf9fe2b01e53cbc3c
--- /dev/null
+++ b/base/callback_list.cc
@@ -0,0 +1,33 @@
+#include "base/callback_list.h"
awong 2013/09/04 18:48:21 Missing copyright.
Cait (Slow) 2013/09/04 22:09:25 Done.
+
+namespace base {
+
+CallbackList::CallbackList(CallbackNotificationType type)
+ : list_impl_(new base::internal::CallbackListImpl(type)) {}
+
+CallbackList::~CallbackList() {}
+
+base::Closure CallbackList::Add(const base::Closure& cb) {
+ DCHECK(!cb.is_null());
+ return list_impl_->AddCallback(new base::Closure(cb));
+}
+
+void CallbackList::Run() {
+ if (might_have_callbacks()) {
+ internal::CallbackListImpl::Iterator it(list_impl_->GetWeakPtr());
+ base::Closure* cb;
+ while((cb = static_cast<base::Closure*>(it.GetNext())) != NULL) {
+ cb->Run();
+ }
+ }
+}
+
+void CallbackList::Clear() {
+ list_impl_->Clear();
+}
+
+bool CallbackList::might_have_callbacks() {
+ return list_impl_->might_have_callbacks();
+}
+
+} // namespace base
awong 2013/09/04 18:48:21 } // namespace base
Cait (Slow) 2013/09/04 22:09:25 Done.

Powered by Google App Engine
This is Rietveld 408576698