Index: media/base/message_loop_factory.cc |
diff --git a/media/base/message_loop_factory.cc b/media/base/message_loop_factory.cc |
index e5b1d3386a3626db9b5fe6f3a3593ed510a63d6d..76ef2d94d274695be0d6e3170f8dc7bff773ab51 100644 |
--- a/media/base/message_loop_factory.cc |
+++ b/media/base/message_loop_factory.cc |
@@ -1,11 +1,56 @@ |
-// 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() { |
+ base::AutoLock auto_lock(lock_); |
Ami GONE FROM CHROMIUM
2012/03/05 23:20:15
Locking in the dtor is a pretty good indicator tha
scherkus (not reviewing)
2012/03/05 23:29:35
I don't think things are borked rather coded defen
acolwell GONE FROM CHROMIUM
2012/03/05 23:53:20
This was an attempt at defensive coding. Nothing s
|
+ |
+ 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) { |
+ base::Thread* thread = GetThread(name); |
+ return thread ? thread->message_loop() : NULL; |
+} |
+ |
+scoped_refptr<base::MessageLoopProxy> |
+MessageLoopFactory::GetMessageLoopProxy(const std::string& name) { |
+ base::Thread* thread = GetThread(name); |
+ return thread ? thread->message_loop_proxy() : NULL; |
+} |
+ |
+base::Thread* MessageLoopFactory::GetThread(const std::string& name) { |
+ if (name.empty()) |
+ return NULL; |
Ami GONE FROM CHROMIUM
2012/03/05 23:20:15
This isn't part of the doco'd interface of the cla
scherkus (not reviewing)
2012/03/05 23:29:35
"NULL is returned if |name| is an empty string" ??
acolwell GONE FROM CHROMIUM
2012/03/05 23:53:20
DCHECK_NE() seems good to me. I think this was one
|
+ |
+ base::AutoLock auto_lock(lock_); |
+ |
+ ThreadMap::iterator it = thread_map_.find(name); |
Ami GONE FROM CHROMIUM
2012/03/05 23:20:15
We don't actually make use of this functionality a
scherkus (not reviewing)
2012/03/05 23:29:35
yup but ideally going further by not creating addi
acolwell GONE FROM CHROMIUM
2012/03/05 23:53:20
So the original intent was to share threads across
|
+ 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 |