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

Side by Side Diff: net/base/completion_callback.h

Issue 21236: Revert cl 9528 to fix mac test_shell_tests (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 10 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 | « no previous file | net/base/io_buffer.h » ('j') | 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 #ifndef NET_BASE_COMPLETION_CALLBACK_H__ 5 #ifndef NET_BASE_COMPLETION_CALLBACK_H__
6 #define NET_BASE_COMPLETION_CALLBACK_H__ 6 #define NET_BASE_COMPLETION_CALLBACK_H__
7 7
8 #include "base/task.h" 8 #include "base/task.h"
9 #include "net/base/io_buffer.h"
9 10
10 namespace net { 11 namespace net {
11 12
12 // A callback specialization that takes a single int parameter. Usually this 13 // A callback specialization that takes a single int parameter. Usually this
13 // is used to report a byte count or network error code. 14 // is used to report a byte count or network error code.
14 typedef Callback1<int>::Type CompletionCallback; 15 typedef Callback1<int>::Type CompletionCallback;
15 16
16 // Used to implement a CompletionCallback. 17 // Used to implement a CompletionCallback.
17 template <class T> 18 template <class T>
18 class CompletionCallbackImpl : 19 class CompletionCallbackImpl :
(...skipping 15 matching lines...) Expand all
34 public base::RefCounted<CancelableCompletionCallback<T> > { 35 public base::RefCounted<CancelableCompletionCallback<T> > {
35 public: 36 public:
36 CancelableCompletionCallback(T* obj, void (T::* meth)(int)) 37 CancelableCompletionCallback(T* obj, void (T::* meth)(int))
37 : CompletionCallbackImpl<T>(obj, meth), is_canceled_(false) { 38 : CompletionCallbackImpl<T>(obj, meth), is_canceled_(false) {
38 } 39 }
39 40
40 void Cancel() { 41 void Cancel() {
41 is_canceled_ = true; 42 is_canceled_ = true;
42 } 43 }
43 44
45 // Attaches the given buffer to this callback so it is valid until the
46 // operation completes. TODO(rvargas): This is a temporal fix for bug 5325
47 // while I send IOBuffer to the lower layers of code.
48 void UseBuffer(net::IOBuffer* buffer) {
49 DCHECK(!buffer_.get());
50 buffer_ = buffer;
51 }
52
53 // The callback is not expected anymore so release the buffer.
54 void ReleaseBuffer() {
55 DCHECK(buffer_.get());
56 buffer_ = NULL;
57 }
58
44 virtual void RunWithParams(const Tuple1<int>& params) { 59 virtual void RunWithParams(const Tuple1<int>& params) {
45 if (is_canceled_) { 60 if (is_canceled_) {
61 CancelableCompletionCallback<T>::ReleaseBuffer();
46 base::RefCounted<CancelableCompletionCallback<T> >::Release(); 62 base::RefCounted<CancelableCompletionCallback<T> >::Release();
47 } else { 63 } else {
48 CompletionCallbackImpl<T>::RunWithParams(params); 64 CompletionCallbackImpl<T>::RunWithParams(params);
49 } 65 }
50 } 66 }
51 67
52 private: 68 private:
69 scoped_refptr<net::IOBuffer> buffer_;
53 bool is_canceled_; 70 bool is_canceled_;
54 }; 71 };
55 72
56 } // namespace net 73 } // namespace net
57 74
58 #endif // NET_BASE_COMPLETION_CALLBACK_H__ 75 #endif // NET_BASE_COMPLETION_CALLBACK_H__
59 76
OLDNEW
« no previous file with comments | « no previous file | net/base/io_buffer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698