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

Unified Diff: content/browser/cancelable_request.cc

Issue 8068013: Add interface to CancelableRequest that allows use of base::Callback<>. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address brett's comments. Created 9 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
« no previous file with comments | « content/browser/cancelable_request.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/cancelable_request.cc
diff --git a/content/browser/cancelable_request.cc b/content/browser/cancelable_request.cc
index 3b1816fec465a6a667bc1bf00e260e50e2b94a66..9a42d6290a7169cdb71cff2bb7e235bcd3df387c 100644
--- a/content/browser/cancelable_request.cc
+++ b/content/browser/cancelable_request.cc
@@ -107,3 +107,34 @@ void CancelableRequestBase::Init(CancelableRequestProvider* provider,
consumer_ = consumer;
handle_ = handle;
}
+
+void CancelableRequestBase::DoForward(const base::Closure& forwarded_call,
+ bool force_async) {
+ if (force_async || callback_thread_ != MessageLoop::current()) {
+ callback_thread_->PostTask(
+ FROM_HERE,
+ base::Bind(&CancelableRequestBase::ExecuteCallback, this,
+ forwarded_call));
+ } else {
+ // We can do synchronous callbacks when we're on the same thread.
+ ExecuteCallback(forwarded_call);
+ }
+}
+
+void CancelableRequestBase::ExecuteCallback(
+ const base::Closure& forwarded_call) {
+ DCHECK_EQ(callback_thread_, MessageLoop::current());
+
+ if (!canceled_.IsSet()) {
+ WillExecute();
+
+ // Execute the callback.
+ forwarded_call.Run();
+ }
+
+ // Notify the provider that the request is complete. The provider will
+ // notify the consumer for us. Note that it is possible for the callback to
+ // cancel this request; we must check canceled again.
+ if (!canceled_.IsSet())
+ NotifyCompleted();
+}
« no previous file with comments | « content/browser/cancelable_request.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698