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

Unified Diff: ipc/mojo/ipc_channel_mojo.cc

Issue 1054253005: ChannelMojo: Ensure that it always has ScopedIPCSupport (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed the ipc_fuzzer breakage Created 5 years, 8 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/mojo/ipc_channel_mojo.h ('k') | ipc/mojo/ipc_channel_mojo_host.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ipc/mojo/ipc_channel_mojo.cc
diff --git a/ipc/mojo/ipc_channel_mojo.cc b/ipc/mojo/ipc_channel_mojo.cc
index f338c6fcdd96df8656681827bbeb08054c049a42..4689e5f64ec7076d9f06b5345310d98d60c45124 100644
--- a/ipc/mojo/ipc_channel_mojo.cc
+++ b/ipc/mojo/ipc_channel_mojo.cc
@@ -28,20 +28,26 @@ namespace {
class MojoChannelFactory : public ChannelFactory {
public:
MojoChannelFactory(ChannelMojo::Delegate* delegate,
+ scoped_refptr<base::TaskRunner> io_runner,
ChannelHandle channel_handle,
Channel::Mode mode)
- : delegate_(delegate), channel_handle_(channel_handle), mode_(mode) {}
+ : delegate_(delegate),
+ io_runner_(io_runner),
+ channel_handle_(channel_handle),
+ mode_(mode) {}
std::string GetName() const override {
return channel_handle_.name;
}
scoped_ptr<Channel> BuildChannel(Listener* listener) override {
- return ChannelMojo::Create(delegate_, channel_handle_, mode_, listener);
+ return ChannelMojo::Create(delegate_, io_runner_, channel_handle_, mode_,
+ listener);
}
private:
ChannelMojo::Delegate* delegate_;
+ scoped_refptr<base::TaskRunner> io_runner_;
ChannelHandle channel_handle_;
Channel::Mode mode_;
};
@@ -53,6 +59,7 @@ class ClientChannelMojo : public ChannelMojo,
public mojo::ErrorHandler {
public:
ClientChannelMojo(ChannelMojo::Delegate* delegate,
+ scoped_refptr<base::TaskRunner> io_runner,
const ChannelHandle& handle,
Listener* listener);
~ClientChannelMojo() override;
@@ -73,9 +80,10 @@ class ClientChannelMojo : public ChannelMojo,
};
ClientChannelMojo::ClientChannelMojo(ChannelMojo::Delegate* delegate,
+ scoped_refptr<base::TaskRunner> io_runner,
const ChannelHandle& handle,
Listener* listener)
- : ChannelMojo(delegate, handle, Channel::MODE_CLIENT, listener),
+ : ChannelMojo(delegate, io_runner, handle, Channel::MODE_CLIENT, listener),
binding_(this) {
}
@@ -104,6 +112,7 @@ void ClientChannelMojo::Init(
class ServerChannelMojo : public ChannelMojo, public mojo::ErrorHandler {
public:
ServerChannelMojo(ChannelMojo::Delegate* delegate,
+ scoped_refptr<base::TaskRunner> io_runner,
const ChannelHandle& handle,
Listener* listener);
~ServerChannelMojo() override;
@@ -126,9 +135,10 @@ class ServerChannelMojo : public ChannelMojo, public mojo::ErrorHandler {
};
ServerChannelMojo::ServerChannelMojo(ChannelMojo::Delegate* delegate,
+ scoped_refptr<base::TaskRunner> io_runner,
const ChannelHandle& handle,
Listener* listener)
- : ChannelMojo(delegate, handle, Channel::MODE_SERVER, listener) {
+ : ChannelMojo(delegate, io_runner, handle, Channel::MODE_SERVER, listener) {
}
ServerChannelMojo::~ServerChannelMojo() {
@@ -196,17 +206,19 @@ bool ChannelMojo::ShouldBeUsed() {
}
// static
-scoped_ptr<ChannelMojo> ChannelMojo::Create(ChannelMojo::Delegate* delegate,
- const ChannelHandle& channel_handle,
- Mode mode,
- Listener* listener) {
+scoped_ptr<ChannelMojo> ChannelMojo::Create(
+ ChannelMojo::Delegate* delegate,
+ scoped_refptr<base::TaskRunner> io_runner,
+ const ChannelHandle& channel_handle,
+ Mode mode,
+ Listener* listener) {
switch (mode) {
case Channel::MODE_CLIENT:
return make_scoped_ptr(
- new ClientChannelMojo(delegate, channel_handle, listener));
+ new ClientChannelMojo(delegate, io_runner, channel_handle, listener));
case Channel::MODE_SERVER:
return make_scoped_ptr(
- new ServerChannelMojo(delegate, channel_handle, listener));
+ new ServerChannelMojo(delegate, io_runner, channel_handle, listener));
default:
NOTREACHED();
return nullptr;
@@ -216,20 +228,23 @@ scoped_ptr<ChannelMojo> ChannelMojo::Create(ChannelMojo::Delegate* delegate,
// static
scoped_ptr<ChannelFactory> ChannelMojo::CreateServerFactory(
ChannelMojo::Delegate* delegate,
+ scoped_refptr<base::TaskRunner> io_runner,
const ChannelHandle& channel_handle) {
- return make_scoped_ptr(
- new MojoChannelFactory(delegate, channel_handle, Channel::MODE_SERVER));
+ return make_scoped_ptr(new MojoChannelFactory(
+ delegate, io_runner, channel_handle, Channel::MODE_SERVER));
}
// static
scoped_ptr<ChannelFactory> ChannelMojo::CreateClientFactory(
ChannelMojo::Delegate* delegate,
+ scoped_refptr<base::TaskRunner> io_runner,
const ChannelHandle& channel_handle) {
- return make_scoped_ptr(
- new MojoChannelFactory(delegate, channel_handle, Channel::MODE_CLIENT));
+ return make_scoped_ptr(new MojoChannelFactory(
+ delegate, io_runner, channel_handle, Channel::MODE_CLIENT));
}
ChannelMojo::ChannelMojo(ChannelMojo::Delegate* delegate,
+ scoped_refptr<base::TaskRunner> io_runner,
const ChannelHandle& handle,
Mode mode,
Listener* listener)
@@ -240,16 +255,12 @@ ChannelMojo::ChannelMojo(ChannelMojo::Delegate* delegate,
// Create MojoBootstrap after all members are set as it touches
// ChannelMojo from a different thread.
bootstrap_ = MojoBootstrap::Create(handle, mode, this);
- if (delegate) {
- if (delegate->GetIOTaskRunner() ==
- base::MessageLoop::current()->message_loop_proxy()) {
- InitDelegate(delegate);
- } else {
- delegate->GetIOTaskRunner()->PostTask(
- FROM_HERE,
- base::Bind(
- &ChannelMojo::InitDelegate, base::Unretained(this), delegate));
- }
+ if (io_runner == base::MessageLoop::current()->message_loop_proxy()) {
+ InitOnIOThread(delegate);
+ } else {
+ io_runner->PostTask(FROM_HERE,
+ base::Bind(&ChannelMojo::InitOnIOThread,
+ base::Unretained(this), delegate));
}
}
@@ -257,9 +268,11 @@ ChannelMojo::~ChannelMojo() {
Close();
}
-void ChannelMojo::InitDelegate(ChannelMojo::Delegate* delegate) {
+void ChannelMojo::InitOnIOThread(ChannelMojo::Delegate* delegate) {
ipc_support_.reset(
new ScopedIPCSupport(base::MessageLoop::current()->task_runner()));
+ if (!delegate)
+ return;
delegate_ = delegate->ToWeakPtr();
delegate_->OnChannelCreated(weak_factory_.GetWeakPtr());
}
« no previous file with comments | « ipc/mojo/ipc_channel_mojo.h ('k') | ipc/mojo/ipc_channel_mojo_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698