OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "media/base/message_loop_factory.h" | 5 #include "media/base/message_loop_factory.h" |
6 | 6 |
| 7 #include "base/threading/thread.h" |
| 8 |
7 namespace media { | 9 namespace media { |
8 | 10 |
9 MessageLoopFactory::~MessageLoopFactory() {} | 11 MessageLoopFactory::MessageLoopFactory() {} |
| 12 |
| 13 MessageLoopFactory::~MessageLoopFactory() { |
| 14 for (ThreadMap::iterator iter = thread_map_.begin(); |
| 15 iter != thread_map_.end(); |
| 16 ++iter) { |
| 17 base::Thread* thread = (*iter).second; |
| 18 |
| 19 if (thread) { |
| 20 thread->Stop(); |
| 21 delete thread; |
| 22 } |
| 23 } |
| 24 thread_map_.clear(); |
| 25 } |
| 26 |
| 27 MessageLoop* MessageLoopFactory::GetMessageLoop(const std::string& name) { |
| 28 return GetThread(name)->message_loop(); |
| 29 } |
| 30 |
| 31 scoped_refptr<base::MessageLoopProxy> |
| 32 MessageLoopFactory::GetMessageLoopProxy(const std::string& name) { |
| 33 return GetThread(name)->message_loop_proxy(); |
| 34 } |
| 35 |
| 36 base::Thread* MessageLoopFactory::GetThread(const std::string& name) { |
| 37 DCHECK(!name.empty()); |
| 38 |
| 39 base::AutoLock auto_lock(lock_); |
| 40 ThreadMap::iterator it = thread_map_.find(name); |
| 41 if (it != thread_map_.end()) |
| 42 return (*it).second; |
| 43 |
| 44 base::Thread* thread = new base::Thread(name.c_str()); |
| 45 CHECK(thread->Start()) << "Failed to start thread: " << name; |
| 46 thread_map_[name] = thread; |
| 47 return thread; |
| 48 } |
10 | 49 |
11 } // namespace media | 50 } // namespace media |
OLD | NEW |