Improve performance of registering font preferences
[chromium-blink-merge.git] / media / base / message_loop_factory.cc
blobda6cac66cc02d368f27d4cf031ce81286a58374e
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.
5 #include "media/base/message_loop_factory.h"
7 #include "base/threading/thread.h"
9 namespace media {
11 MessageLoopFactory::MessageLoopFactory() {}
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;
20 threads_.clear();
23 scoped_refptr<base::MessageLoopProxy> MessageLoopFactory::GetMessageLoop(
24 Type type) {
25 return GetThread(type)->message_loop_proxy();
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;
35 const char* name = NULL;
36 switch (type) {
37 case kDecoder:
38 name = "MediaDecoder";
39 break;
40 case kPipeline:
41 name = "MediaPipeline";
42 break;
45 base::Thread* thread = new base::Thread(name);
46 CHECK(thread->Start()) << "Failed to start thread: " << name;
47 threads_.push_back(std::make_pair(type, thread));
48 return thread;
51 } // namespace media