| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // This file contains utility functions and classes that help the | 5 // This file contains utility functions and classes that help the |
| 6 // implementation, and management of the Callback objects. | 6 // implementation, and management of the Callback objects. |
| 7 | 7 |
| 8 #ifndef BASE_CALLBACK_INTERNAL_H_ | 8 #ifndef BASE_CALLBACK_INTERNAL_H_ |
| 9 #define BASE_CALLBACK_INTERNAL_H_ | 9 #define BASE_CALLBACK_INTERNAL_H_ |
| 10 | 10 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 // CallbackBase<MoveOnly> is a direct base class of MoveOnly callbacks, and | 57 // CallbackBase<MoveOnly> is a direct base class of MoveOnly callbacks, and |
| 58 // CallbackBase<Copyable> uses CallbackBase<MoveOnly> for its implementation. | 58 // CallbackBase<Copyable> uses CallbackBase<MoveOnly> for its implementation. |
| 59 template <> | 59 template <> |
| 60 class BASE_EXPORT CallbackBase<CopyMode::MoveOnly> { | 60 class BASE_EXPORT CallbackBase<CopyMode::MoveOnly> { |
| 61 public: | 61 public: |
| 62 CallbackBase(CallbackBase&& c); | 62 CallbackBase(CallbackBase&& c); |
| 63 CallbackBase& operator=(CallbackBase&& c); | 63 CallbackBase& operator=(CallbackBase&& c); |
| 64 | 64 |
| 65 // Returns true if Callback is null (doesn't refer to anything). | 65 // Returns true if Callback is null (doesn't refer to anything). |
| 66 bool is_null() const { return bind_state_.get() == NULL; } | 66 bool is_null() const { return bind_state_.get() == NULL; } |
| 67 explicit operator bool() const { return !is_null(); } |
| 67 | 68 |
| 68 // Returns the Callback into an uninitialized state. | 69 // Returns the Callback into an uninitialized state. |
| 69 void Reset(); | 70 void Reset(); |
| 70 | 71 |
| 71 protected: | 72 protected: |
| 72 // In C++, it is safe to cast function pointers to function pointers of | 73 // In C++, it is safe to cast function pointers to function pointers of |
| 73 // another type. It is not okay to use void*. We create a InvokeFuncStorage | 74 // another type. It is not okay to use void*. We create a InvokeFuncStorage |
| 74 // that that can store our function pointer, and then cast it back to | 75 // that that can store our function pointer, and then cast it back to |
| 75 // the original type on usage. | 76 // the original type on usage. |
| 76 using InvokeFuncStorage = void(*)(); | 77 using InvokeFuncStorage = void(*)(); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 ~CallbackBase() {} | 109 ~CallbackBase() {} |
| 109 }; | 110 }; |
| 110 | 111 |
| 111 extern template class CallbackBase<CopyMode::MoveOnly>; | 112 extern template class CallbackBase<CopyMode::MoveOnly>; |
| 112 extern template class CallbackBase<CopyMode::Copyable>; | 113 extern template class CallbackBase<CopyMode::Copyable>; |
| 113 | 114 |
| 114 } // namespace internal | 115 } // namespace internal |
| 115 } // namespace base | 116 } // namespace base |
| 116 | 117 |
| 117 #endif // BASE_CALLBACK_INTERNAL_H_ | 118 #endif // BASE_CALLBACK_INTERNAL_H_ |
| OLD | NEW |