| OLD | NEW |
| 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 | 9 |
| 10 namespace net { | 10 namespace net { |
| 11 | 11 |
| 12 // A callback specialization that takes a single int parameter. Usually this | 12 // A callback specialization that takes a single int parameter. Usually this |
| 13 // is used to report a byte count or network error code. | 13 // is used to report a byte count or network error code. |
| 14 typedef Callback1<int>::Type CompletionCallback; | 14 typedef Callback1<int>::Type CompletionCallback; |
| 15 | 15 |
| 16 // Used to implement a CompletionCallback. | 16 // Used to implement a CompletionCallback. |
| 17 template <class T> | 17 template <class T> |
| 18 class CompletionCallbackImpl : | 18 class CompletionCallbackImpl : |
| 19 public CallbackImpl< T, void (T::*)(int), Tuple1<int> > { | 19 public CallbackImpl< T, void (T::*)(int), Tuple1<int> > { |
| 20 public: | 20 public: |
| 21 CompletionCallbackImpl(T* obj, void (T::* meth)(int)) | 21 CompletionCallbackImpl(T* obj, void (T::* meth)(int)) |
| 22 : CallbackImpl< T, void (T::*)(int), Tuple1<int> >::CallbackImpl(obj, meth)
{ | 22 : CallbackImpl< T, void (T::*)(int), |
| 23 Tuple1<int> >::CallbackImpl(obj, meth) { |
| 23 } | 24 } |
| 24 }; | 25 }; |
| 25 | 26 |
| 26 // CancelableCompletionCallback is used for completion callbacks | 27 // CancelableCompletionCallback is used for completion callbacks |
| 27 // which may outlive the target for the method dispatch. In such a case, the | 28 // which may outlive the target for the method dispatch. In such a case, the |
| 28 // provider of the callback calls Cancel() to mark the callback as | 29 // provider of the callback calls Cancel() to mark the callback as |
| 29 // "canceled". When the canceled callback is eventually run it does nothing | 30 // "canceled". When the canceled callback is eventually run it does nothing |
| 30 // other than to decrement the refcount to 0 and free the memory. | 31 // other than to decrement the refcount to 0 and free the memory. |
| 31 template <class T> | 32 template <class T> |
| 32 class CancelableCompletionCallback : | 33 class CancelableCompletionCallback : |
| (...skipping 17 matching lines...) Expand all Loading... |
| 50 } | 51 } |
| 51 | 52 |
| 52 private: | 53 private: |
| 53 bool is_canceled_; | 54 bool is_canceled_; |
| 54 }; | 55 }; |
| 55 | 56 |
| 56 } // namespace net | 57 } // namespace net |
| 57 | 58 |
| 58 #endif // NET_BASE_COMPLETION_CALLBACK_H__ | 59 #endif // NET_BASE_COMPLETION_CALLBACK_H__ |
| 59 | 60 |
| OLD | NEW |