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 struct MessageLoopTypeNamePair { | |
12 MessageLoopFactory::Type type; | |
13 const char* name; | |
14 }; | |
15 | |
16 static const MessageLoopTypeNamePair kMessageLoopTypeToNameMapping[] = { | |
17 { MessageLoopFactory::kAudioDecoder, "AudioDecoderThread" }, | |
18 { MessageLoopFactory::kVideoDecoder, "VideoDecoderThread" }, | |
19 { MessageLoopFactory::kPipeline, "PipelineThread" } | |
20 }; | |
21 | |
11 MessageLoopFactory::MessageLoopFactory() {} | 22 MessageLoopFactory::MessageLoopFactory() {} |
12 | 23 |
13 MessageLoopFactory::~MessageLoopFactory() { | 24 MessageLoopFactory::~MessageLoopFactory() { |
14 for (ThreadList::reverse_iterator it = threads_.rbegin(); | 25 for (ThreadList::reverse_iterator it = threads_.rbegin(); |
15 it != threads_.rend(); ++it) { | 26 it != threads_.rend(); ++it) { |
16 base::Thread* thread = it->second; | 27 base::Thread* thread = it->second; |
17 thread->Stop(); | 28 thread->Stop(); |
18 delete thread; | 29 delete thread; |
19 } | 30 } |
20 threads_.clear(); | 31 threads_.clear(); |
21 } | 32 } |
22 | 33 |
23 MessageLoop* MessageLoopFactory::GetMessageLoop(const std::string& name) { | 34 scoped_refptr<base::MessageLoopProxy> MessageLoopFactory::GetMessageLoop( |
24 return GetThread(name)->message_loop(); | 35 Type type) { |
36 return GetThread(type)->message_loop_proxy(); | |
25 } | 37 } |
26 | 38 |
27 scoped_refptr<base::MessageLoopProxy> | 39 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_); | 40 base::AutoLock auto_lock(lock_); |
36 for (ThreadList::iterator it = threads_.begin(); it != threads_.end(); ++it) { | 41 for (ThreadList::iterator it = threads_.begin(); it != threads_.end(); ++it) { |
37 if (it->first == name) | 42 if (it->first == type) |
38 return it->second; | 43 return it->second; |
39 } | 44 } |
40 | 45 |
46 std::string name; | |
47 for (size_t i = 0; i < arraysize(kMessageLoopTypeToNameMapping); ++i) { | |
48 if (kMessageLoopTypeToNameMapping[i].type == type) | |
49 name = kMessageLoopTypeToNameMapping[i].name; | |
50 } | |
51 DCHECK(!name.empty()); | |
52 | |
41 base::Thread* thread = new base::Thread(name.c_str()); | 53 base::Thread* thread = new base::Thread(name.c_str()); |
Ami GONE FROM CHROMIUM
2012/08/10 04:38:06
I think you're working too hard on this :)
l.16-21
scherkus (not reviewing)
2012/08/10 17:00:09
+1
xhwang
2012/08/10 19:33:33
Done.
| |
42 CHECK(thread->Start()) << "Failed to start thread: " << name; | 54 CHECK(thread->Start()) << "Failed to start thread: " << name; |
43 threads_.push_back(std::make_pair(name, thread)); | 55 threads_.push_back(std::make_pair(type, thread)); |
44 return thread; | 56 return thread; |
45 } | 57 } |
46 | 58 |
47 } // namespace media | 59 } // namespace media |
OLD | NEW |