| Index: mojo/public/cpp/bindings/thread_safe_interface_ptr.h
|
| diff --git a/mojo/public/cpp/bindings/thread_safe_interface_ptr.h b/mojo/public/cpp/bindings/thread_safe_interface_ptr.h
|
| index 605bddda1376bb97f2beef559129afe9169342db..8c8234caa32793f0f7a373055b26ffe23bd6ccd6 100644
|
| --- a/mojo/public/cpp/bindings/thread_safe_interface_ptr.h
|
| +++ b/mojo/public/cpp/bindings/thread_safe_interface_ptr.h
|
| @@ -51,43 +51,49 @@ class ThreadSafeInterfacePtrBase
|
| ThreadSafeInterfacePtrDeleter> {
|
| public:
|
| using ProxyType = typename Interface::Proxy_;
|
| + using PtrInfoType = typename InterfacePtrType<Interface>::PtrInfoType;
|
|
|
| + // Creates a ThreadSafeInterfacePtrBase wrapping an underlying non-thread-safe
|
| + // InterfacePtrType which is bound to the calling thread. All messages sent
|
| + // via this thread-safe proxy will internally be sent by first posting to this
|
| + // (the calling) thread's TaskRunner.
|
| static scoped_refptr<ThreadSafeInterfacePtrBase<Interface, InterfacePtrType>>
|
| Create(InterfacePtrType<Interface> interface_ptr) {
|
| scoped_refptr<ThreadSafeInterfacePtrBase> ptr(
|
| new ThreadSafeInterfacePtrBase());
|
| - return ptr->Bind(std::move(interface_ptr)) ? ptr : nullptr;
|
| + ptr->interface_ptr_task_runner_ = base::ThreadTaskRunnerHandle::Get();
|
| + return ptr->Bind(interface_ptr.PassInterface()) ? ptr : nullptr;
|
| }
|
|
|
| - // Creates a ThreadSafeInterfacePtrBase with no associated InterfacePtr.
|
| - // Call Bind() with the InterfacePtr once available, which must be called on
|
| - // the |bind_task_runner|.
|
| - // Providing the TaskRunner here allows you to post a task to
|
| - // |bind_task_runner| to do the bind and then immediately start calling
|
| - // methods on the returned interface.
|
| + // Creates a ThreadSafeInterfacePtrBase which binds the underlying
|
| + // non-thread-safe InterfacePtrType on the specified TaskRunner. All messages
|
| + // sent via this thread-safe proxy will internally be sent by first posting to
|
| + // that TaskRunner.
|
| static scoped_refptr<ThreadSafeInterfacePtrBase<Interface, InterfacePtrType>>
|
| - CreateUnbound(
|
| - const scoped_refptr<base::SingleThreadTaskRunner>& bind_task_runner) {
|
| + Create(PtrInfoType ptr_info,
|
| + const scoped_refptr<base::SingleThreadTaskRunner>& bind_task_runner) {
|
| scoped_refptr<ThreadSafeInterfacePtrBase<Interface, InterfacePtrType>> ptr =
|
| new ThreadSafeInterfacePtrBase();
|
| ptr->interface_ptr_task_runner_ = bind_task_runner;
|
| + bind_task_runner->PostTask(
|
| + FROM_HERE,
|
| + base::Bind(base::IgnoreResult(&ThreadSafeInterfacePtrBase::Bind), ptr,
|
| + base::Passed(&ptr_info)));
|
| return ptr;
|
| }
|
|
|
| // Binds a ThreadSafeInterfacePtrBase previously created with CreateUnbound().
|
| - // This must be called on the thread that |interface_ptr| should be used.
|
| + // This must be called on the thread that |ptr_info| should be used.
|
| // If created with CreateUnbound() that thread should be the same as the one
|
| // provided at creation time.
|
| - bool Bind(InterfacePtrType<Interface> interface_ptr) {
|
| - DCHECK(!interface_ptr_task_runner_ ||
|
| - interface_ptr_task_runner_ == base::ThreadTaskRunnerHandle::Get());
|
| - if (!interface_ptr.is_bound()) {
|
| + bool Bind(PtrInfoType ptr_info) {
|
| + DCHECK_EQ(interface_ptr_task_runner_, base::ThreadTaskRunnerHandle::Get());
|
| + if (!ptr_info.is_valid()) {
|
| LOG(ERROR) << "Attempting to bind a ThreadSafe[Associated]InterfacePtr "
|
| "from an unbound InterfacePtr.";
|
| return false;
|
| }
|
| - interface_ptr_ = std::move(interface_ptr);
|
| - interface_ptr_task_runner_ = base::ThreadTaskRunnerHandle::Get();
|
| + interface_ptr_.Bind(std::move(ptr_info));
|
| return true;
|
| }
|
|
|
|
|