Chromium Code Reviews| Index: media/base/message_loop_factory_impl.cc |
| diff --git a/media/base/message_loop_factory_impl.cc b/media/base/message_loop_factory_impl.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..af655b28e82b3e977ff71f9136d2e3cbcf8ebce2 |
| --- /dev/null |
| +++ b/media/base/message_loop_factory_impl.cc |
| @@ -0,0 +1,54 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "media/base/message_loop_factory_impl.h" |
| + |
| +namespace media { |
| + |
| +MessageLoopFactoryImpl::MessageLoopFactoryImpl() {} |
| + |
| +MessageLoopFactoryImpl::~MessageLoopFactoryImpl() { |
| + AutoLock auto_lock(lock_); |
| + |
| + for (ThreadMap::iterator iter = thread_map_.begin(); |
| + iter != thread_map_.end(); |
| + ++iter) { |
| + base::Thread* thread = (*iter).second; |
| + |
| + if (thread) { |
| + thread->Stop(); |
| + delete thread; |
| + } |
| + } |
| + thread_map_.clear(); |
| +} |
| + |
| +// MessageLoopFactory methods. |
| +MessageLoop* MessageLoopFactoryImpl::GetMessageLoop(const std::string& name) { |
| + if (name.empty()) { |
| + return NULL; |
| + } |
| + |
| + MessageLoop* message_loop = NULL; |
| + AutoLock auto_lock(lock_); |
| + |
| + base::Thread* thread = thread_map_[std::string(name)]; |
|
scherkus (not reviewing)
2011/01/13 23:52:50
no need for std::string ctor here
also do we want
acolwell GONE FROM CHROMIUM
2011/01/14 01:14:12
Done. Changed code to use find.
On 2011/01/13 23:
|
| + |
| + if (!thread) { |
| + thread = new base::Thread(name.c_str()); |
| + |
| + if (thread->Start()) { |
| + thread_map_[name] = thread; |
| + message_loop = thread->message_loop(); |
|
scherkus (not reviewing)
2011/01/13 23:52:50
wondering if we can clean up these nested ifs by j
acolwell GONE FROM CHROMIUM
2011/01/14 01:14:12
Done.
|
| + } else { |
| + delete thread; |
|
scherkus (not reviewing)
2011/01/13 23:52:50
maybe LOG(ERROR)?
acolwell GONE FROM CHROMIUM
2011/01/14 01:14:12
Done.
|
| + } |
| + } else { |
| + message_loop = thread->message_loop(); |
| + } |
| + |
| + return message_loop; |
| +} |
| + |
| +} // namespace media |