| OLD | NEW |
| 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 Loading... |
| 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__ |
| OLD | NEW |