Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(173)

Side by Side Diff: base/callback_internal.h

Issue 2344143002: Add const to BindStateBase to align RefCounted constness (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/bind_internal.h ('k') | base/callback_internal.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 18 matching lines...) Expand all
29 // RefCountedThreadSafe since it requires the destructor to be a virtual method. 29 // RefCountedThreadSafe since it requires the destructor to be a virtual method.
30 // Creating a vtable for every BindState template instantiation results in a lot 30 // Creating a vtable for every BindState template instantiation results in a lot
31 // of bloat. Its only task is to call the destructor which can be done with a 31 // of bloat. Its only task is to call the destructor which can be done with a
32 // function pointer. 32 // function pointer.
33 class BASE_EXPORT BindStateBase { 33 class BASE_EXPORT BindStateBase {
34 public: 34 public:
35 using InvokeFuncStorage = void(*)(); 35 using InvokeFuncStorage = void(*)();
36 36
37 protected: 37 protected:
38 BindStateBase(InvokeFuncStorage polymorphic_invoke, 38 BindStateBase(InvokeFuncStorage polymorphic_invoke,
39 void (*destructor)(BindStateBase*)); 39 void (*destructor)(const BindStateBase*));
40 BindStateBase(InvokeFuncStorage polymorphic_invoke, 40 BindStateBase(InvokeFuncStorage polymorphic_invoke,
41 void (*destructor)(BindStateBase*), 41 void (*destructor)(const BindStateBase*),
42 bool (*is_cancelled)(const BindStateBase*)); 42 bool (*is_cancelled)(const BindStateBase*));
43 ~BindStateBase() = default; 43 ~BindStateBase() = default;
44 44
45 private: 45 private:
46 friend class scoped_refptr<BindStateBase>; 46 friend class scoped_refptr<BindStateBase>;
47 template <CopyMode copy_mode> 47 template <CopyMode copy_mode>
48 friend class CallbackBase; 48 friend class CallbackBase;
49 49
50 bool IsCancelled() const { 50 bool IsCancelled() const {
51 return is_cancelled_(this); 51 return is_cancelled_(this);
52 } 52 }
53 53
54 void AddRef(); 54 void AddRef() const;
55 void Release(); 55 void Release() const;
Yuta Kitamura 2016/09/20 10:04:21 I'm not sure adding const to these is legit. In my
tzik 2016/09/20 10:54:30 The refcount is not a state of the instance, but a
Yuta Kitamura 2016/09/21 06:01:36 Ah okay, this lets us refcount const objects, righ
56 56
57 // In C++, it is safe to cast function pointers to function pointers of 57 // In C++, it is safe to cast function pointers to function pointers of
58 // another type. It is not okay to use void*. We create a InvokeFuncStorage 58 // another type. It is not okay to use void*. We create a InvokeFuncStorage
59 // that that can store our function pointer, and then cast it back to 59 // that that can store our function pointer, and then cast it back to
60 // the original type on usage. 60 // the original type on usage.
61 InvokeFuncStorage polymorphic_invoke_; 61 InvokeFuncStorage polymorphic_invoke_;
62 62
63 AtomicRefCount ref_count_; 63 mutable AtomicRefCount ref_count_;
64 64
65 // Pointer to a function that will properly destroy |this|. 65 // Pointer to a function that will properly destroy |this|.
66 void (*destructor_)(BindStateBase*); 66 void (*destructor_)(const BindStateBase*);
67 bool (*is_cancelled_)(const BindStateBase*); 67 bool (*is_cancelled_)(const BindStateBase*);
68 68
69 DISALLOW_COPY_AND_ASSIGN(BindStateBase); 69 DISALLOW_COPY_AND_ASSIGN(BindStateBase);
70 }; 70 };
71 71
72 // Holds the Callback methods that don't require specialization to reduce 72 // Holds the Callback methods that don't require specialization to reduce
73 // template bloat. 73 // template bloat.
74 // CallbackBase<MoveOnly> is a direct base class of MoveOnly callbacks, and 74 // CallbackBase<MoveOnly> is a direct base class of MoveOnly callbacks, and
75 // CallbackBase<Copyable> uses CallbackBase<MoveOnly> for its implementation. 75 // CallbackBase<Copyable> uses CallbackBase<MoveOnly> for its implementation.
76 template <> 76 template <>
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 ~CallbackBase() {} 130 ~CallbackBase() {}
131 }; 131 };
132 132
133 extern template class CallbackBase<CopyMode::MoveOnly>; 133 extern template class CallbackBase<CopyMode::MoveOnly>;
134 extern template class CallbackBase<CopyMode::Copyable>; 134 extern template class CallbackBase<CopyMode::Copyable>;
135 135
136 } // namespace internal 136 } // namespace internal
137 } // namespace base 137 } // namespace base
138 138
139 #endif // BASE_CALLBACK_INTERNAL_H_ 139 #endif // BASE_CALLBACK_INTERNAL_H_
OLDNEW
« no previous file with comments | « base/bind_internal.h ('k') | base/callback_internal.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698