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

Unified Diff: ipc/ipc_channel_mojo.cc

Issue 2668153003: Mojo C++ Bindings: Eliminate unbound ThreadSafeInterfacePtr (Closed)
Patch Set: format and rebase... Created 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ipc/ipc_channel_mojo.h ('k') | ipc/ipc_channel_proxy.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ipc/ipc_channel_mojo.cc
diff --git a/ipc/ipc_channel_mojo.cc b/ipc/ipc_channel_mojo.cc
index 4189b9c06f1a58bfa4ebc28b3c9a10442aaada9c..3d5e8553a658bb84c27dbf04bcdcfb5662c35644 100644
--- a/ipc/ipc_channel_mojo.cc
+++ b/ipc/ipc_channel_mojo.cc
@@ -274,25 +274,49 @@ ChannelMojo::ChannelMojo(
Mode mode,
Listener* listener,
const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner)
- : pipe_(handle.get()), listener_(listener), weak_factory_(this) {
- // Create MojoBootstrap after all members are set as it touches
- // ChannelMojo from a different thread.
- bootstrap_ =
- MojoBootstrap::Create(std::move(handle), mode, this, ipc_task_runner);
+ : task_runner_(ipc_task_runner),
+ pipe_(handle.get()),
+ listener_(listener),
+ weak_factory_(this) {
+ bootstrap_ = MojoBootstrap::Create(std::move(handle), mode, ipc_task_runner);
+}
+
+void ChannelMojo::ForwardMessageFromThreadSafePtr(mojo::Message message) {
+ DCHECK(task_runner_->RunsTasksOnCurrentThread());
+ if (!message_reader_)
+ return;
+ message_reader_->sender().internal_state()->ForwardMessage(
+ std::move(message));
+}
+
+void ChannelMojo::ForwardMessageWithResponderFromThreadSafePtr(
+ mojo::Message message,
+ std::unique_ptr<mojo::MessageReceiver> responder) {
+ DCHECK(task_runner_->RunsTasksOnCurrentThread());
+ if (!message_reader_)
+ return;
+ message_reader_->sender().internal_state()->ForwardMessageWithResponder(
+ std::move(message), std::move(responder));
}
ChannelMojo::~ChannelMojo() {
+ DCHECK(task_runner_->RunsTasksOnCurrentThread());
Close();
}
bool ChannelMojo::Connect() {
+ DCHECK(task_runner_->RunsTasksOnCurrentThread());
+
WillConnect();
- DCHECK(!task_runner_);
- task_runner_ = base::ThreadTaskRunnerHandle::Get();
- DCHECK(!message_reader_);
+ mojom::ChannelAssociatedPtr sender;
+ mojom::ChannelAssociatedRequest receiver;
+ bootstrap_->Connect(&sender, &receiver);
- bootstrap_->Connect();
+ DCHECK(!message_reader_);
+ sender->SetPeerPid(GetSelfPID());
+ message_reader_.reset(new internal::MessagePipeReader(
+ pipe_, std::move(sender), std::move(receiver), this));
return true;
}
@@ -321,14 +345,6 @@ void ChannelMojo::Close() {
associated_interfaces_.clear();
}
-// MojoBootstrap::Delegate implementation
-void ChannelMojo::OnPipesAvailable(mojom::ChannelAssociatedPtr sender,
- mojom::ChannelAssociatedRequest receiver) {
- sender->SetPeerPid(GetSelfPID());
- message_reader_.reset(new internal::MessagePipeReader(
- pipe_, std::move(sender), std::move(receiver), this));
-}
-
void ChannelMojo::OnPipeError() {
DCHECK(task_runner_);
if (task_runner_->RunsTasksOnCurrentThread()) {
@@ -377,6 +393,15 @@ bool ChannelMojo::Send(Message* message) {
Channel::AssociatedInterfaceSupport*
ChannelMojo::GetAssociatedInterfaceSupport() { return this; }
+std::unique_ptr<mojo::ThreadSafeForwarder<mojom::Channel>>
+ChannelMojo::CreateThreadSafeChannel() {
+ return base::MakeUnique<mojo::ThreadSafeForwarder<mojom::Channel>>(
+ task_runner_, base::Bind(&ChannelMojo::ForwardMessageFromThreadSafePtr,
+ weak_factory_.GetWeakPtr()),
+ base::Bind(&ChannelMojo::ForwardMessageWithResponderFromThreadSafePtr,
+ weak_factory_.GetWeakPtr()));
+}
+
void ChannelMojo::OnPeerPidReceived(int32_t peer_pid) {
listener_->OnChannelConnected(peer_pid);
}
« no previous file with comments | « ipc/ipc_channel_mojo.h ('k') | ipc/ipc_channel_proxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698