Chromium Code Reviews| Index: base/uber_callback_helpers.h |
| diff --git a/base/uber_callback_helpers.h b/base/uber_callback_helpers.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..652880c95eea2d4358606f12d4b44c72a9e1f450 |
| --- /dev/null |
| +++ b/base/uber_callback_helpers.h |
| @@ -0,0 +1,48 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +// This file contains utility functions and classes that help the implemenation, |
| +// and management of the Callback objects. |
| + |
| +#ifndef BASE_UBER_CALLBACK_HELPERS_H_ |
| +#define BASE_UBER_CALLBACK_HELPERS_H_ |
| +#pragma once |
| + |
| +#include "base/ref_counted.h" |
| + |
| +namespace base { |
| +namespace internal { |
| + |
| +// InvokerStorageBase is used to provide an opaque handle that the Callback |
| +// class can use to represent a function object with bound arguments. It |
| +// behaves as an existential type that is used by a corresponding |
| +// PolymorphicInvoke function to perform the function execution. This allows |
| +// us to shield the Callback class from the types of the bound argument via |
| +// "type erasure." |
| +// |
| +// TODO(ajwong): Explain the PolymorphicInvoke setup is more understandable |
| +// terms. |
| +class InvokerStorageBase : public RefCountedThreadSafe<InvokerStorageBase> { |
| + protected: |
| + friend class RefCountedThreadSafe<InvokerStorageBase>; |
| + virtual ~InvokerStorageBase() {} |
| +}; |
| + |
| +template <typename T> |
| +struct InvokerStorageHolder { |
| + explicit InvokerStorageHolder(T* invoker_storage) |
| + : invoker_storage_(invoker_storage) { |
| + } |
| + 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
|
| +}; |
| + |
| +template <typename T> |
| +InvokerStorageHolder<T> MakeInvokerStorageHolder(T* o) { |
| + return InvokerStorageHolder<T>(o); |
| +} |
| + |
| +} // namespace internal |
| +} // namespace base |
| + |
| +#endif // BASE_UBER_CALLBACK_HELPERS_H_ |