Adds the ability for MessageLoop to take a MessagePump

Using default args is against style guide, but there are a ton of
places (mostly tests) that define a MessageLoop as a member. I'll see
about a cleanup pass that removes the default args.

BUG=none
TEST=NONE
R=darin@chromium.org

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@233800 0039d316-1c4b-4281-b951-d872f2087c98


CrOS-Libchrome-Original-Commit: 9f0e4f712366b55628efeffca4e55438aef80691
diff --git a/base/message_loop/message_loop.cc b/base/message_loop/message_loop.cc
index 7cd22a8..6d3d59c 100644
--- a/base/message_loop/message_loop.cc
+++ b/base/message_loop/message_loop.cc
@@ -144,14 +144,7 @@
 #endif  // OS_WIN
       message_histogram_(NULL),
       run_loop_(NULL) {
-  DCHECK(!current()) << "should only have one message loop per thread";
-  lazy_tls_ptr.Pointer()->Set(this);
-
-  incoming_task_queue_ = new internal::IncomingTaskQueue(this);
-  message_loop_proxy_ =
-      new internal::MessageLoopProxyImpl(incoming_task_queue_);
-  thread_task_runner_handle_.reset(
-      new ThreadTaskRunnerHandle(message_loop_proxy_));
+  Init();
 
 // TODO(rvargas): Get rid of the OS guards.
 #if defined(OS_WIN)
@@ -198,6 +191,20 @@
   }
 }
 
+MessageLoop::MessageLoop(scoped_ptr<MessagePump> pump)
+    : pump_(pump.Pass()),
+      type_(TYPE_CUSTOM),
+      exception_restoration_(false),
+      nestable_tasks_allowed_(true),
+#if defined(OS_WIN)
+      os_modal_loop_(false),
+#endif  // OS_WIN
+      message_histogram_(NULL),
+      run_loop_(NULL) {
+  DCHECK(pump_.get());
+  Init();
+}
+
 MessageLoop::~MessageLoop() {
   DCHECK_EQ(this, current());
 
@@ -397,6 +404,17 @@
 
 //------------------------------------------------------------------------------
 
+void MessageLoop::Init() {
+  DCHECK(!current()) << "should only have one message loop per thread";
+  lazy_tls_ptr.Pointer()->Set(this);
+
+  incoming_task_queue_ = new internal::IncomingTaskQueue(this);
+  message_loop_proxy_ =
+      new internal::MessageLoopProxyImpl(incoming_task_queue_);
+  thread_task_runner_handle_.reset(
+      new ThreadTaskRunnerHandle(message_loop_proxy_));
+}
+
 // Runs the loop in two different SEH modes:
 // enable_SEH_restoration_ = false : any unhandled exception goes to the last
 // one that calls SetUnhandledExceptionFilter().