summaryrefslogtreecommitdiffstats
path: root/media/base/message_loop_factory.cc
diff options
context:
space:
mode:
authorscherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-06 01:33:50 +0000
committerscherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-06 01:33:50 +0000
commitb8032290c28370be60077d7e509e41951b04715c (patch)
tree13cb575caf8539a97c75de1eb353ce820fc58859 /media/base/message_loop_factory.cc
parent6baff0b5ce43b24522f0af48e664d925088c7f3d (diff)
downloadchromium_src-b8032290c28370be60077d7e509e41951b04715c.zip
chromium_src-b8032290c28370be60077d7e509e41951b04715c.tar.gz
chromium_src-b8032290c28370be60077d7e509e41951b04715c.tar.bz2
Fold media::MessageLoopFactoryImpl into media::MessageLoopFactory.
We haven't had a second implementation of the interface since MessageLoopFactory was added in r71548. Review URL: https://chromiumcodereview.appspot.com/9597016 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@125064 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/base/message_loop_factory.cc')
-rw-r--r--media/base/message_loop_factory.cc43
1 files changed, 41 insertions, 2 deletions
diff --git a/media/base/message_loop_factory.cc b/media/base/message_loop_factory.cc
index e5b1d33..a62abc5 100644
--- a/media/base/message_loop_factory.cc
+++ b/media/base/message_loop_factory.cc
@@ -1,11 +1,50 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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.h"
+#include "base/threading/thread.h"
+
namespace media {
-MessageLoopFactory::~MessageLoopFactory() {}
+MessageLoopFactory::MessageLoopFactory() {}
+
+MessageLoopFactory::~MessageLoopFactory() {
+ 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();
+}
+
+MessageLoop* MessageLoopFactory::GetMessageLoop(const std::string& name) {
+ return GetThread(name)->message_loop();
+}
+
+scoped_refptr<base::MessageLoopProxy>
+MessageLoopFactory::GetMessageLoopProxy(const std::string& name) {
+ return GetThread(name)->message_loop_proxy();
+}
+
+base::Thread* MessageLoopFactory::GetThread(const std::string& name) {
+ DCHECK(!name.empty());
+
+ base::AutoLock auto_lock(lock_);
+ ThreadMap::iterator it = thread_map_.find(name);
+ if (it != thread_map_.end())
+ return (*it).second;
+
+ base::Thread* thread = new base::Thread(name.c_str());
+ CHECK(thread->Start()) << "Failed to start thread: " << name;
+ thread_map_[name] = thread;
+ return thread;
+}
} // namespace media