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

Unified Diff: base/cancelable_callback.cc

Issue 8673008: base::Bind: Implement CancelableCallback to replace CancelableTaske. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 1 month 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/cancelable_callback.cc
diff --git a/base/cancelable_callback.cc b/base/cancelable_callback.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ae06d5778218a4ed01158e14821f41eb9216d49d
--- /dev/null
+++ b/base/cancelable_callback.cc
@@ -0,0 +1,28 @@
+// Copyright (c) 2011 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.
+
+#include "base/cancelable_callback.h"
+
+namespace base {
+
+CancelableCallback::CancelableCallback(const base::Closure callback)
+ : ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)),
+ forwarder_(base::Bind(&CancelableCallback::RunCallback,
+ weak_factory_.GetWeakPtr())),
+ callback_(callback) {
binji 2011/11/23 02:21:44 check for !callback.is_null?
James Hawkins 2011/11/23 03:59:08 Done.
+}
+
+void CancelableCallback::Cancel() {
+ weak_factory_.InvalidateWeakPtrs();
+}
+
+const base::Closure& CancelableCallback::callback() const {
+ return forwarder_;
+}
+
+void CancelableCallback::RunCallback() {
+ callback_.Run();
+}
+
+}
groby-ooo-7-16 2011/11/23 02:14:12 nit: } // namespace base

Powered by Google App Engine
This is Rietveld 408576698