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

Side by Side Diff: base/bind_helpers.h

Issue 1699123002: Unify BindState refcount management into the bound arguments. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: +comment Created 4 years, 10 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.h ('k') | base/bind_internal.h » ('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 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 template <typename T> 418 template <typename T>
419 T* Unwrap(const OwnedWrapper<T>& o) { 419 T* Unwrap(const OwnedWrapper<T>& o) {
420 return o.get(); 420 return o.get();
421 } 421 }
422 422
423 template <typename T> 423 template <typename T>
424 T Unwrap(PassedWrapper<T>& o) { 424 T Unwrap(PassedWrapper<T>& o) {
425 return o.Take(); 425 return o.Take();
426 } 426 }
427 427
428 // Utility for handling different refcounting semantics in the Bind()
429 // function.
430 template <bool is_method, typename... T>
431 struct MaybeScopedRefPtr;
432
433 template <bool is_method>
434 struct MaybeScopedRefPtr<is_method> {
435 MaybeScopedRefPtr() {}
436 };
437
438 template <typename T, typename... Rest>
439 struct MaybeScopedRefPtr<false, T, Rest...> {
440 MaybeScopedRefPtr(const T&, const Rest&...) {}
441 };
442
443 template <typename T, size_t n, typename... Rest>
444 struct MaybeScopedRefPtr<false, T[n], Rest...> {
445 MaybeScopedRefPtr(const T*, const Rest&...) {}
446 };
447
448 template <typename T, typename... Rest>
449 struct MaybeScopedRefPtr<true, T, Rest...> {
450 MaybeScopedRefPtr(const T& o, const Rest&...) {}
451 };
452
453 template <typename T, typename... Rest>
454 struct MaybeScopedRefPtr<true, T*, Rest...> {
455 MaybeScopedRefPtr(T* o, const Rest&...) : ref_(o) {}
456 scoped_refptr<T> ref_;
457 };
458
459 // No need to additionally AddRef() and Release() since we are storing a
460 // scoped_refptr<> inside the storage object already.
461 template <typename T, typename... Rest>
462 struct MaybeScopedRefPtr<true, scoped_refptr<T>, Rest...> {
463 MaybeScopedRefPtr(const scoped_refptr<T>&, const Rest&...) {}
464 };
465
466 template <typename T, typename... Rest>
467 struct MaybeScopedRefPtr<true, const T*, Rest...> {
468 MaybeScopedRefPtr(const T* o, const Rest&...) : ref_(o) {}
469 scoped_refptr<const T> ref_;
470 };
471
472 // IsWeakMethod is a helper that determine if we are binding a WeakPtr<> to a 428 // IsWeakMethod is a helper that determine if we are binding a WeakPtr<> to a
473 // method. It is used internally by Bind() to select the correct 429 // method. It is used internally by Bind() to select the correct
474 // InvokeHelper that will no-op itself in the event the WeakPtr<> for 430 // InvokeHelper that will no-op itself in the event the WeakPtr<> for
475 // the target object is invalidated. 431 // the target object is invalidated.
476 // 432 //
477 // The first argument should be the type of the object that will be received by 433 // The first argument should be the type of the object that will be received by
478 // the method. 434 // the method.
479 template <bool IsMethod, typename... Args> 435 template <bool IsMethod, typename... Args>
480 struct IsWeakMethod : public false_type {}; 436 struct IsWeakMethod : public false_type {};
481 437
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 BASE_EXPORT void DoNothing(); 590 BASE_EXPORT void DoNothing();
635 591
636 template<typename T> 592 template<typename T>
637 void DeletePointer(T* obj) { 593 void DeletePointer(T* obj) {
638 delete obj; 594 delete obj;
639 } 595 }
640 596
641 } // namespace base 597 } // namespace base
642 598
643 #endif // BASE_BIND_HELPERS_H_ 599 #endif // BASE_BIND_HELPERS_H_
OLDNEW
« no previous file with comments | « base/bind.h ('k') | base/bind_internal.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698