Skip to content

Commit

Permalink
Support Microsoft::WRL::ComPtr as a receiver of base::Bind{Once,Repea…
Browse files Browse the repository at this point in the history
…ting}

After this CL, we can use ComPtr as the |this| pointer of base::BindOnce
and base::BindRepeating.

ComPtr doesn't have `operator*` nor `operator->*` that are needed to run
a method pointer. So we need a special handling for it to use it as a
receiver on base::Bind.

We currently use scoped_refptr to store COM instance on base::Bind, which
happens to work, but that looks fragile. This CL is a preparation to
convert these scoped_refptr to ComPtr.

Change-Id: I1fe31e23ac627050860fe2c81ead6807a17bb939
Reviewed-on: https://chromium-review.googlesource.com/1145153
Commit-Queue: Taiju Tsuiki <tzik@chromium.org>
Reviewed-by: Jan Wilken Dörrie <jdoerrie@chromium.org>
Reviewed-by: Robert Liao <robliao@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#577470}
  • Loading branch information
tzik authored and Commit Bot committed Jul 24, 2018
1 parent 49874bf commit c44f810
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions base/bind_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@
// BindState<> -- Stores the curried parameters, and is the main entry point
// into the Bind() system.

#if defined(OS_WIN)
namespace Microsoft {
namespace WRL {
template <typename>
class ComPtr;
} // namespace WRL
} // namespace Microsoft
#endif

namespace base {

template <typename T>
Expand Down Expand Up @@ -910,6 +919,13 @@ struct BindUnwrapTraits<internal::PassedWrapper<T>> {
static T Unwrap(const internal::PassedWrapper<T>& o) { return o.Take(); }
};

#if defined(OS_WIN)
template <typename T>
struct BindUnwrapTraits<Microsoft::WRL::ComPtr<T>> {
static T* Unwrap(const Microsoft::WRL::ComPtr<T>& ptr) { return ptr.Get(); }
};
#endif

// CallbackCancellationTraits allows customization of Callback's cancellation
// semantics. By default, callbacks are not cancellable. A specialization should
// set is_cancellable = true and implement an IsCancelled() that returns if the
Expand Down

0 comments on commit c44f810

Please sign in to comment.