| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "media/base/message_loop_factory.h" | |
| 6 | |
| 7 #include "base/threading/thread.h" | |
| 8 | |
| 9 namespace media { | |
| 10 | |
| 11 MessageLoopFactory::MessageLoopFactory() {} | |
| 12 | |
| 13 MessageLoopFactory::~MessageLoopFactory() { | |
| 14 for (ThreadList::reverse_iterator it = threads_.rbegin(); | |
| 15 it != threads_.rend(); ++it) { | |
| 16 base::Thread* thread = it->second; | |
| 17 thread->Stop(); | |
| 18 delete thread; | |
| 19 } | |
| 20 threads_.clear(); | |
| 21 } | |
| 22 | |
| 23 scoped_refptr<base::MessageLoopProxy> MessageLoopFactory::GetMessageLoop( | |
| 24 Type type) { | |
| 25 return GetThread(type)->message_loop_proxy(); | |
| 26 } | |
| 27 | |
| 28 base::Thread* MessageLoopFactory::GetThread(Type type) { | |
| 29 base::AutoLock auto_lock(lock_); | |
| 30 for (ThreadList::iterator it = threads_.begin(); it != threads_.end(); ++it) { | |
| 31 if (it->first == type) | |
| 32 return it->second; | |
| 33 } | |
| 34 | |
| 35 const char* name = NULL; | |
| 36 switch (type) { | |
| 37 case kPipeline: | |
| 38 name = "MediaPipeline"; | |
| 39 break; | |
| 40 } | |
| 41 | |
| 42 base::Thread* thread = new base::Thread(name); | |
| 43 CHECK(thread->Start()) << "Failed to start thread: " << name; | |
| 44 threads_.push_back(std::make_pair(type, thread)); | |
| 45 return thread; | |
| 46 } | |
| 47 | |
| 48 } // namespace media | |
| OLD | NEW |