Index: base/message_loop/message_loop.cc |
diff --git a/base/message_loop/message_loop.cc b/base/message_loop/message_loop.cc |
index 7cd22a876553817ee788c09cbfdd3c05a45c4695..7357ed3bf857f2afcd962e03c75fd168170025c8 100644 |
--- a/base/message_loop/message_loop.cc |
+++ b/base/message_loop/message_loop.cc |
@@ -98,6 +98,50 @@ bool AlwaysNotifyPump(MessageLoop::Type type) { |
#endif |
} |
+MessagePump* CreateMessagePump(MessageLoop::Type type) { |
+// TODO(rvargas): Get rid of the OS guards. |
+#if defined(OS_WIN) |
+#define MESSAGE_PUMP_UI new MessagePumpForUI() |
+#define MESSAGE_PUMP_IO new MessagePumpForIO() |
+#elif defined(OS_IOS) |
+#define MESSAGE_PUMP_UI MessagePumpMac::Create() |
+#define MESSAGE_PUMP_IO new MessagePumpIOSForIO() |
+#elif defined(OS_MACOSX) |
+#define MESSAGE_PUMP_UI MessagePumpMac::Create() |
+#define MESSAGE_PUMP_IO new MessagePumpLibevent() |
+#elif defined(OS_NACL) |
+// Currently NaCl doesn't have a UI MessageLoop. |
+// TODO(abarth): Figure out if we need this. |
+#define MESSAGE_PUMP_UI NULL |
+// ipc_channel_nacl.cc uses a worker thread to do socket reads currently, and |
+// doesn't require extra support for watching file descriptors. |
+#define MESSAGE_PUMP_IO new MessagePumpDefault() |
+#elif defined(OS_POSIX) // POSIX but not MACOSX. |
+#define MESSAGE_PUMP_UI new MessagePumpForUI() |
+#define MESSAGE_PUMP_IO new MessagePumpLibevent() |
+#else |
+#error Not implemented |
+#endif |
+ |
+ if (type == MessageLoop::TYPE_UI) { |
+ if (message_pump_for_ui_factory_) |
+ return message_pump_for_ui_factory_(); |
+ return MESSAGE_PUMP_UI; |
+ } |
+ if (type == MessageLoop::TYPE_IO) |
+ return MESSAGE_PUMP_IO; |
+#if defined(TOOLKIT_GTK) |
+ if (type == MessageLoop::TYPE_GPU) |
+ return new MessagePumpX11(); |
+#endif |
+#if defined(OS_ANDROID) |
+ if (type == MessageLoop::TYPE_JAVA) |
+ return MESSAGE_PUMP_UI; |
+#endif |
+ DCHECK_EQ(MessageLoop::TYPE_DEFAULT, type); |
+ return new MessagePumpDefault(); |
+} |
+ |
} // namespace |
//------------------------------------------------------------------------------ |
@@ -135,8 +179,9 @@ MessageLoop::DestructionObserver::~DestructionObserver() { |
//------------------------------------------------------------------------------ |
-MessageLoop::MessageLoop(Type type) |
- : type_(type), |
+MessageLoop::MessageLoop(Type type, MessagePump* message_pump) |
+ : pump_(message_pump), |
+ type_(type), |
exception_restoration_(false), |
nestable_tasks_allowed_(true), |
#if defined(OS_WIN) |
@@ -153,49 +198,8 @@ MessageLoop::MessageLoop(Type type) |
thread_task_runner_handle_.reset( |
new ThreadTaskRunnerHandle(message_loop_proxy_)); |
-// TODO(rvargas): Get rid of the OS guards. |
-#if defined(OS_WIN) |
-#define MESSAGE_PUMP_UI new MessagePumpForUI() |
-#define MESSAGE_PUMP_IO new MessagePumpForIO() |
-#elif defined(OS_IOS) |
-#define MESSAGE_PUMP_UI MessagePumpMac::Create() |
-#define MESSAGE_PUMP_IO new MessagePumpIOSForIO() |
-#elif defined(OS_MACOSX) |
-#define MESSAGE_PUMP_UI MessagePumpMac::Create() |
-#define MESSAGE_PUMP_IO new MessagePumpLibevent() |
-#elif defined(OS_NACL) |
-// Currently NaCl doesn't have a UI MessageLoop. |
-// TODO(abarth): Figure out if we need this. |
-#define MESSAGE_PUMP_UI NULL |
-// ipc_channel_nacl.cc uses a worker thread to do socket reads currently, and |
-// doesn't require extra support for watching file descriptors. |
-#define MESSAGE_PUMP_IO new MessagePumpDefault() |
-#elif defined(OS_POSIX) // POSIX but not MACOSX. |
-#define MESSAGE_PUMP_UI new MessagePumpForUI() |
-#define MESSAGE_PUMP_IO new MessagePumpLibevent() |
-#else |
-#error Not implemented |
-#endif |
- |
- if (type_ == TYPE_UI) { |
- if (message_pump_for_ui_factory_) |
- pump_.reset(message_pump_for_ui_factory_()); |
- else |
- pump_.reset(MESSAGE_PUMP_UI); |
- } else if (type_ == TYPE_IO) { |
- pump_.reset(MESSAGE_PUMP_IO); |
-#if defined(TOOLKIT_GTK) |
- } else if (type_ == TYPE_GPU) { |
- pump_.reset(new MessagePumpX11()); |
-#endif |
-#if defined(OS_ANDROID) |
- } else if (type_ == TYPE_JAVA) { |
- pump_.reset(MESSAGE_PUMP_UI); |
-#endif |
- } else { |
- DCHECK_EQ(TYPE_DEFAULT, type_); |
- pump_.reset(new MessagePumpDefault()); |
- } |
+ if (!pump_.get()) |
+ pump_.reset(CreateMessagePump(type)); |
} |
MessageLoop::~MessageLoop() { |