OLD | NEW |
1 // Copyright (c) 2012 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" | 7 #include "base/threading/thread.h" |
8 | 8 |
9 namespace media { | 9 namespace media { |
10 | 10 |
11 MessageLoopFactory::MessageLoopFactory() {} | 11 MessageLoopFactory::MessageLoopFactory() {} |
12 | 12 |
13 MessageLoopFactory::~MessageLoopFactory() { | 13 MessageLoopFactory::~MessageLoopFactory() { |
14 for (ThreadList::reverse_iterator it = threads_.rbegin(); | 14 for (ThreadList::reverse_iterator it = threads_.rbegin(); |
15 it != threads_.rend(); ++it) { | 15 it != threads_.rend(); ++it) { |
16 base::Thread* thread = it->second; | 16 base::Thread* thread = it->second; |
17 thread->Stop(); | 17 thread->Stop(); |
18 delete thread; | 18 delete thread; |
19 } | 19 } |
20 threads_.clear(); | 20 threads_.clear(); |
21 } | 21 } |
22 | 22 |
23 MessageLoop* MessageLoopFactory::GetMessageLoop(const std::string& name) { | 23 scoped_refptr<base::MessageLoopProxy> MessageLoopFactory::GetMessageLoop( |
24 return GetThread(name)->message_loop(); | 24 Type type) { |
| 25 return GetThread(type)->message_loop_proxy(); |
25 } | 26 } |
26 | 27 |
27 scoped_refptr<base::MessageLoopProxy> | 28 base::Thread* MessageLoopFactory::GetThread(Type type) { |
28 MessageLoopFactory::GetMessageLoopProxy(const std::string& name) { | |
29 return GetThread(name)->message_loop_proxy(); | |
30 } | |
31 | |
32 base::Thread* MessageLoopFactory::GetThread(const std::string& name) { | |
33 DCHECK(!name.empty()); | |
34 | |
35 base::AutoLock auto_lock(lock_); | 29 base::AutoLock auto_lock(lock_); |
36 for (ThreadList::iterator it = threads_.begin(); it != threads_.end(); ++it) { | 30 for (ThreadList::iterator it = threads_.begin(); it != threads_.end(); ++it) { |
37 if (it->first == name) | 31 if (it->first == type) |
38 return it->second; | 32 return it->second; |
39 } | 33 } |
40 | 34 |
41 base::Thread* thread = new base::Thread(name.c_str()); | 35 const char* name = NULL; |
| 36 switch (type) { |
| 37 case kAudioDecoder: |
| 38 name = "AudioDecoderThread"; |
| 39 break; |
| 40 case kVideoDecoder: |
| 41 name = "VideoDecoderThread"; |
| 42 break; |
| 43 case kPipeline: |
| 44 name = "PipelineThread"; |
| 45 break; |
| 46 } |
| 47 |
| 48 base::Thread* thread = new base::Thread(name); |
42 CHECK(thread->Start()) << "Failed to start thread: " << name; | 49 CHECK(thread->Start()) << "Failed to start thread: " << name; |
43 threads_.push_back(std::make_pair(name, thread)); | 50 threads_.push_back(std::make_pair(type, thread)); |
44 return thread; | 51 return thread; |
45 } | 52 } |
46 | 53 |
47 } // namespace media | 54 } // namespace media |
OLD | NEW |