Move creation of capturer, input stub into ChromotingHost

BUG=None
TEST=None

Review URL: http://codereview.chromium.org/5065001

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@66390 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/remoting/host/chromoting_host.cc b/remoting/host/chromoting_host.cc
index c7fc7f5..e8b2ccc 100644
--- a/remoting/host/chromoting_host.cc
+++ b/remoting/host/chromoting_host.cc
@@ -8,12 +8,21 @@
 #include "base/task.h"
 #include "build/build_config.h"
 #include "remoting/base/constants.h"
+#if defined(OS_WIN)
+#include "remoting/host/capturer_gdi.h"
+#include "remoting/host/event_executor_win.h"
+#elif defined(OS_LINUX)
+#include "remoting/host/capturer_linux.h"
+#include "remoting/host/event_executor_linux.h"
+#elif defined(OS_MACOSX)
+#include "remoting/host/capturer_mac.h"
+#include "remoting/host/event_executor_mac.h"
+#endif
 #include "remoting/base/encoder.h"
 #include "remoting/base/encoder_verbatim.h"
 #include "remoting/base/encoder_vp8.h"
 #include "remoting/base/encoder_zlib.h"
 #include "remoting/host/chromoting_host_context.h"
-#include "remoting/host/capturer.h"
 #include "remoting/host/host_config.h"
 #include "remoting/host/host_stub_fake.h"
 #include "remoting/host/session_manager.h"
@@ -28,13 +37,44 @@
 namespace remoting {
 
 ChromotingHost::ChromotingHost(ChromotingHostContext* context,
-                               MutableHostConfig* config,
-                               Capturer* capturer,
-                               protocol::InputStub* input_stub)
+                               MutableHostConfig* config)
+    : context_(context),
+      config_(config),
+#if defined(OS_WIN)
+      capturer_(new remoting::CapturerGdi(
+          context->capture_message_loop())),
+      input_stub_(new remoting::EventExecutorWin(
+          context->capture_message_loop(), capturer_.get())),
+#elif defined(OS_LINUX)
+      capturer_(new remoting::CapturerLinux(
+          context->capture_message_loop())),
+      input_stub_(new remoting::EventExecutorLinux(
+          context->capture_message_loop(), capturer_.get())),
+#elif defined(OS_MACOSX)
+      capturer_(new remoting::CapturerMac(
+          context->capture_message_loop())),
+      input_stub_(new remoting::EventExecutorMac(
+          context->capture_message_loop(), capturer_.get())),
+#endif
+      host_stub_(new HostStubFake()),
+      state_(kInitial) {
+}
+
+ChromotingHost::ChromotingHost(ChromotingHostContext* context,
+                               MutableHostConfig* config, Capturer* capturer)
     : context_(context),
       config_(config),
       capturer_(capturer),
-      input_stub_(input_stub),
+#if defined(OS_WIN)
+      input_stub_(new remoting::EventExecutorWin(
+          context->capture_message_loop(), capturer)),
+#elif defined(OS_LINUX)
+      input_stub_(new remoting::EventExecutorLinux(
+          context->capture_message_loop(), capturer)),
+#elif defined(OS_MACOSX)
+      input_stub_(new remoting::EventExecutorMac(
+          context->capture_message_loop(), capturer)),
+#endif
       host_stub_(new HostStubFake()),
       state_(kInitial) {
 }
diff --git a/remoting/host/chromoting_host.h b/remoting/host/chromoting_host.h
index f3b908f..2294fdd 100644
--- a/remoting/host/chromoting_host.h
+++ b/remoting/host/chromoting_host.h
@@ -63,8 +63,9 @@
                        public protocol::ConnectionToClient::EventHandler,
                        public JingleClient::Callback {
  public:
+  ChromotingHost(ChromotingHostContext* context, MutableHostConfig* config);
   ChromotingHost(ChromotingHostContext* context, MutableHostConfig* config,
-                 Capturer* capturer, protocol::InputStub* input_stub);
+                 Capturer* capturer);
   virtual ~ChromotingHost();
 
   // Asynchronously start the host process.
diff --git a/remoting/host/simple_host_process.cc b/remoting/host/simple_host_process.cc
index 0a6ff42..5decb81 100644
--- a/remoting/host/simple_host_process.cc
+++ b/remoting/host/simple_host_process.cc
@@ -36,17 +36,6 @@
 #include "remoting/proto/video.pb.h"
 
 #if defined(OS_WIN)
-#include "remoting/host/capturer_gdi.h"
-#include "remoting/host/event_executor_win.h"
-#elif defined(OS_LINUX)
-#include "remoting/host/capturer_linux.h"
-#include "remoting/host/event_executor_linux.h"
-#elif defined(OS_MACOSX)
-#include "remoting/host/capturer_mac.h"
-#include "remoting/host/event_executor_mac.h"
-#endif
-
-#if defined(OS_WIN)
 const std::wstring kDefaultConfigPath = L".ChromotingConfig.json";
 const wchar_t kHomeDrive[] = L"HOMEDRIVE";
 const wchar_t kHomePath[] = L"HOMEPATH";
@@ -77,27 +66,6 @@
   remoting::ChromotingHostContext context;
   context.Start();
 
-  scoped_ptr<remoting::Capturer> capturer;
-  scoped_ptr<remoting::protocol::InputStub> input_stub;
-#if defined(OS_WIN)
-  capturer.reset(new remoting::CapturerGdi(
-      context.capture_message_loop()));
-  input_stub.reset(new remoting::EventExecutorWin(
-      context.capture_message_loop(), capturer.get()));
-#elif defined(OS_LINUX)
-  capturer.reset(new remoting::CapturerLinux(
-      context.capture_message_loop()));
-  input_stub.reset(new remoting::EventExecutorLinux(
-      context.capture_message_loop(), capturer.get()));
-#elif defined(OS_MACOSX)
-  capturer.reset(new remoting::CapturerMac(
-      context.capture_message_loop()));
-  input_stub.reset(new remoting::EventExecutorMac(
-      context.capture_message_loop(), capturer.get()));
-#endif
-
-  // Check the argument to see if we should use a fake capturer.
-  bool fake = cmd_line->HasSwitch(kFakeSwitchName);
 
 #if defined(OS_WIN)
   std::wstring home_path = GetEnvironmentVar(kHomeDrive);
@@ -111,12 +79,6 @@
     config_path = cmd_line->GetSwitchValuePath(kConfigSwitchName);
   }
 
-  if (fake) {
-    // Inject a fake capturer.
-    LOG(INFO) << "Using a fake capturer.";
-    capturer.reset(new remoting::CapturerFake(context.capture_message_loop()));
-  }
-
   base::Thread file_io_thread("FileIO");
   file_io_thread.Start();
 
@@ -136,11 +98,16 @@
       << "Cannot load media library";
 
   // Construct a chromoting host.
-  scoped_refptr<remoting::ChromotingHost> host(
-      new remoting::ChromotingHost(&context,
-                                   config,
-                                   capturer.release(),
-                                   input_stub.release()));
+  scoped_refptr<remoting::ChromotingHost> host;
+
+  bool fake = cmd_line->HasSwitch(kFakeSwitchName);
+  if (fake) {
+    host = new remoting::ChromotingHost(
+        &context, config,
+        new remoting::CapturerFake(context.capture_message_loop()));
+  } else {
+    host = new remoting::ChromotingHost(&context, config);
+  }
 
   // Let the chromoting host run until the shutdown task is executed.
   MessageLoop message_loop(MessageLoop::TYPE_UI);