From 6140bb1557468deec09b78eec185b33b11d8493c Mon Sep 17 00:00:00 2001 From: Matt Falkenhagen Date: Tue, 19 Nov 2019 22:52:36 +0000 Subject: [PATCH] Convert ipc to Once/Repeating variants of Bind/Callback. Bug: 1007797 Change-Id: I20d470fa136ee6c7dc997648725440a2fc89c65b Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1923968 Reviewed-by: Ken Rockot Commit-Queue: Matt Falkenhagen Cr-Commit-Position: refs/heads/master@{#716806} --- ipc/ipc_channel.h | 16 +++++++++------- ipc/ipc_channel_mojo.cc | 8 +++++--- ipc/ipc_channel_nacl.cc | 21 +++++++++++++-------- ipc/ipc_channel_proxy.h | 10 +++++----- 4 files changed, 32 insertions(+), 23 deletions(-) diff --git a/ipc/ipc_channel.h b/ipc/ipc_channel.h index 04395f091e2091..c74cf0c6a8c4d9 100644 --- a/ipc/ipc_channel.h +++ b/ipc/ipc_channel.h @@ -90,7 +90,7 @@ class COMPONENT_EXPORT(IPC) Channel : public Sender { class COMPONENT_EXPORT(IPC) AssociatedInterfaceSupport { public: using GenericAssociatedInterfaceFactory = - base::Callback; + base::RepeatingCallback; virtual ~AssociatedInterfaceSupport() {} @@ -114,26 +114,28 @@ class COMPONENT_EXPORT(IPC) Channel : public Sender { // AsscoiatedRemote. // Template helper to add an interface factory to this channel. template - using AssociatedInterfaceFactory = - base::Callback)>; + using AssociatedInterfaceFactory = base::RepeatingCallback)>; template void AddAssociatedInterface( const AssociatedInterfaceFactory& factory) { AddGenericAssociatedInterface( Interface::Name_, - base::Bind(&BindAssociatedInterfaceRequest, factory)); + base::BindRepeating(&BindAssociatedInterfaceRequest, + factory)); } // Template helper to add an interface factory to this channel. template - using AssociatedReceiverFactory = - base::Callback)>; + using AssociatedReceiverFactory = base::RepeatingCallback)>; template void AddAssociatedInterface( const AssociatedReceiverFactory& factory) { AddGenericAssociatedInterface( Interface::Name_, - base::Bind(&BindPendingAssociatedReceiver, factory)); + base::BindRepeating(&BindPendingAssociatedReceiver, + factory)); } // Remove this after done with migrating all AsscoiatedInterfacePtr to diff --git a/ipc/ipc_channel_mojo.cc b/ipc/ipc_channel_mojo.cc index 0affc2677bf415..02c955b15251c5 100644 --- a/ipc/ipc_channel_mojo.cc +++ b/ipc/ipc_channel_mojo.cc @@ -256,9 +256,11 @@ std::unique_ptr> ChannelMojo::CreateThreadSafeChannel() { return std::make_unique>( task_runner_, - base::Bind(&ChannelMojo::ForwardMessageFromThreadSafePtr, weak_ptr_), - base::Bind(&ChannelMojo::ForwardMessageWithResponderFromThreadSafePtr, - weak_ptr_), + base::BindRepeating(&ChannelMojo::ForwardMessageFromThreadSafePtr, + weak_ptr_), + base::BindRepeating( + &ChannelMojo::ForwardMessageWithResponderFromThreadSafePtr, + weak_ptr_), *bootstrap_->GetAssociatedGroup()); } diff --git a/ipc/ipc_channel_nacl.cc b/ipc/ipc_channel_nacl.cc index 50ff64c7120b1a..1db4acb9e5c629 100644 --- a/ipc/ipc_channel_nacl.cc +++ b/ipc/ipc_channel_nacl.cc @@ -83,8 +83,9 @@ class ChannelNacl::ReaderThreadRunner // above callbacks. ReaderThreadRunner( int pipe, - base::Callback)> data_read_callback, - base::Callback failure_callback, + base::RepeatingCallback)> + data_read_callback, + base::RepeatingCallback failure_callback, scoped_refptr main_task_runner); // DelegateSimpleThread implementation. Reads data from the pipe in a loop @@ -93,8 +94,9 @@ class ChannelNacl::ReaderThreadRunner private: int pipe_; - base::Callback)> data_read_callback_; - base::Callback failure_callback_; + base::RepeatingCallback)> + data_read_callback_; + base::RepeatingCallback failure_callback_; scoped_refptr main_task_runner_; DISALLOW_COPY_AND_ASSIGN(ReaderThreadRunner); @@ -102,8 +104,9 @@ class ChannelNacl::ReaderThreadRunner ChannelNacl::ReaderThreadRunner::ReaderThreadRunner( int pipe, - base::Callback)> data_read_callback, - base::Callback failure_callback, + base::RepeatingCallback)> + data_read_callback, + base::RepeatingCallback failure_callback, scoped_refptr main_task_runner) : pipe_(pipe), data_read_callback_(data_read_callback), @@ -163,8 +166,10 @@ bool ChannelNacl::Connect() { // ReaderThreadRunner. reader_thread_runner_.reset(new ReaderThreadRunner( pipe_, - base::Bind(&ChannelNacl::DidRecvMsg, weak_ptr_factory_.GetWeakPtr()), - base::Bind(&ChannelNacl::ReadDidFail, weak_ptr_factory_.GetWeakPtr()), + base::BindRepeating(&ChannelNacl::DidRecvMsg, + weak_ptr_factory_.GetWeakPtr()), + base::BindRepeating(&ChannelNacl::ReadDidFail, + weak_ptr_factory_.GetWeakPtr()), base::ThreadTaskRunnerHandle::Get())); reader_thread_.reset( new base::DelegateSimpleThread(reader_thread_runner_.get(), diff --git a/ipc/ipc_channel_proxy.h b/ipc/ipc_channel_proxy.h index ab1d8d3c98d0d9..0218ec80e55b70 100644 --- a/ipc/ipc_channel_proxy.h +++ b/ipc/ipc_channel_proxy.h @@ -168,7 +168,7 @@ class COMPONENT_EXPORT(IPC) ChannelProxy : public Sender { void RemoveFilter(MessageFilter* filter); using GenericAssociatedInterfaceFactory = - base::Callback; + base::RepeatingCallback; // Adds a generic associated interface factory to bind incoming interface // requests directly on the IO thread. MUST be called either before Init() or @@ -179,8 +179,8 @@ class COMPONENT_EXPORT(IPC) ChannelProxy : public Sender { const GenericAssociatedInterfaceFactory& factory); template - using AssociatedInterfaceFactory = - base::Callback)>; + using AssociatedInterfaceFactory = base::RepeatingCallback)>; // Helper to bind an IO-thread associated interface factory, inferring the // interface name from the callback argument's type. MUST be called before @@ -190,8 +190,8 @@ class COMPONENT_EXPORT(IPC) ChannelProxy : public Sender { const AssociatedInterfaceFactory& factory) { AddGenericAssociatedInterfaceForIOThread( Interface::Name_, - base::Bind(&ChannelProxy::BindAssociatedInterfaceRequest, - factory)); + base::BindRepeating( + &ChannelProxy::BindAssociatedInterfaceRequest, factory)); } // Requests an associated interface from the remote endpoint.