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}
diff --git a/content/child/child_thread_impl.cc b/content/child/child_thread_impl.cc
index 8acc37d..f62222c7 100644
--- a/content/child/child_thread_impl.cc
+++ b/content/child/child_thread_impl.cc
@@ -248,20 +248,42 @@
       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(std::string name, bool mojo)
-    : channel_name(name), use_mojo_channel(mojo), in_browser_process(true) {
-}
-
 ChildThreadImpl::Options::~Options() {
 }
 
+ChildThreadImpl::Options::Builder::Builder() {
+}
+
+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(
     IPC::Sender* sender)
     : sender_(sender) {}
@@ -274,7 +296,7 @@
     : 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 @@
     : 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 @@
   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 @@
 }
 
 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(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 @@
 // 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(const std::string& channel_name)
-    : ChildThreadImpl(Options(channel_name, false)),
+    : ChildThreadImpl(Options::Builder()
+                          .InBrowserProcess(true)
+                          .WithChannelName(channel_name)
+                          .Build()),
       single_process_(true) {
   Init();
 }