summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorskyostil <skyostil@chromium.org>2015-03-04 12:20:46 -0800
committerCommit bot <commit-bot@chromium.org>2015-03-04 20:21:19 +0000
commitf28ccd0b2709832d05156bd107d29d48a4a440cc (patch)
tree48bb3c6a2bd75e833331a80642a793df7945bafc
parent3ec467e4a16884c3855745e2f7513132098a4e36 (diff)
downloadchromium_src-f28ccd0b2709832d05156bd107d29d48a4a440cc.zip
chromium_src-f28ccd0b2709832d05156bd107d29d48a4a440cc.tar.gz
chromium_src-f28ccd0b2709832d05156bd107d29d48a4a440cc.tar.bz2
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}
-rw-r--r--content/child/child_thread_impl.cc40
-rw-r--r--content/child/child_thread_impl.h43
-rw-r--r--content/gpu/gpu_child_thread.cc11
-rw-r--r--content/renderer/render_thread_impl.cc17
-rw-r--r--content/utility/utility_thread_impl.cc5
5 files changed, 88 insertions, 28 deletions
diff --git a/content/child/child_thread_impl.cc b/content/child/child_thread_impl.cc
index 8acc37d..f62222c 100644
--- a/content/child/child_thread_impl.cc
+++ b/content/child/child_thread_impl.cc
@@ -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)
diff --git a/content/child/child_thread_impl.h b/content/child/child_thread_impl.h
index b6094b5..03727d6 100644
--- a/content/child/child_thread_impl.h
+++ b/content/child/child_thread_impl.h
@@ -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_
diff --git a/content/gpu/gpu_child_thread.cc b/content/gpu/gpu_child_thread.cc
index 1064a70..901618e 100644
--- a/content/gpu/gpu_child_thread.cc
+++ b/content/gpu/gpu_child_thread.cc
@@ -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)
diff --git a/content/renderer/render_thread_impl.cc b/content/renderer/render_thread_impl.cc
index a5a3917..0291a86 100644
--- a/content/renderer/render_thread_impl.cc
+++ b/content/renderer/render_thread_impl.cc
@@ -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();
}
diff --git a/content/utility/utility_thread_impl.cc b/content/utility/utility_thread_impl.cc
index 26af2b1..d1b9bfa 100644
--- a/content/utility/utility_thread_impl.cc
+++ b/content/utility/utility_thread_impl.cc
@@ -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();
}