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

Side by Side 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, 2 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/browser/cancelable_request.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/cancelable_request.h" 5 #include "content/browser/cancelable_request.h"
6 6
7 CancelableRequestProvider::CancelableRequestProvider() 7 CancelableRequestProvider::CancelableRequestProvider()
8 : next_handle_(1) { 8 : next_handle_(1) {
9 } 9 }
10 10
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 } 100 }
101 101
102 void CancelableRequestBase::Init(CancelableRequestProvider* provider, 102 void CancelableRequestBase::Init(CancelableRequestProvider* provider,
103 CancelableRequestProvider::Handle handle, 103 CancelableRequestProvider::Handle handle,
104 CancelableRequestConsumerBase* consumer) { 104 CancelableRequestConsumerBase* consumer) {
105 DCHECK(handle_ == 0 && provider_ == NULL && consumer_ == NULL); 105 DCHECK(handle_ == 0 && provider_ == NULL && consumer_ == NULL);
106 provider_ = provider; 106 provider_ = provider;
107 consumer_ = consumer; 107 consumer_ = consumer;
108 handle_ = handle; 108 handle_ = handle;
109 } 109 }
110
111 void CancelableRequestBase::DoForward(const base::Closure& forwarded_call,
112 bool force_async) {
113 if (force_async || callback_thread_ != MessageLoop::current()) {
114 callback_thread_->PostTask(
115 FROM_HERE,
116 base::Bind(&CancelableRequestBase::ExecuteCallback, this,
117 forwarded_call));
118 } else {
119 // We can do synchronous callbacks when we're on the same thread.
120 ExecuteCallback(forwarded_call);
121 }
122 }
123
124 void CancelableRequestBase::ExecuteCallback(
125 const base::Closure& forwarded_call) {
126 DCHECK_EQ(callback_thread_, MessageLoop::current());
127
128 if (!canceled_.IsSet()) {
129 WillExecute();
130
131 // Execute the callback.
132 forwarded_call.Run();
133 }
134
135 // Notify the provider that the request is complete. The provider will
136 // notify the consumer for us. Note that it is possible for the callback to
137 // cancel this request; we must check canceled again.
138 if (!canceled_.IsSet())
139 NotifyCompleted();
140 }
OLDNEW
« 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