Commit f28ccd0b authored by skyostil's avatar skyostil Committed by Commit bot

content: Refactor ChildThreadImpl::Options

Refactor the way options are passed to ChildThreadImpl to make the
call sites easier to read and to make it easier to add a task runner
parameter later.

BUG=444764

Review URL: https://codereview.chromium.org/974933002

Cr-Commit-Position: refs/heads/master@{#319117}
parent 3ec467e4
......@@ -248,18 +248,40 @@ ChildThreadImpl::Options::Options()
in_browser_process(false) {
}
ChildThreadImpl::Options::Options(bool mojo)
: channel_name(base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
switches::kProcessChannelID)),
use_mojo_channel(mojo),
in_browser_process(true) {
ChildThreadImpl::Options::~Options() {
}
ChildThreadImpl::Options::Options(std::string name, bool mojo)
: channel_name(name), use_mojo_channel(mojo), in_browser_process(true) {
ChildThreadImpl::Options::Builder::Builder() {
}
ChildThreadImpl::Options::~Options() {
ChildThreadImpl::Options::Builder&
ChildThreadImpl::Options::Builder::InBrowserProcess(bool in_browser_process) {
options_.in_browser_process = in_browser_process;
return *this;
}
ChildThreadImpl::Options::Builder&
ChildThreadImpl::Options::Builder::UseMojoChannel(bool use_mojo_channel) {
options_.use_mojo_channel = use_mojo_channel;
return *this;
}
ChildThreadImpl::Options::Builder&
ChildThreadImpl::Options::Builder::WithChannelName(
const std::string& channel_name) {
options_.channel_name = channel_name;
return *this;
}
ChildThreadImpl::Options::Builder&
ChildThreadImpl::Options::Builder::AddStartupFilter(
IPC::MessageFilter* filter) {
options_.startup_filters.push_back(filter);
return *this;
}
ChildThreadImpl::Options ChildThreadImpl::Options::Builder::Build() {
return options_;
}
ChildThreadImpl::ChildThreadMessageRouter::ChildThreadMessageRouter(
......@@ -274,7 +296,7 @@ ChildThreadImpl::ChildThreadImpl()
: router_(this),
in_browser_process_(false),
channel_connected_factory_(this) {
Init(Options());
Init(Options::Builder().Build());
}
ChildThreadImpl::ChildThreadImpl(const Options& options)
......
......@@ -62,17 +62,7 @@ class CONTENT_EXPORT ChildThreadImpl
: public IPC::Listener,
virtual public ChildThread {
public:
struct CONTENT_EXPORT Options {
Options();
explicit Options(bool mojo);
Options(std::string name, bool mojo);
~Options();
std::string channel_name;
bool use_mojo_channel;
bool in_browser_process;
std::vector<IPC::MessageFilter*> startup_filters;
};
struct CONTENT_EXPORT Options;
// Creates the thread.
ChildThreadImpl();
......@@ -315,6 +305,37 @@ class CONTENT_EXPORT ChildThreadImpl
DISALLOW_COPY_AND_ASSIGN(ChildThreadImpl);
};
struct ChildThreadImpl::Options {
~Options();
class Builder;
std::string channel_name;
bool use_mojo_channel;
bool in_browser_process;
std::vector<IPC::MessageFilter*> startup_filters;
private:
Options();
};
class ChildThreadImpl::Options::Builder {
public:
Builder();
Builder& InBrowserProcess(bool in_browser_process);
Builder& UseMojoChannel(bool use_mojo_channel);
Builder& WithChannelName(const std::string& channel_name);
Builder& AddStartupFilter(IPC::MessageFilter* filter);
Options Build();
private:
struct Options options_;
DISALLOW_COPY_AND_ASSIGN(Builder);
};
} // namespace content
#endif // CONTENT_CHILD_CHILD_THREAD_IMPL_H_
......@@ -45,17 +45,17 @@ bool GpuProcessLogMessageHandler(int severity,
}
ChildThreadImpl::Options GetOptions() {
ChildThreadImpl::Options options;
ChildThreadImpl::Options::Builder builder;
#if defined(USE_OZONE)
IPC::MessageFilter* message_filter = ui::OzonePlatform::GetInstance()
->GetGpuPlatformSupport()
->GetMessageFilter();
if (message_filter)
options.startup_filters.push_back(message_filter);
builder.AddStartupFilter(message_filter);
#endif
return options;
return builder.Build();
}
} // namespace
......@@ -77,7 +77,10 @@ GpuChildThread::GpuChildThread(GpuWatchdogThread* watchdog_thread,
}
GpuChildThread::GpuChildThread(const std::string& channel_id)
: ChildThreadImpl(Options(channel_id, false)),
: ChildThreadImpl(Options::Builder()
.InBrowserProcess(true)
.WithChannelName(channel_id)
.Build()),
dead_on_arrival_(false),
in_browser_process_(true) {
#if defined(OS_WIN)
......
......@@ -433,18 +433,29 @@ RenderThreadImpl* RenderThreadImpl::current() {
// When we run plugins in process, we actually run them on the render thread,
// which means that we need to make the render thread pump UI events.
RenderThreadImpl::RenderThreadImpl()
: ChildThreadImpl(Options(ShouldUseMojoChannel())) {
: ChildThreadImpl(Options::Builder()
.InBrowserProcess(true)
.UseMojoChannel(ShouldUseMojoChannel())
.Build()) {
Init();
}
RenderThreadImpl::RenderThreadImpl(const std::string& channel_name)
: ChildThreadImpl(Options(channel_name, ShouldUseMojoChannel())) {
: ChildThreadImpl(Options::Builder()
.InBrowserProcess(true)
.UseMojoChannel(ShouldUseMojoChannel())
.WithChannelName(channel_name)
.Build()) {
Init();
}
RenderThreadImpl::RenderThreadImpl(
scoped_ptr<base::MessageLoop> main_message_loop)
: ChildThreadImpl(Options(ShouldUseMojoChannel())),
: ChildThreadImpl(Options::Builder()
// TODO(skyostil): This should be set to false.
.InBrowserProcess(true)
.UseMojoChannel(ShouldUseMojoChannel())
.Build()),
main_message_loop_(main_message_loop.Pass()) {
Init();
}
......
......@@ -40,7 +40,10 @@ UtilityThreadImpl::UtilityThreadImpl() : single_process_(false) {
}
UtilityThreadImpl::UtilityThreadImpl(const std::string& channel_name)
: ChildThreadImpl(Options(channel_name, false)),
: ChildThreadImpl(Options::Builder()
.InBrowserProcess(true)
.WithChannelName(channel_name)
.Build()),
single_process_(true) {
Init();
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment