diff options
author | wjia@google.com <wjia@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-07 02:06:23 +0000 |
---|---|---|
committer | wjia@google.com <wjia@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-07 02:06:23 +0000 |
commit | 79ba6c7b6058c27f114fb339dec33a95e57752a5 (patch) | |
tree | 31fa4c553d8501575c1a9f8cd2fbc69794f5dfcb /media | |
parent | 68f88b99c791834d90017decb2b49f79c8905dc3 (diff) | |
download | chromium_src-79ba6c7b6058c27f114fb339dec33a95e57752a5.zip chromium_src-79ba6c7b6058c27f114fb339dec33a95e57752a5.tar.gz chromium_src-79ba6c7b6058c27f114fb339dec33a95e57752a5.tar.bz2 |
add MessageLoopProxy in MessageLoopFactory
bug=None
TEST=try bots
Review URL: http://codereview.chromium.org/6951013
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@84540 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media')
-rw-r--r-- | media/base/message_loop_factory.h | 10 | ||||
-rw-r--r-- | media/base/message_loop_factory_impl.cc | 25 | ||||
-rw-r--r-- | media/base/message_loop_factory_impl.h | 2 |
3 files changed, 37 insertions, 0 deletions
diff --git a/media/base/message_loop_factory.h b/media/base/message_loop_factory.h index 7ed6412..35078ed 100644 --- a/media/base/message_loop_factory.h +++ b/media/base/message_loop_factory.h @@ -7,7 +7,9 @@ #include <string> +#include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" +#include "base/message_loop_proxy.h" class MessageLoop; @@ -23,6 +25,14 @@ class MessageLoopFactory { // creation process. virtual MessageLoop* GetMessageLoop(const std::string& name) = 0; + // Get the message loop proxy associated with |name|. A new MessageLoopProxy + // is created if the factory doesn't have one associated with |name|. + // NULL is returned if |name| is an empty string, or a new + // MessageLoop needs to be created and a failure occurs during the + // creation process. + virtual scoped_refptr<base::MessageLoopProxy> GetMessageLoopProxy( + const std::string& name) = 0; + protected: // Only allow scoped_ptr<> to delete factory. friend class scoped_ptr<MessageLoopFactory>; diff --git a/media/base/message_loop_factory_impl.cc b/media/base/message_loop_factory_impl.cc index ebe64a4..6cf12da 100644 --- a/media/base/message_loop_factory_impl.cc +++ b/media/base/message_loop_factory_impl.cc @@ -48,4 +48,29 @@ MessageLoop* MessageLoopFactoryImpl::GetMessageLoop(const std::string& name) { return NULL; } +scoped_refptr<base::MessageLoopProxy> +MessageLoopFactoryImpl::GetMessageLoopProxy(const std::string& name) { + if (name.empty()) { + return NULL; + } + + base::AutoLock auto_lock(lock_); + + ThreadMap::iterator it = thread_map_.find(name); + if (it != thread_map_.end()) + return (*it).second->message_loop_proxy(); + + scoped_ptr<base::Thread> thread(new base::Thread(name.c_str())); + + if (thread->Start()) { + scoped_refptr<base::MessageLoopProxy> message_loop_proxy = + thread->message_loop_proxy(); + thread_map_[name] = thread.release(); + return message_loop_proxy; + } + + LOG(ERROR) << "Failed to start '" << name << "' thread!"; + return NULL; +} + } // namespace media diff --git a/media/base/message_loop_factory_impl.h b/media/base/message_loop_factory_impl.h index e7576ba..821cd66 100644 --- a/media/base/message_loop_factory_impl.h +++ b/media/base/message_loop_factory_impl.h @@ -19,6 +19,8 @@ class MessageLoopFactoryImpl : public MessageLoopFactory { // MessageLoopFactory methods. virtual MessageLoop* GetMessageLoop(const std::string& name); + virtual scoped_refptr<base::MessageLoopProxy> GetMessageLoopProxy( + const std::string& name); protected: virtual ~MessageLoopFactoryImpl(); |