Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(204)

Unified Diff: media/base/message_loop_factory.cc

Issue 10855051: Use enum instead of string in MessageLoopFactory::GetMessageLoop* (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update player_wtl Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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;
}

Powered by Google App Engine
This is Rietveld 408576698