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

Unified Diff: base/cancelable_callback.cc

Issue 8662047: base::Bind: Implement a 1-arity CancelableCallback and use this to implement (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comment fixes. 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
« no previous file with comments | « base/cancelable_callback.h ('k') | base/cancelable_callback_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/cancelable_callback.cc
diff --git a/base/cancelable_callback.cc b/base/cancelable_callback.cc
deleted file mode 100644
index da9777dfb93a7c19add93ea63b9545cc5b61ff02..0000000000000000000000000000000000000000
--- a/base/cancelable_callback.cc
+++ /dev/null
@@ -1,60 +0,0 @@
-// 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"
-
-#include "base/bind.h"
-#include "base/compiler_specific.h"
-#include "base/logging.h"
-
-namespace base {
-
-CancelableCallback::CancelableCallback()
- : ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
-}
-
-CancelableCallback::CancelableCallback(const base::Closure& callback)
- : ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)),
- callback_(callback) {
- DCHECK(!callback.is_null());
- InitializeForwarder();
-}
-
-CancelableCallback::~CancelableCallback() {}
-
-void CancelableCallback::Cancel() {
- weak_factory_.InvalidateWeakPtrs();
- callback_.Reset();
-}
-
-bool CancelableCallback::IsCancelled() const {
- return callback_.is_null();
-}
-
-void CancelableCallback::Reset(const base::Closure& callback) {
- DCHECK(!callback.is_null());
-
- // Outstanding tasks (e.g., posted to a message loop) must not be called.
- Cancel();
-
- // |forwarder_| is no longer valid after Cancel(), so re-bind.
- InitializeForwarder();
-
- callback_ = callback;
-}
-
-const base::Closure& CancelableCallback::callback() const {
- return forwarder_;
-}
-
-void CancelableCallback::RunCallback() {
- callback_.Run();
-}
-
-void CancelableCallback::InitializeForwarder() {
- forwarder_ = base::Bind(&CancelableCallback::RunCallback,
- weak_factory_.GetWeakPtr());
-}
-
-} // namespace bind
« no previous file with comments | « base/cancelable_callback.h ('k') | base/cancelable_callback_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698