Chromium Code Reviews| 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" | |
| 10 #include "base/callback.h" | 9 #include "base/callback.h" |
| 11 #include "base/cancelable_callback.h" | 10 #include "base/cancelable_callback.h" |
| 12 #include "net/base/net_export.h" | 11 #include "net/base/net_export.h" |
|
groby-ooo-7-16
2012/01/03 18:32:25
Don't need that one any more.
James Hawkins
2012/01/03 18:39:21
Done.
| |
| 13 | 12 |
| 14 namespace net { | 13 namespace net { |
| 15 | 14 |
| 16 // A callback specialization that takes a single int parameter. Usually this | 15 // A callback specialization that takes a single int parameter. Usually this is |
| 17 // is used to report a byte count or network error code. | 16 // used to report a byte count or network error code. |
| 18 typedef Callback1<int>::Type OldCompletionCallback; | |
| 19 typedef base::Callback<void(int)> CompletionCallback; | 17 typedef base::Callback<void(int)> CompletionCallback; |
| 20 | 18 |
| 21 // Temporary (in the code) adapter of OldCompletionCallback for use at call | |
| 22 // sites that expect a CompletionCallback. | |
| 23 // | |
| 24 // TODO(jhawkins): Remove once OldCompletionCallback is removed. | |
| 25 void NET_EXPORT OldCompletionCallbackAdapter(OldCompletionCallback* callback, | |
| 26 int result); | |
| 27 | |
| 28 // Used to implement a OldCompletionCallback. | |
| 29 template <class T> | |
| 30 class OldCompletionCallbackImpl : | |
| 31 public CallbackImpl< T, void (T::*)(int), Tuple1<int> > { | |
| 32 public: | |
| 33 OldCompletionCallbackImpl(T* obj, void (T::* meth)(int)) | |
| 34 : CallbackImpl< T, void (T::*)(int), | |
| 35 Tuple1<int> >::CallbackImpl(obj, meth) { | |
| 36 } | |
| 37 }; | |
| 38 | |
| 39 typedef base::CancelableCallback<void(int)> CancelableCompletionCallback; | 19 typedef base::CancelableCallback<void(int)> CancelableCompletionCallback; |
| 40 | 20 |
| 41 // CancelableOldCompletionCallback is used for completion callbacks | |
| 42 // which may outlive the target for the method dispatch. In such a case, the | |
| 43 // provider of the callback calls Cancel() to mark the callback as | |
| 44 // "canceled". When the canceled callback is eventually run it does nothing | |
| 45 // other than to decrement the refcount to 0 and free the memory. | |
| 46 template <class T> | |
| 47 class CancelableOldCompletionCallback : | |
| 48 public OldCompletionCallbackImpl<T>, | |
| 49 public base::RefCounted<CancelableOldCompletionCallback<T> > { | |
| 50 public: | |
| 51 CancelableOldCompletionCallback(T* obj, void (T::* meth)(int)) | |
| 52 : OldCompletionCallbackImpl<T>(obj, meth), is_canceled_(false) { | |
| 53 } | |
| 54 | |
| 55 void Cancel() { | |
| 56 is_canceled_ = true; | |
| 57 } | |
| 58 | |
| 59 virtual void RunWithParams(const Tuple1<int>& params) { | |
| 60 if (is_canceled_) { | |
| 61 base::RefCounted<CancelableOldCompletionCallback<T> >::Release(); | |
| 62 } else { | |
| 63 OldCompletionCallbackImpl<T>::RunWithParams(params); | |
| 64 } | |
| 65 } | |
| 66 | |
| 67 private: | |
| 68 bool is_canceled_; | |
| 69 }; | |
| 70 | |
| 71 } // namespace net | 21 } // namespace net |
| 72 | 22 |
| 73 #endif // NET_BASE_COMPLETION_CALLBACK_H__ | 23 #endif // NET_BASE_COMPLETION_CALLBACK_H__ |
| OLD | NEW |