MessageLoop: wire the unused static method in base::Thread (follow-up cleanup)
Actually use the private static method (CreateUnbound) in base::Thread.
I added the method in the last refactoring patch but forgot to use it;
I can either remove the static method or use it, I do the latter in this
patch as I thought leaving the private ctor of MessageLoop only for
delegated use-case cleaner.
BUG=465458
R=thakis@chromium.org
Review URL: https://codereview.chromium.org/1212193003
Cr-Commit-Position: refs/heads/master@{#336710}
CrOS-Libchrome-Original-Commit: 547a48bb006e275f1192c983a634e911c8c1edbd
diff --git a/base/message_loop/message_loop.h b/base/message_loop/message_loop.h
index b1b219a..1b6d407 100644
--- a/base/message_loop/message_loop.h
+++ b/base/message_loop/message_loop.h
@@ -415,7 +415,7 @@
// thread the message loop runs on, before calling Run().
// Before BindToCurrentThread() is called only Post*Task() functions can
// be called on the message loop.
- scoped_ptr<MessageLoop> CreateUnbound(
+ static scoped_ptr<MessageLoop> CreateUnbound(
Type type,
MessagePumpFactoryCallback pump_factory);
diff --git a/base/threading/thread.cc b/base/threading/thread.cc
index 6ca1cae..7bff242 100644
--- a/base/threading/thread.cc
+++ b/base/threading/thread.cc
@@ -94,8 +94,9 @@
type = MessageLoop::TYPE_CUSTOM;
message_loop_timer_slack_ = options.timer_slack;
- message_loop_ = new MessageLoop(type, options.message_pump_factory);
-
+ scoped_ptr<MessageLoop> message_loop = MessageLoop::CreateUnbound(
+ type, options.message_pump_factory);
+ message_loop_ = message_loop.get();
start_event_.reset(new WaitableEvent(false, false));
// Hold the thread_lock_ while starting a new thread, so that we can make sure
@@ -111,13 +112,16 @@
}
if (!created) {
DLOG(ERROR) << "failed to create thread";
- delete message_loop_;
message_loop_ = nullptr;
start_event_.reset();
return false;
}
}
+ // The ownership of message_loop is managemed by the newly created thread
+ // within the ThreadMain.
+ ignore_result(message_loop.release());
+
DCHECK(message_loop_);
return true;
}