Skip to content

Commit

Permalink
Convert ipc to Once/Repeating variants of Bind/Callback.
Browse files Browse the repository at this point in the history
Bug: 1007797
Change-Id: I20d470fa136ee6c7dc997648725440a2fc89c65b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1923968
Reviewed-by: Ken Rockot <rockot@google.com>
Commit-Queue: Matt Falkenhagen <falken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#716806}
  • Loading branch information
mfalken authored and Commit Bot committed Nov 19, 2019
1 parent 34bab11 commit 6140bb1
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 23 deletions.
16 changes: 9 additions & 7 deletions ipc/ipc_channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class COMPONENT_EXPORT(IPC) Channel : public Sender {
class COMPONENT_EXPORT(IPC) AssociatedInterfaceSupport {
public:
using GenericAssociatedInterfaceFactory =
base::Callback<void(mojo::ScopedInterfaceEndpointHandle)>;
base::RepeatingCallback<void(mojo::ScopedInterfaceEndpointHandle)>;

virtual ~AssociatedInterfaceSupport() {}

Expand All @@ -114,26 +114,28 @@ class COMPONENT_EXPORT(IPC) Channel : public Sender {
// AsscoiatedRemote.
// Template helper to add an interface factory to this channel.
template <typename Interface>
using AssociatedInterfaceFactory =
base::Callback<void(mojo::AssociatedInterfaceRequest<Interface>)>;
using AssociatedInterfaceFactory = base::RepeatingCallback<void(
mojo::AssociatedInterfaceRequest<Interface>)>;
template <typename Interface>
void AddAssociatedInterface(
const AssociatedInterfaceFactory<Interface>& factory) {
AddGenericAssociatedInterface(
Interface::Name_,
base::Bind(&BindAssociatedInterfaceRequest<Interface>, factory));
base::BindRepeating(&BindAssociatedInterfaceRequest<Interface>,
factory));
}

// Template helper to add an interface factory to this channel.
template <typename Interface>
using AssociatedReceiverFactory =
base::Callback<void(mojo::PendingAssociatedReceiver<Interface>)>;
using AssociatedReceiverFactory = base::RepeatingCallback<void(
mojo::PendingAssociatedReceiver<Interface>)>;
template <typename Interface>
void AddAssociatedInterface(
const AssociatedReceiverFactory<Interface>& factory) {
AddGenericAssociatedInterface(
Interface::Name_,
base::Bind(&BindPendingAssociatedReceiver<Interface>, factory));
base::BindRepeating(&BindPendingAssociatedReceiver<Interface>,
factory));
}

// Remove this after done with migrating all AsscoiatedInterfacePtr to
Expand Down
8 changes: 5 additions & 3 deletions ipc/ipc_channel_mojo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,11 @@ std::unique_ptr<mojo::ThreadSafeForwarder<mojom::Channel>>
ChannelMojo::CreateThreadSafeChannel() {
return std::make_unique<mojo::ThreadSafeForwarder<mojom::Channel>>(
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());
}

Expand Down
21 changes: 13 additions & 8 deletions ipc/ipc_channel_nacl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@ class ChannelNacl::ReaderThreadRunner
// above callbacks.
ReaderThreadRunner(
int pipe,
base::Callback<void(std::unique_ptr<MessageContents>)> data_read_callback,
base::Callback<void()> failure_callback,
base::RepeatingCallback<void(std::unique_ptr<MessageContents>)>
data_read_callback,
base::RepeatingCallback<void()> failure_callback,
scoped_refptr<base::SingleThreadTaskRunner> main_task_runner);

// DelegateSimpleThread implementation. Reads data from the pipe in a loop
Expand All @@ -93,17 +94,19 @@ class ChannelNacl::ReaderThreadRunner

private:
int pipe_;
base::Callback<void(std::unique_ptr<MessageContents>)> data_read_callback_;
base::Callback<void ()> failure_callback_;
base::RepeatingCallback<void(std::unique_ptr<MessageContents>)>
data_read_callback_;
base::RepeatingCallback<void()> failure_callback_;
scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_;

DISALLOW_COPY_AND_ASSIGN(ReaderThreadRunner);
};

ChannelNacl::ReaderThreadRunner::ReaderThreadRunner(
int pipe,
base::Callback<void(std::unique_ptr<MessageContents>)> data_read_callback,
base::Callback<void()> failure_callback,
base::RepeatingCallback<void(std::unique_ptr<MessageContents>)>
data_read_callback,
base::RepeatingCallback<void()> failure_callback,
scoped_refptr<base::SingleThreadTaskRunner> main_task_runner)
: pipe_(pipe),
data_read_callback_(data_read_callback),
Expand Down Expand Up @@ -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(),
Expand Down
10 changes: 5 additions & 5 deletions ipc/ipc_channel_proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ class COMPONENT_EXPORT(IPC) ChannelProxy : public Sender {
void RemoveFilter(MessageFilter* filter);

using GenericAssociatedInterfaceFactory =
base::Callback<void(mojo::ScopedInterfaceEndpointHandle)>;
base::RepeatingCallback<void(mojo::ScopedInterfaceEndpointHandle)>;

// Adds a generic associated interface factory to bind incoming interface
// requests directly on the IO thread. MUST be called either before Init() or
Expand All @@ -179,8 +179,8 @@ class COMPONENT_EXPORT(IPC) ChannelProxy : public Sender {
const GenericAssociatedInterfaceFactory& factory);

template <typename Interface>
using AssociatedInterfaceFactory =
base::Callback<void(mojo::AssociatedInterfaceRequest<Interface>)>;
using AssociatedInterfaceFactory = base::RepeatingCallback<void(
mojo::AssociatedInterfaceRequest<Interface>)>;

// Helper to bind an IO-thread associated interface factory, inferring the
// interface name from the callback argument's type. MUST be called before
Expand All @@ -190,8 +190,8 @@ class COMPONENT_EXPORT(IPC) ChannelProxy : public Sender {
const AssociatedInterfaceFactory<Interface>& factory) {
AddGenericAssociatedInterfaceForIOThread(
Interface::Name_,
base::Bind(&ChannelProxy::BindAssociatedInterfaceRequest<Interface>,
factory));
base::BindRepeating(
&ChannelProxy::BindAssociatedInterfaceRequest<Interface>, factory));
}

// Requests an associated interface from the remote endpoint.
Expand Down

0 comments on commit 6140bb1

Please sign in to comment.