diff options
-rw-r--r-- | base/base.gypi | 3 | ||||
-rw-r--r-- | base/bind.h | 2 | ||||
-rw-r--r-- | base/bind.h.pump | 2 | ||||
-rw-r--r-- | base/bind_internal.h | 2 | ||||
-rw-r--r-- | base/bind_internal.h.pump | 2 | ||||
-rw-r--r-- | base/callback.h | 45 | ||||
-rw-r--r-- | base/callback.h.pump | 45 | ||||
-rw-r--r-- | base/callback_helpers.h (renamed from base/callback_internal.h) | 37 | ||||
-rw-r--r-- | base/callback_internal.cc | 33 | ||||
-rw-r--r-- | base/callback_unittest.cc | 2 |
10 files changed, 97 insertions, 76 deletions
diff --git a/base/base.gypi b/base/base.gypi index 13cb1ba..79ba5f4 100644 --- a/base/base.gypi +++ b/base/base.gypi @@ -42,8 +42,7 @@ 'bits.h', 'bzip2_error_handler.cc', 'callback.h', - 'callback_internal.cc', - 'callback_internal.h', + 'callback_helpers.h', 'callback_old.h', 'command_line.cc', 'command_line.h', diff --git a/base/bind.h b/base/bind.h index cd9eb19..c23af2e 100644 --- a/base/bind.h +++ b/base/bind.h @@ -12,7 +12,7 @@ #pragma once #include "base/bind_internal.h" -#include "base/callback_internal.h" +#include "base/callback_helpers.h" // See base/callback.h for how to use these functions. // diff --git a/base/bind.h.pump b/base/bind.h.pump index 62b313f..fc7f246 100644 --- a/base/bind.h.pump +++ b/base/bind.h.pump @@ -16,7 +16,7 @@ $var MAX_ARITY = 6 #pragma once #include "base/bind_internal.h" -#include "base/callback_internal.h" +#include "base/callback_helpers.h" // See base/callback.h for how to use these functions. // diff --git a/base/bind_internal.h b/base/bind_internal.h index dd8afde..62f2050 100644 --- a/base/bind_internal.h +++ b/base/bind_internal.h @@ -12,7 +12,7 @@ #pragma once #include "base/bind_helpers.h" -#include "base/callback_internal.h" +#include "base/callback_helpers.h" #include "base/template_util.h" namespace base { diff --git a/base/bind_internal.h.pump b/base/bind_internal.h.pump index 6fd95fe..132b0db 100644 --- a/base/bind_internal.h.pump +++ b/base/bind_internal.h.pump @@ -16,7 +16,7 @@ $var MAX_ARITY = 6 #pragma once #include "base/bind_helpers.h" -#include "base/callback_internal.h" +#include "base/callback_helpers.h" #include "base/template_util.h" namespace base { diff --git a/base/callback.h b/base/callback.h index 9c76aa5..9e43afb 100644 --- a/base/callback.h +++ b/base/callback.h @@ -11,7 +11,7 @@ #define BASE_CALLBACK_H_ #pragma once -#include "base/callback_internal.h" +#include "base/callback_helpers.h" #include "base/callback_old.h" // New, super-duper, unified Callback system. This will eventually replace @@ -212,6 +212,49 @@ namespace base { +namespace internal { + +// Holds the methods that don't require specialization to reduce template bloat. +class CallbackBase { + public: + // Returns true if Callback is null (doesn't refer to anything). + bool is_null() const { + return invoker_storage_.get() == NULL; + } + + // Returns the Callback into an uninitalized state. + void Reset() { + invoker_storage_ = NULL; + polymorphic_invoke_ = NULL; + } + + bool Equals(const CallbackBase& other) const { + return invoker_storage_.get() == other.invoker_storage_.get() && + polymorphic_invoke_ == other.polymorphic_invoke_; + } + + protected: + // In C++, it is safe to cast function pointers to function pointers of + // another type. It is not okay to use void*. We create a InvokeFuncStorage + // that that can store our function pointer, and then cast it back to + // the original type on usage. + typedef void(*InvokeFuncStorage)(void); + + CallbackBase(InvokeFuncStorage polymorphic_invoke, + scoped_refptr<InvokerStorageBase>* invoker_storage) + : polymorphic_invoke_(polymorphic_invoke) { + if (invoker_storage) { + invoker_storage_.swap(*invoker_storage); + } + } + + scoped_refptr<InvokerStorageBase> invoker_storage_; + InvokeFuncStorage polymorphic_invoke_; +}; + +} // namespace internal + + // First, we forward declare the Callback class template. This informs the // compiler that the template only has 1 type parameter which is the function // signature that the Callback is representing. diff --git a/base/callback.h.pump b/base/callback.h.pump index 2efe0c5..19b7987 100644 --- a/base/callback.h.pump +++ b/base/callback.h.pump @@ -15,7 +15,7 @@ $var MAX_ARITY = 6 #define BASE_CALLBACK_H_ #pragma once -#include "base/callback_internal.h" +#include "base/callback_helpers.h" #include "base/callback_old.h" // New, super-duper, unified Callback system. This will eventually replace @@ -216,6 +216,49 @@ $var MAX_ARITY = 6 namespace base { +namespace internal { + +// Holds the methods that don't require specialization to reduce template bloat. +class CallbackBase { + public: + // Returns true if Callback is null (doesn't refer to anything). + bool is_null() const { + return invoker_storage_.get() == NULL; + } + + // Returns the Callback into an uninitalized state. + void Reset() { + invoker_storage_ = NULL; + polymorphic_invoke_ = NULL; + } + + bool Equals(const CallbackBase& other) const { + return invoker_storage_.get() == other.invoker_storage_.get() && + polymorphic_invoke_ == other.polymorphic_invoke_; + } + + protected: + // In C++, it is safe to cast function pointers to function pointers of + // another type. It is not okay to use void*. We create a InvokeFuncStorage + // that that can store our function pointer, and then cast it back to + // the original type on usage. + typedef void(*InvokeFuncStorage)(void); + + CallbackBase(InvokeFuncStorage polymorphic_invoke, + scoped_refptr<InvokerStorageBase>* invoker_storage) + : polymorphic_invoke_(polymorphic_invoke) { + if (invoker_storage) { + invoker_storage_.swap(*invoker_storage); + } + } + + scoped_refptr<InvokerStorageBase> invoker_storage_; + InvokeFuncStorage polymorphic_invoke_; +}; + +} // namespace internal + + // First, we forward declare the Callback class template. This informs the // compiler that the template only has 1 type parameter which is the function // signature that the Callback is representing. diff --git a/base/callback_internal.h b/base/callback_helpers.h index 4f1d3c3..86b0df1 100644 --- a/base/callback_internal.h +++ b/base/callback_helpers.h @@ -5,8 +5,8 @@ // This file contains utility functions and classes that help the // implementation, and management of the Callback objects. -#ifndef BASE_CALLBACK_INTERNAL_H_ -#define BASE_CALLBACK_INTERNAL_H_ +#ifndef BASE_CALLBACK_HELPERS_H_ +#define BASE_CALLBACK_HELPERS_H_ #pragma once #include "base/ref_counted.h" @@ -49,38 +49,7 @@ InvokerStorageHolder<T> MakeInvokerStorageHolder(T* o) { return InvokerStorageHolder<T>(o); } -// Holds the Callback methods that don't require specialization to reduce -// template bloat. -class CallbackBase { - public: - // Returns true if Callback is null (doesn't refer to anything). - bool is_null() const; - - // Returns the Callback into an uninitalized state. - void Reset(); - - bool Equals(const CallbackBase& other) const; - - protected: - // In C++, it is safe to cast function pointers to function pointers of - // another type. It is not okay to use void*. We create a InvokeFuncStorage - // that that can store our function pointer, and then cast it back to - // the original type on usage. - typedef void(*InvokeFuncStorage)(void); - - CallbackBase(InvokeFuncStorage polymorphic_invoke, - scoped_refptr<InvokerStorageBase>* invoker_storage); - - // Force the destructor to be instaniated inside this translation unit so - // that our subclasses will not get inlined versions. Avoids more template - // bloat. - ~CallbackBase(); - - scoped_refptr<InvokerStorageBase> invoker_storage_; - InvokeFuncStorage polymorphic_invoke_; -}; - } // namespace internal } // namespace base -#endif // BASE_CALLBACK_INTERNAL_H_ +#endif // BASE_CALLBACK_HELPERS_H_ diff --git a/base/callback_internal.cc b/base/callback_internal.cc deleted file mode 100644 index 979543e..0000000 --- a/base/callback_internal.cc +++ /dev/null @@ -1,33 +0,0 @@ -// 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. - -#include "base/callback_internal.h" - -namespace base { -namespace internal { - -bool CallbackBase::is_null() const { - return invoker_storage_.get() == NULL; -} - -void CallbackBase::Reset() { - invoker_storage_ = NULL; - polymorphic_invoke_ = NULL; -} - -bool CallbackBase::Equals(const CallbackBase& other) const { - return invoker_storage_.get() == other.invoker_storage_.get() && - polymorphic_invoke_ == other.polymorphic_invoke_; -} - -CallbackBase::CallbackBase(InvokeFuncStorage polymorphic_invoke, - scoped_refptr<InvokerStorageBase>* invoker_storage) - : polymorphic_invoke_(polymorphic_invoke) { - if (invoker_storage) { - invoker_storage_.swap(*invoker_storage); - } -} - -} // namespace base -} // namespace internal diff --git a/base/callback_unittest.cc b/base/callback_unittest.cc index e41b399..bf2b606 100644 --- a/base/callback_unittest.cc +++ b/base/callback_unittest.cc @@ -3,7 +3,7 @@ // found in the LICENSE file. #include "base/callback.h" -#include "base/callback_internal.h" +#include "base/callback_helpers.h" #include "base/scoped_ptr.h" #include "testing/gtest/include/gtest/gtest.h" |