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

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

Issue 20251: Extend the IOBuffer to the disk cache.... (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"
10 9
11 namespace net { 10 namespace net {
12 11
13 // A callback specialization that takes a single int parameter. Usually this 12 // A callback specialization that takes a single int parameter. Usually this
14 // is used to report a byte count or network error code. 13 // is used to report a byte count or network error code.
15 typedef Callback1<int>::Type CompletionCallback; 14 typedef Callback1<int>::Type CompletionCallback;
16 15
17 // Used to implement a CompletionCallback. 16 // Used to implement a CompletionCallback.
18 template <class T> 17 template <class T>
19 class CompletionCallbackImpl : 18 class CompletionCallbackImpl :
(...skipping 15 matching lines...) Expand all
35 public base::RefCounted<CancelableCompletionCallback<T> > { 34 public base::RefCounted<CancelableCompletionCallback<T> > {
36 public: 35 public:
37 CancelableCompletionCallback(T* obj, void (T::* meth)(int)) 36 CancelableCompletionCallback(T* obj, void (T::* meth)(int))
38 : CompletionCallbackImpl<T>(obj, meth), is_canceled_(false) { 37 : CompletionCallbackImpl<T>(obj, meth), is_canceled_(false) {
39 } 38 }
40 39
41 void Cancel() { 40 void Cancel() {
42 is_canceled_ = true; 41 is_canceled_ = true;
43 } 42 }
44 43
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
59 virtual void RunWithParams(const Tuple1<int>& params) { 44 virtual void RunWithParams(const Tuple1<int>& params) {
60 if (is_canceled_) { 45 if (is_canceled_) {
61 CancelableCompletionCallback<T>::ReleaseBuffer();
62 base::RefCounted<CancelableCompletionCallback<T> >::Release(); 46 base::RefCounted<CancelableCompletionCallback<T> >::Release();
63 } else { 47 } else {
64 CompletionCallbackImpl<T>::RunWithParams(params); 48 CompletionCallbackImpl<T>::RunWithParams(params);
65 } 49 }
66 } 50 }
67 51
68 private: 52 private:
69 scoped_refptr<net::IOBuffer> buffer_;
70 bool is_canceled_; 53 bool is_canceled_;
71 }; 54 };
72 55
73 } // namespace net 56 } // namespace net
74 57
75 #endif // NET_BASE_COMPLETION_CALLBACK_H__ 58 #endif // NET_BASE_COMPLETION_CALLBACK_H__
76 59
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