Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 // This file contains utility functions and classes that help the implemenation, | |
| 6 // and management of the Callback objects. | |
| 7 | |
| 8 #ifndef BASE_UBER_CALLBACK_HELPERS_H_ | |
| 9 #define BASE_UBER_CALLBACK_HELPERS_H_ | |
| 10 #pragma once | |
| 11 | |
| 12 #include "base/ref_counted.h" | |
| 13 | |
| 14 namespace base { | |
| 15 namespace internal { | |
| 16 | |
| 17 // InvokerStorageBase is used to provide an opaque handle that the Callback | |
| 18 // class can use to represent a function object with bound arguments. It | |
| 19 // behaves as an existential type that is used by a corresponding | |
| 20 // PolymorphicInvoke function to perform the function execution. This allows | |
| 21 // us to shield the Callback class from the types of the bound argument via | |
| 22 // "type erasure." | |
| 23 // | |
| 24 // TODO(ajwong): Explain the PolymorphicInvoke setup is more understandable | |
| 25 // terms. | |
| 26 class InvokerStorageBase : public RefCountedThreadSafe<InvokerStorageBase> { | |
| 27 protected: | |
| 28 friend class RefCountedThreadSafe<InvokerStorageBase>; | |
| 29 virtual ~InvokerStorageBase() {} | |
| 30 }; | |
| 31 | |
| 32 template <typename T> | |
| 33 struct InvokerStorageHolder { | |
| 34 explicit InvokerStorageHolder(T* invoker_storage) | |
| 35 : invoker_storage_(invoker_storage) { | |
| 36 } | |
| 37 mutable scoped_refptr<InvokerStorageBase> invoker_storage_; | |
|
willchan no longer on Chromium
2011/02/06 10:26:50
in structs, you don't use the trailing underscore
| |
| 38 }; | |
| 39 | |
| 40 template <typename T> | |
| 41 InvokerStorageHolder<T> MakeInvokerStorageHolder(T* o) { | |
| 42 return InvokerStorageHolder<T>(o); | |
| 43 } | |
| 44 | |
| 45 } // namespace internal | |
| 46 } // namespace base | |
| 47 | |
| 48 #endif // BASE_UBER_CALLBACK_HELPERS_H_ | |
| OLD | NEW |