summaryrefslogtreecommitdiffstats
path: root/base/threading
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-08 06:16:53 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-08 06:16:53 +0000
commit9f0e4f712366b55628efeffca4e55438aef80691 (patch)
tree1b3c1fb6465493809b58731520fae9e0b8c947a8 /base/threading
parentada24fdfa9a21a23b4bbe792d2b56deff2be6f81 (diff)
downloadchromium_src-9f0e4f712366b55628efeffca4e55438aef80691.zip
chromium_src-9f0e4f712366b55628efeffca4e55438aef80691.tar.gz
chromium_src-9f0e4f712366b55628efeffca4e55438aef80691.tar.bz2
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
Diffstat (limited to 'base/threading')
-rw-r--r--base/threading/thread.cc24
-rw-r--r--base/threading/thread.h21
2 files changed, 39 insertions, 6 deletions
diff --git a/base/threading/thread.cc b/base/threading/thread.cc
index aca4ddb..ae4d373 100644
--- a/base/threading/thread.cc
+++ b/base/threading/thread.cc
@@ -49,6 +49,20 @@ struct Thread::StartupData {
event(false, false) {}
};
+Thread::Options::Options()
+ : message_loop_type(MessageLoop::TYPE_DEFAULT),
+ stack_size(0) {
+}
+
+Thread::Options::Options(MessageLoop::Type type,
+ size_t size)
+ : message_loop_type(type),
+ stack_size(size) {
+}
+
+Thread::Options::~Options() {
+}
+
Thread::Thread(const char* name)
:
#if defined(OS_WIN)
@@ -174,8 +188,14 @@ void Thread::ThreadMain() {
{
// The message loop for this thread.
// Allocated on the heap to centralize any leak reports at this line.
- scoped_ptr<MessageLoop> message_loop(
- new MessageLoop(startup_data_->options.message_loop_type));
+ scoped_ptr<MessageLoop> message_loop;
+ if (!startup_data_->options.message_pump_factory.is_null()) {
+ message_loop.reset(
+ new MessageLoop(startup_data_->options.message_pump_factory.Run()));
+ } else {
+ message_loop.reset(
+ new MessageLoop(startup_data_->options.message_loop_type));
+ }
// Complete the initialization of our Thread object.
thread_id_ = PlatformThread::CurrentId();
diff --git a/base/threading/thread.h b/base/threading/thread.h
index 98831b8..99f9dd4 100644
--- a/base/threading/thread.h
+++ b/base/threading/thread.h
@@ -8,12 +8,16 @@
#include <string>
#include "base/base_export.h"
+#include "base/callback.h"
+#include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop.h"
#include "base/message_loop/message_loop_proxy.h"
#include "base/threading/platform_thread.h"
namespace base {
+class MessagePump;
+
// A simple thread abstraction that establishes a MessageLoop on a new thread.
// The consumer uses the MessageLoop of the thread to cause code to execute on
// the thread. When this object is destroyed the thread is terminated. All
@@ -29,14 +33,23 @@ namespace base {
// (3.b) MessageLoop::DestructionObserver::WillDestroyCurrentMessageLoop
class BASE_EXPORT Thread : PlatformThread::Delegate {
public:
- struct Options {
- Options() : message_loop_type(MessageLoop::TYPE_DEFAULT), stack_size(0) {}
- Options(MessageLoop::Type type, size_t size)
- : message_loop_type(type), stack_size(size) {}
+ struct BASE_EXPORT Options {
+ typedef Callback<scoped_ptr<MessagePump>()> MessagePumpFactory;
+
+ Options();
+ Options(MessageLoop::Type type, size_t size);
+ ~Options();
// Specifies the type of message loop that will be allocated on the thread.
+ // This is ignored if message_pump_factory.is_null() is false.
MessageLoop::Type message_loop_type;
+ // Used to create the MessagePump for the MessageLoop. The callback is Run()
+ // on the thread. If message_pump_factory.is_null(), then a MessagePump
+ // appropriate for |message_loop_type| is created. Setting this forces the
+ // MessageLoop::Type to TYPE_CUSTOM.
+ MessagePumpFactory message_pump_factory;
+
// Specifies the maximum stack size that the thread is allowed to use.
// This does not necessarily correspond to the thread's initial stack size.
// A value of 0 indicates that the default maximum should be used.