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

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

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 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
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 #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 #pragma once 7 #pragma once
8 8
9 #include "base/callback_old.h" 9 #include "base/callback_old.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/cancelable_callback.h"
11 12
12 namespace net { 13 namespace net {
13 14
14 // A callback specialization that takes a single int parameter. Usually this 15 // A callback specialization that takes a single int parameter. Usually this
15 // is used to report a byte count or network error code. 16 // is used to report a byte count or network error code.
16 typedef Callback1<int>::Type OldCompletionCallback; 17 typedef Callback1<int>::Type OldCompletionCallback;
17 typedef base::Callback<void(int)> CompletionCallback; 18 typedef base::Callback<void(int)> CompletionCallback;
18 19
19 // Used to implement a OldCompletionCallback. 20 // Used to implement a OldCompletionCallback.
20 template <class T> 21 template <class T>
21 class OldCompletionCallbackImpl : 22 class OldCompletionCallbackImpl :
22 public CallbackImpl< T, void (T::*)(int), Tuple1<int> > { 23 public CallbackImpl< T, void (T::*)(int), Tuple1<int> > {
23 public: 24 public:
24 OldCompletionCallbackImpl(T* obj, void (T::* meth)(int)) 25 OldCompletionCallbackImpl(T* obj, void (T::* meth)(int))
25 : CallbackImpl< T, void (T::*)(int), 26 : CallbackImpl< T, void (T::*)(int),
26 Tuple1<int> >::CallbackImpl(obj, meth) { 27 Tuple1<int> >::CallbackImpl(obj, meth) {
27 } 28 }
28 }; 29 };
29 30
31 typedef base::CancelableCallback<void(int)> CancelableCompletionCallback;
32
30 // CancelableOldCompletionCallback is used for completion callbacks 33 // CancelableOldCompletionCallback is used for completion callbacks
31 // which may outlive the target for the method dispatch. In such a case, the 34 // which may outlive the target for the method dispatch. In such a case, the
32 // provider of the callback calls Cancel() to mark the callback as 35 // provider of the callback calls Cancel() to mark the callback as
33 // "canceled". When the canceled callback is eventually run it does nothing 36 // "canceled". When the canceled callback is eventually run it does nothing
34 // other than to decrement the refcount to 0 and free the memory. 37 // other than to decrement the refcount to 0 and free the memory.
35 template <class T> 38 template <class T>
36 class CancelableOldCompletionCallback : 39 class CancelableOldCompletionCallback :
37 public OldCompletionCallbackImpl<T>, 40 public OldCompletionCallbackImpl<T>,
38 public base::RefCounted<CancelableOldCompletionCallback<T> > { 41 public base::RefCounted<CancelableOldCompletionCallback<T> > {
39 public: 42 public:
(...skipping 13 matching lines...) Expand all
53 } 56 }
54 } 57 }
55 58
56 private: 59 private:
57 bool is_canceled_; 60 bool is_canceled_;
58 }; 61 };
59 62
60 } // namespace net 63 } // namespace net
61 64
62 #endif // NET_BASE_COMPLETION_CALLBACK_H__ 65 #endif // NET_BASE_COMPLETION_CALLBACK_H__
OLDNEW
« no previous file with comments | « chrome/browser/renderer_host/offline_resource_handler.cc ('k') | webkit/appcache/appcache_group.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698