Used scoped_ptr
There was this TODO(sky): convert this and InitMessagePumpForUIFactory() to return a
scoped_ptr.
This patch is for doing the same.
R=darin@chromium.org, sky@chromium.org
Review URL: https://codereview.chromium.org/185413019
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@255643 0039d316-1c4b-4281-b951-d872f2087c98
CrOS-Libchrome-Original-Commit: eed3318eaa4bb5a8c252093c4d9881b4ef14de99
diff --git a/base/message_loop/message_loop.cc b/base/message_loop/message_loop.cc
index e14ce85..229eae7 100644
--- a/base/message_loop/message_loop.cc
+++ b/base/message_loop/message_loop.cc
@@ -125,7 +125,7 @@
run_loop_(NULL) {
Init();
- pump_.reset(CreateMessagePumpForType(type));
+ pump_ = CreateMessagePumpForType(type).Pass();
}
MessageLoop::MessageLoop(scoped_ptr<MessagePump> pump)
@@ -201,27 +201,27 @@
}
// static
-MessagePump* MessageLoop::CreateMessagePumpForType(Type type) {
+scoped_ptr<MessagePump> MessageLoop::CreateMessagePumpForType(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()
+#define MESSAGE_PUMP_UI scoped_ptr<MessagePump>(new MessagePumpForUI())
+#define MESSAGE_PUMP_IO scoped_ptr<MessagePump>(new MessagePumpForIO())
#elif defined(OS_IOS)
-#define MESSAGE_PUMP_UI MessagePumpMac::Create()
-#define MESSAGE_PUMP_IO new MessagePumpIOSForIO()
+#define MESSAGE_PUMP_UI scoped_ptr<MessagePump>(MessagePumpMac::Create())
+#define MESSAGE_PUMP_IO scoped_ptr<MessagePump>(new MessagePumpIOSForIO())
#elif defined(OS_MACOSX)
-#define MESSAGE_PUMP_UI MessagePumpMac::Create()
-#define MESSAGE_PUMP_IO new MessagePumpLibevent()
+#define MESSAGE_PUMP_UI scoped_ptr<MessagePump>(MessagePumpMac::Create())
+#define MESSAGE_PUMP_IO scoped_ptr<MessagePump>(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
+#define MESSAGE_PUMP_UI scoped_ptr<MessagePump>()
// 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()
+#define MESSAGE_PUMP_IO scoped_ptr<MessagePump>(new MessagePumpDefault())
#elif defined(OS_POSIX) // POSIX but not MACOSX.
-#define MESSAGE_PUMP_UI new MessagePumpForUI()
-#define MESSAGE_PUMP_IO new MessagePumpLibevent()
+#define MESSAGE_PUMP_UI scoped_ptr<MessagePump>(new MessagePumpForUI())
+#define MESSAGE_PUMP_IO scoped_ptr<MessagePump>(new MessagePumpLibevent())
#else
#error Not implemented
#endif
@@ -235,14 +235,14 @@
return MESSAGE_PUMP_IO;
#if defined(TOOLKIT_GTK)
if (type == MessageLoop::TYPE_GPU)
- return new MessagePumpX11();
+ return scoped_ptr<MessagePump>(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();
+ return scoped_ptr<MessagePump>(new MessagePumpDefault());
}
void MessageLoop::AddDestructionObserver(
diff --git a/base/message_loop/message_loop.h b/base/message_loop/message_loop.h
index 956f5f0..400a5ec 100644
--- a/base/message_loop/message_loop.h
+++ b/base/message_loop/message_loop.h
@@ -154,7 +154,7 @@
static void EnableHistogrammer(bool enable_histogrammer);
- typedef MessagePump* (MessagePumpFactory)();
+ typedef scoped_ptr<MessagePump> (MessagePumpFactory)();
// Uses the given base::MessagePumpForUIFactory to override the default
// MessagePump implementation for 'TYPE_UI'. Returns true if the factory
// was successfully registered.
@@ -162,10 +162,7 @@
// Creates the default MessagePump based on |type|. Caller owns return
// value.
- // TODO(sky): convert this and InitMessagePumpForUIFactory() to return a
- // scoped_ptr.
- static MessagePump* CreateMessagePumpForType(Type type);
-
+ static scoped_ptr<MessagePump> CreateMessagePumpForType(Type type);
// A DestructionObserver is notified when the current MessageLoop is being
// destroyed. These observers are notified prior to MessageLoop::current()
// being changed to return NULL. This gives interested parties the chance to
diff --git a/base/message_loop/message_loop_unittest.cc b/base/message_loop/message_loop_unittest.cc
index 7921c9b..4637165 100644
--- a/base/message_loop/message_loop_unittest.cc
+++ b/base/message_loop/message_loop_unittest.cc
@@ -36,15 +36,15 @@
namespace {
-MessagePump* TypeDefaultMessagePumpFactory() {
+scoped_ptr<MessagePump> TypeDefaultMessagePumpFactory() {
return MessageLoop::CreateMessagePumpForType(MessageLoop::TYPE_DEFAULT);
}
-MessagePump* TypeIOMessagePumpFactory() {
+scoped_ptr<MessagePump> TypeIOMessagePumpFactory() {
return MessageLoop::CreateMessagePumpForType(MessageLoop::TYPE_IO);
}
-MessagePump* TypeUIMessagePumpFactory() {
+scoped_ptr<MessagePump> TypeUIMessagePumpFactory() {
return MessageLoop::CreateMessagePumpForType(MessageLoop::TYPE_UI);
}