| 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 // ScopedCallbackFactory helps in cases where you wish to allocate a Callback | 5 // ScopedCallbackFactory helps in cases where you wish to allocate a Callback |
| 6 // (see base/callback.h), but need to prevent any pending callbacks from | 6 // (see base/callback.h), but need to prevent any pending callbacks from |
| 7 // executing when your object gets destroyed. | 7 // executing when your object gets destroyed. |
| 8 // | 8 // |
| 9 // EXAMPLE: | 9 // EXAMPLE: |
| 10 // | 10 // |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 // | 29 // |
| 30 // In the above example, the Process function calls GatherDataAsynchronously to | 30 // In the above example, the Process function calls GatherDataAsynchronously to |
| 31 // kick off some asynchronous processing that upon completion will notify a | 31 // kick off some asynchronous processing that upon completion will notify a |
| 32 // callback. If in the meantime, the MyClass instance is destroyed, when the | 32 // callback. If in the meantime, the MyClass instance is destroyed, when the |
| 33 // callback runs, it will notice that the MyClass instance is dead, and it will | 33 // callback runs, it will notice that the MyClass instance is dead, and it will |
| 34 // avoid calling the GotData method. | 34 // avoid calling the GotData method. |
| 35 | 35 |
| 36 #ifndef BASE_MEMORY_SCOPED_CALLBACK_FACTORY_H_ | 36 #ifndef BASE_MEMORY_SCOPED_CALLBACK_FACTORY_H_ |
| 37 #define BASE_MEMORY_SCOPED_CALLBACK_FACTORY_H_ | 37 #define BASE_MEMORY_SCOPED_CALLBACK_FACTORY_H_ |
| 38 | 38 |
| 39 #include "base/callback.h" | 39 #include "base/callback_old.h" |
| 40 #include "base/memory/weak_ptr.h" | 40 #include "base/memory/weak_ptr.h" |
| 41 | 41 |
| 42 namespace base { | 42 namespace base { |
| 43 | 43 |
| 44 template <class T> | 44 template <class T> |
| 45 class ScopedCallbackFactory { | 45 class ScopedCallbackFactory { |
| 46 public: | 46 public: |
| 47 explicit ScopedCallbackFactory(T* obj) : weak_factory_(obj) { | 47 explicit ScopedCallbackFactory(T* obj) : weak_factory_(obj) { |
| 48 } | 48 } |
| 49 | 49 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 DispatchToMethod(this->obj_.get(), this->meth_, params); | 124 DispatchToMethod(this->obj_.get(), this->meth_, params); |
| 125 } | 125 } |
| 126 }; | 126 }; |
| 127 | 127 |
| 128 WeakPtrFactory<T> weak_factory_; | 128 WeakPtrFactory<T> weak_factory_; |
| 129 }; | 129 }; |
| 130 | 130 |
| 131 } // namespace base | 131 } // namespace base |
| 132 | 132 |
| 133 #endif // BASE_MEMORY_SCOPED_CALLBACK_FACTORY_H_ | 133 #endif // BASE_MEMORY_SCOPED_CALLBACK_FACTORY_H_ |
| OLD | NEW |