summaryrefslogtreecommitdiffstats
path: root/base/bind_internal.h
diff options
context:
space:
mode:
authorajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-01 06:31:41 +0000
committerajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-01 06:31:41 +0000
commit8217d454b2f96847028e9b0dbe7d82d66959ecb4 (patch)
treefc6ff9f433b1f09b56c54421d625c410bdac4882 /base/bind_internal.h
parent63a2ecf084a9f13418e100cca6689925bc9dfe96 (diff)
downloadchromium_src-8217d454b2f96847028e9b0dbe7d82d66959ecb4.zip
chromium_src-8217d454b2f96847028e9b0dbe7d82d66959ecb4.tar.gz
chromium_src-8217d454b2f96847028e9b0dbe7d82d66959ecb4.tar.bz2
Use NeedsScopedRefptrButGetsRawPtr instead of UnsafeBindtoRefCountedArg.
Will's implementation of NeedsScopedRefptrButGetsRawPtr checks for refcounting by testing for converability of the pointer values to base::RefCounted and base::RefCountedThreadsafe. This happens to tolerate incomplete types in a sane way on linux where the check is enabled. UnsafeBindtoRefCountedArg's impelmentation relies on introspecting the type for the existence of a member function. Though this will catch refcounted objects with a refcount API that are not derived from base::RefCounted and base::RefCountedThreadsafe it requires complete types which places too strong of a constraint on what kinds of arguments can be bound. Since the majority (all?) refcounted types in Chromium are derived from base::RefCounted and base::RefCountedThreadsafe, this should be just as good of a guarantee. Bug filed to see if there's a way to adapt UnsafeBindtoRefCountedArg. BUG=94995,98732 TEST=new unittest. Review URL: http://codereview.chromium.org/8101008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@103627 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/bind_internal.h')
-rw-r--r--base/bind_internal.h94
1 files changed, 58 insertions, 36 deletions
diff --git a/base/bind_internal.h b/base/bind_internal.h
index 404b795..7beba51 100644
--- a/base/bind_internal.h
+++ b/base/bind_internal.h
@@ -14,6 +14,7 @@
#include "base/bind_helpers.h"
#include "base/callback_internal.h"
+#include "base/memory/raw_scoped_refptr_mismatch_checker.h"
#include "base/memory/weak_ptr.h"
#include "base/template_util.h"
#include "build/build_config.h"
@@ -1815,7 +1816,8 @@ class InvokerStorage1 : public InvokerStorageBase {
// scoped_refptr check because the binder itself takes care of this. We also
// disallow binding of an array as the method's target object.
COMPILE_ASSERT(IsMethod::value ||
- !internal::UnsafeBindtoRefCountedArg<P1>::value,
+ internal::NeedsScopedRefptrButGetsRawPtr<
+ typename ParamTraits<P1>::StorageType>::value == 0,
p1_is_refcounted_type_and_needs_scoped_refptr);
COMPILE_ASSERT(!IsMethod::value || !is_array<P1>::value,
first_bound_argument_to_method_cannot_be_array);
@@ -1862,12 +1864,14 @@ class InvokerStorage2 : public InvokerStorageBase {
// scoped_refptr check because the binder itself takes care of this. We also
// disallow binding of an array as the method's target object.
COMPILE_ASSERT(IsMethod::value ||
- !internal::UnsafeBindtoRefCountedArg<P1>::value,
+ internal::NeedsScopedRefptrButGetsRawPtr<
+ typename ParamTraits<P1>::StorageType>::value == 0,
p1_is_refcounted_type_and_needs_scoped_refptr);
COMPILE_ASSERT(!IsMethod::value || !is_array<P1>::value,
first_bound_argument_to_method_cannot_be_array);
- COMPILE_ASSERT(!internal::UnsafeBindtoRefCountedArg<P2>::value,
- p2_is_refcounted_type_and_needs_scoped_refptr);
+ COMPILE_ASSERT(internal::NeedsScopedRefptrButGetsRawPtr<
+ typename ParamTraits<P2>::StorageType>::value == 0,
+ p2_is_refcounted_type_and_needs_scoped_refptr);
// Do not allow binding a non-const reference parameter. Non-const reference
// parameters are disallowed by the Google style guide. Also, binding a
@@ -1915,14 +1919,17 @@ class InvokerStorage3 : public InvokerStorageBase {
// scoped_refptr check because the binder itself takes care of this. We also
// disallow binding of an array as the method's target object.
COMPILE_ASSERT(IsMethod::value ||
- !internal::UnsafeBindtoRefCountedArg<P1>::value,
+ internal::NeedsScopedRefptrButGetsRawPtr<
+ typename ParamTraits<P1>::StorageType>::value == 0,
p1_is_refcounted_type_and_needs_scoped_refptr);
COMPILE_ASSERT(!IsMethod::value || !is_array<P1>::value,
first_bound_argument_to_method_cannot_be_array);
- COMPILE_ASSERT(!internal::UnsafeBindtoRefCountedArg<P2>::value,
- p2_is_refcounted_type_and_needs_scoped_refptr);
- COMPILE_ASSERT(!internal::UnsafeBindtoRefCountedArg<P3>::value,
- p3_is_refcounted_type_and_needs_scoped_refptr);
+ COMPILE_ASSERT(internal::NeedsScopedRefptrButGetsRawPtr<
+ typename ParamTraits<P2>::StorageType>::value == 0,
+ p2_is_refcounted_type_and_needs_scoped_refptr);
+ COMPILE_ASSERT(internal::NeedsScopedRefptrButGetsRawPtr<
+ typename ParamTraits<P3>::StorageType>::value == 0,
+ p3_is_refcounted_type_and_needs_scoped_refptr);
// Do not allow binding a non-const reference parameter. Non-const reference
// parameters are disallowed by the Google style guide. Also, binding a
@@ -1974,16 +1981,20 @@ class InvokerStorage4 : public InvokerStorageBase {
// scoped_refptr check because the binder itself takes care of this. We also
// disallow binding of an array as the method's target object.
COMPILE_ASSERT(IsMethod::value ||
- !internal::UnsafeBindtoRefCountedArg<P1>::value,
+ internal::NeedsScopedRefptrButGetsRawPtr<
+ typename ParamTraits<P1>::StorageType>::value == 0,
p1_is_refcounted_type_and_needs_scoped_refptr);
COMPILE_ASSERT(!IsMethod::value || !is_array<P1>::value,
first_bound_argument_to_method_cannot_be_array);
- COMPILE_ASSERT(!internal::UnsafeBindtoRefCountedArg<P2>::value,
- p2_is_refcounted_type_and_needs_scoped_refptr);
- COMPILE_ASSERT(!internal::UnsafeBindtoRefCountedArg<P3>::value,
- p3_is_refcounted_type_and_needs_scoped_refptr);
- COMPILE_ASSERT(!internal::UnsafeBindtoRefCountedArg<P4>::value,
- p4_is_refcounted_type_and_needs_scoped_refptr);
+ COMPILE_ASSERT(internal::NeedsScopedRefptrButGetsRawPtr<
+ typename ParamTraits<P2>::StorageType>::value == 0,
+ p2_is_refcounted_type_and_needs_scoped_refptr);
+ COMPILE_ASSERT(internal::NeedsScopedRefptrButGetsRawPtr<
+ typename ParamTraits<P3>::StorageType>::value == 0,
+ p3_is_refcounted_type_and_needs_scoped_refptr);
+ COMPILE_ASSERT(internal::NeedsScopedRefptrButGetsRawPtr<
+ typename ParamTraits<P4>::StorageType>::value == 0,
+ p4_is_refcounted_type_and_needs_scoped_refptr);
// Do not allow binding a non-const reference parameter. Non-const reference
// parameters are disallowed by the Google style guide. Also, binding a
@@ -2040,18 +2051,23 @@ class InvokerStorage5 : public InvokerStorageBase {
// scoped_refptr check because the binder itself takes care of this. We also
// disallow binding of an array as the method's target object.
COMPILE_ASSERT(IsMethod::value ||
- !internal::UnsafeBindtoRefCountedArg<P1>::value,
+ internal::NeedsScopedRefptrButGetsRawPtr<
+ typename ParamTraits<P1>::StorageType>::value == 0,
p1_is_refcounted_type_and_needs_scoped_refptr);
COMPILE_ASSERT(!IsMethod::value || !is_array<P1>::value,
first_bound_argument_to_method_cannot_be_array);
- COMPILE_ASSERT(!internal::UnsafeBindtoRefCountedArg<P2>::value,
- p2_is_refcounted_type_and_needs_scoped_refptr);
- COMPILE_ASSERT(!internal::UnsafeBindtoRefCountedArg<P3>::value,
- p3_is_refcounted_type_and_needs_scoped_refptr);
- COMPILE_ASSERT(!internal::UnsafeBindtoRefCountedArg<P4>::value,
- p4_is_refcounted_type_and_needs_scoped_refptr);
- COMPILE_ASSERT(!internal::UnsafeBindtoRefCountedArg<P5>::value,
- p5_is_refcounted_type_and_needs_scoped_refptr);
+ COMPILE_ASSERT(internal::NeedsScopedRefptrButGetsRawPtr<
+ typename ParamTraits<P2>::StorageType>::value == 0,
+ p2_is_refcounted_type_and_needs_scoped_refptr);
+ COMPILE_ASSERT(internal::NeedsScopedRefptrButGetsRawPtr<
+ typename ParamTraits<P3>::StorageType>::value == 0,
+ p3_is_refcounted_type_and_needs_scoped_refptr);
+ COMPILE_ASSERT(internal::NeedsScopedRefptrButGetsRawPtr<
+ typename ParamTraits<P4>::StorageType>::value == 0,
+ p4_is_refcounted_type_and_needs_scoped_refptr);
+ COMPILE_ASSERT(internal::NeedsScopedRefptrButGetsRawPtr<
+ typename ParamTraits<P5>::StorageType>::value == 0,
+ p5_is_refcounted_type_and_needs_scoped_refptr);
// Do not allow binding a non-const reference parameter. Non-const reference
// parameters are disallowed by the Google style guide. Also, binding a
@@ -2113,20 +2129,26 @@ class InvokerStorage6 : public InvokerStorageBase {
// scoped_refptr check because the binder itself takes care of this. We also
// disallow binding of an array as the method's target object.
COMPILE_ASSERT(IsMethod::value ||
- !internal::UnsafeBindtoRefCountedArg<P1>::value,
+ internal::NeedsScopedRefptrButGetsRawPtr<
+ typename ParamTraits<P1>::StorageType>::value == 0,
p1_is_refcounted_type_and_needs_scoped_refptr);
COMPILE_ASSERT(!IsMethod::value || !is_array<P1>::value,
first_bound_argument_to_method_cannot_be_array);
- COMPILE_ASSERT(!internal::UnsafeBindtoRefCountedArg<P2>::value,
- p2_is_refcounted_type_and_needs_scoped_refptr);
- COMPILE_ASSERT(!internal::UnsafeBindtoRefCountedArg<P3>::value,
- p3_is_refcounted_type_and_needs_scoped_refptr);
- COMPILE_ASSERT(!internal::UnsafeBindtoRefCountedArg<P4>::value,
- p4_is_refcounted_type_and_needs_scoped_refptr);
- COMPILE_ASSERT(!internal::UnsafeBindtoRefCountedArg<P5>::value,
- p5_is_refcounted_type_and_needs_scoped_refptr);
- COMPILE_ASSERT(!internal::UnsafeBindtoRefCountedArg<P6>::value,
- p6_is_refcounted_type_and_needs_scoped_refptr);
+ COMPILE_ASSERT(internal::NeedsScopedRefptrButGetsRawPtr<
+ typename ParamTraits<P2>::StorageType>::value == 0,
+ p2_is_refcounted_type_and_needs_scoped_refptr);
+ COMPILE_ASSERT(internal::NeedsScopedRefptrButGetsRawPtr<
+ typename ParamTraits<P3>::StorageType>::value == 0,
+ p3_is_refcounted_type_and_needs_scoped_refptr);
+ COMPILE_ASSERT(internal::NeedsScopedRefptrButGetsRawPtr<
+ typename ParamTraits<P4>::StorageType>::value == 0,
+ p4_is_refcounted_type_and_needs_scoped_refptr);
+ COMPILE_ASSERT(internal::NeedsScopedRefptrButGetsRawPtr<
+ typename ParamTraits<P5>::StorageType>::value == 0,
+ p5_is_refcounted_type_and_needs_scoped_refptr);
+ COMPILE_ASSERT(internal::NeedsScopedRefptrButGetsRawPtr<
+ typename ParamTraits<P6>::StorageType>::value == 0,
+ p6_is_refcounted_type_and_needs_scoped_refptr);
// Do not allow binding a non-const reference parameter. Non-const reference
// parameters are disallowed by the Google style guide. Also, binding a