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

Side by Side Diff: base/bind_helpers.h

Issue 2106123002: Remove unused UnsafeBindtoRefCountedArg in bind_helpers.h (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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 | « no previous file | base/bind_unittest.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) 2011 The Chromium Authors. All rights reserved. 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 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 defines a set of argument wrappers and related factory methods that 5 // This defines a set of argument wrappers and related factory methods that
6 // can be used specify the refcounting and reference semantics of arguments 6 // can be used specify the refcounting and reference semantics of arguments
7 // that are bound by the Bind() function in base/bind.h. 7 // that are bound by the Bind() function in base/bind.h.
8 // 8 //
9 // It also defines a set of simple functions and utilities that people want 9 // It also defines a set of simple functions and utilities that people want
10 // when using Callback<> and Bind(). 10 // when using Callback<> and Bind().
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 // substitution if T::TargetFunc exists. Thus GoodCheck<Base>(0) will resolve 233 // substitution if T::TargetFunc exists. Thus GoodCheck<Base>(0) will resolve
234 // to the variadic version if T has TargetFunc. If T::TargetFunc does not 234 // to the variadic version if T has TargetFunc. If T::TargetFunc does not
235 // exist, then &C::TargetFunc is not ambiguous, and the overload resolution 235 // exist, then &C::TargetFunc is not ambiguous, and the overload resolution
236 // will prefer GoodCheck(Helper<&C::TargetFunc>*). 236 // will prefer GoodCheck(Helper<&C::TargetFunc>*).
237 // 237 //
238 // This method of SFINAE will correctly probe for inherited names, but it cannot 238 // This method of SFINAE will correctly probe for inherited names, but it cannot
239 // typecheck those names. It's still a good enough sanity check though. 239 // typecheck those names. It's still a good enough sanity check though.
240 // 240 //
241 // Works on gcc-4.2, gcc-4.4, and Visual Studio 2008. 241 // Works on gcc-4.2, gcc-4.4, and Visual Studio 2008.
242 // 242 //
243 // TODO(ajwong): Move to ref_counted.h or template_util.h when we've vetted
244 // this works well.
245 //
246 // TODO(ajwong): Make this check for Release() as well.
247 // See http://crbug.com/82038.
248 template <typename T>
249 class SupportsAddRefAndRelease {
250 using Yes = char[1];
251 using No = char[2];
252
253 struct BaseMixin {
254 void AddRef();
255 };
256
257 // MSVC warns when you try to use Base if T has a private destructor, the
258 // common pattern for refcounted types. It does this even though no attempt to
259 // instantiate Base is made. We disable the warning for this definition.
260 #if defined(OS_WIN)
261 #pragma warning(push)
262 #pragma warning(disable:4624)
263 #endif
264 struct Base : public T, public BaseMixin {
265 };
266 #if defined(OS_WIN)
267 #pragma warning(pop)
268 #endif
269
270 template <void(BaseMixin::*)()> struct Helper {};
271
272 template <typename C>
273 static No& Check(Helper<&C::AddRef>*);
274
275 template <typename >
276 static Yes& Check(...);
277
278 public:
279 enum { value = sizeof(Check<Base>(0)) == sizeof(Yes) };
280 };
281
282 // Helpers to assert that arguments of a recounted type are bound with a
283 // scoped_refptr.
284 template <bool IsClasstype, typename T>
285 struct UnsafeBindtoRefCountedArgHelper : std::false_type {
286 };
287
288 template <typename T>
289 struct UnsafeBindtoRefCountedArgHelper<true, T>
290 : std::integral_constant<bool, SupportsAddRefAndRelease<T>::value> {
291 };
292
293 template <typename T>
294 struct UnsafeBindtoRefCountedArg : std::false_type {
295 };
296
297 template <typename T>
298 struct UnsafeBindtoRefCountedArg<T*>
299 : UnsafeBindtoRefCountedArgHelper<std::is_class<T>::value, T> {
300 };
301 243
302 template <typename T> 244 template <typename T>
303 class HasIsMethodTag { 245 class HasIsMethodTag {
304 using Yes = char[1]; 246 using Yes = char[1];
305 using No = char[2]; 247 using No = char[2];
306 248
307 template <typename U> 249 template <typename U>
308 static Yes& Check(typename U::IsMethod*); 250 static Yes& Check(typename U::IsMethod*);
309 251
310 template <typename U> 252 template <typename U>
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 572
631 template <typename T> 573 template <typename T>
632 struct IsWeakReceiver<internal::ConstRefWrapper<T>> : IsWeakReceiver<T> {}; 574 struct IsWeakReceiver<internal::ConstRefWrapper<T>> : IsWeakReceiver<T> {};
633 575
634 template <typename T> 576 template <typename T>
635 struct IsWeakReceiver<WeakPtr<T>> : std::true_type {}; 577 struct IsWeakReceiver<WeakPtr<T>> : std::true_type {};
636 578
637 } // namespace base 579 } // namespace base
638 580
639 #endif // BASE_BIND_HELPERS_H_ 581 #endif // BASE_BIND_HELPERS_H_
OLDNEW
« no previous file with comments | « no previous file | base/bind_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698