Chromium Code Reviews| Index: media/base/message_loop_factory.cc |
| diff --git a/media/base/message_loop_factory.cc b/media/base/message_loop_factory.cc |
| index 22ec96c9a21cc166adf2a405d7c39201a18fea3f..7764175f3826a5782fe7b38a6d2b6504a02b3896 100644 |
| --- a/media/base/message_loop_factory.cc |
| +++ b/media/base/message_loop_factory.cc |
| @@ -8,6 +8,17 @@ |
| namespace media { |
| +struct MessageLoopTypeNamePair { |
| + MessageLoopFactory::MessageLoopType type; |
| + const char* name; |
| +}; |
| + |
| +static const MessageLoopTypeNamePair message_loop_type_to_name_mapping[] = { |
|
scherkus (not reviewing)
2012/08/09 17:13:24
this should be kMessageLoopXxx
xhwang
2012/08/10 01:04:28
Done.
|
| + { MessageLoopFactory::AUDIO_DECODER, "AudioDecoderThread" }, |
| + { MessageLoopFactory::VIDEO_DECODER, "VideoDecoderThread" }, |
| + { MessageLoopFactory::PIPELINE, "PipelineThread" } |
| +}; |
| + |
| MessageLoopFactory::MessageLoopFactory() {} |
| MessageLoopFactory::~MessageLoopFactory() { |
| @@ -20,27 +31,32 @@ MessageLoopFactory::~MessageLoopFactory() { |
| threads_.clear(); |
| } |
| -MessageLoop* MessageLoopFactory::GetMessageLoop(const std::string& name) { |
| - return GetThread(name)->message_loop(); |
| +MessageLoop* MessageLoopFactory::GetMessageLoop(MessageLoopType type) { |
| + return GetThread(type)->message_loop(); |
| } |
| scoped_refptr<base::MessageLoopProxy> |
| -MessageLoopFactory::GetMessageLoopProxy(const std::string& name) { |
| - return GetThread(name)->message_loop_proxy(); |
| +MessageLoopFactory::GetMessageLoopProxy(MessageLoopType type) { |
| + return GetThread(type)->message_loop_proxy(); |
| } |
| -base::Thread* MessageLoopFactory::GetThread(const std::string& name) { |
| - DCHECK(!name.empty()); |
| - |
| +base::Thread* MessageLoopFactory::GetThread(MessageLoopType type) { |
| base::AutoLock auto_lock(lock_); |
| for (ThreadList::iterator it = threads_.begin(); it != threads_.end(); ++it) { |
| - if (it->first == name) |
| + if (it->first == type) |
| return it->second; |
| } |
| + std::string name; |
| + for (size_t i = 0; i < arraysize(message_loop_type_to_name_mapping); ++i) { |
| + if (message_loop_type_to_name_mapping[i].type == type) |
| + name = message_loop_type_to_name_mapping[i].name; |
| + } |
| + DCHECK(!name.empty()); |
| + |
| base::Thread* thread = new base::Thread(name.c_str()); |
| CHECK(thread->Start()) << "Failed to start thread: " << name; |
| - threads_.push_back(std::make_pair(name, thread)); |
| + threads_.push_back(std::make_pair(type, thread)); |
| return thread; |
| } |