0

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
This commit is contained in:
scherkus@chromium.org
2012-03-06 01:33:50 +00:00
parent 6baff0b5ce
commit b8032290c2
13 changed files with 84 additions and 145 deletions

@ -86,7 +86,7 @@
#include "content/renderer/websharedworker_proxy.h"
#include "media/base/filter_collection.h"
#include "media/base/media_switches.h"
#include "media/base/message_loop_factory_impl.h"
#include "media/base/message_loop_factory.h"
#include "media/filters/gpu_video_decoder.h"
#include "net/base/escape.h"
#include "net/base/net_errors.h"
@ -2118,7 +2118,7 @@ WebMediaPlayer* RenderViewImpl::createMediaPlayer(
RenderViewObserver, observers_, WillCreateMediaPlayer(frame, client));
media::MessageLoopFactory* message_loop_factory =
new media::MessageLoopFactoryImpl();
new media::MessageLoopFactory();
media::FilterCollection* collection = new media::FilterCollection();
RenderMediaLog* render_media_log = new RenderMediaLog();

@ -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

@ -1,43 +1,62 @@
// 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.
#ifndef MEDIA_BASE_MESSAGE_LOOP_FACTORY_H_
#define MEDIA_BASE_MESSAGE_LOOP_FACTORY_H_
#include <map>
#include <string>
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop_proxy.h"
#include "base/synchronization/lock.h"
#include "media/base/media_export.h"
class MessageLoop;
namespace base {
class Thread;
}
namespace media {
// Factory object that manages named MessageLoops.
//
// TODO(scherkus): replace this with something simpler http://crbug.com/116873
class MEDIA_EXPORT MessageLoopFactory {
public:
MessageLoopFactory();
// Get the message loop associated with |name|. A new MessageLoop
// is created if the factory doesn't have one associated with |name|.
// NULL is returned if |name| is an empty string, or a new
// MessageLoop needs to be created and a failure occurs during the
// creation process.
virtual MessageLoop* GetMessageLoop(const std::string& name) = 0;
//
// |name| must not be an empty string.
MessageLoop* GetMessageLoop(const std::string& name);
// Get the message loop proxy associated with |name|. A new MessageLoopProxy
// is created if the factory doesn't have one associated with |name|.
// NULL is returned if |name| is an empty string, or a new
// MessageLoop needs to be created and a failure occurs during the
// creation process.
virtual scoped_refptr<base::MessageLoopProxy> GetMessageLoopProxy(
const std::string& name) = 0;
//
// |name| must not be an empty string.
scoped_refptr<base::MessageLoopProxy> GetMessageLoopProxy(
const std::string& name);
protected:
private:
// Only allow scoped_ptr<> to delete factory.
friend class scoped_ptr<MessageLoopFactory>;
virtual ~MessageLoopFactory();
~MessageLoopFactory();
// Returns the thread associated with |name| creating a new thread if needed.
base::Thread* GetThread(const std::string& name);
// Lock used to serialize access for the following data members.
base::Lock lock_;
typedef std::map<std::string, base::Thread*> ThreadMap;
ThreadMap thread_map_;
DISALLOW_COPY_AND_ASSIGN(MessageLoopFactory);
};
} // namespace media

@ -1,76 +0,0 @@
// Copyright (c) 2011 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_impl.h"
namespace media {
MessageLoopFactoryImpl::MessageLoopFactoryImpl() {}
MessageLoopFactoryImpl::~MessageLoopFactoryImpl() {
base::AutoLock auto_lock(lock_);
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();
}
// MessageLoopFactory methods.
MessageLoop* MessageLoopFactoryImpl::GetMessageLoop(const std::string& name) {
if (name.empty()) {
return NULL;
}
base::AutoLock auto_lock(lock_);
ThreadMap::iterator it = thread_map_.find(name);
if (it != thread_map_.end())
return (*it).second->message_loop();
scoped_ptr<base::Thread> thread(new base::Thread(name.c_str()));
if (thread->Start()) {
MessageLoop* message_loop = thread->message_loop();
thread_map_[name] = thread.release();
return message_loop;
}
LOG(ERROR) << "Failed to start '" << name << "' thread!";
return NULL;
}
scoped_refptr<base::MessageLoopProxy>
MessageLoopFactoryImpl::GetMessageLoopProxy(const std::string& name) {
if (name.empty()) {
return NULL;
}
base::AutoLock auto_lock(lock_);
ThreadMap::iterator it = thread_map_.find(name);
if (it != thread_map_.end())
return (*it).second->message_loop_proxy();
scoped_ptr<base::Thread> thread(new base::Thread(name.c_str()));
if (thread->Start()) {
scoped_refptr<base::MessageLoopProxy> message_loop_proxy =
thread->message_loop_proxy();
thread_map_[name] = thread.release();
return message_loop_proxy;
}
LOG(ERROR) << "Failed to start '" << name << "' thread!";
return NULL;
}
} // namespace media

@ -1,40 +0,0 @@
// Copyright (c) 2011 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.
#ifndef MEDIA_BASE_MESSAGE_LOOP_FACTORY_IMPL_H_
#define MEDIA_BASE_MESSAGE_LOOP_FACTORY_IMPL_H_
#include <map>
#include <string>
#include "base/threading/thread.h"
#include "media/base/message_loop_factory.h"
namespace media {
class MEDIA_EXPORT MessageLoopFactoryImpl : public MessageLoopFactory {
public:
MessageLoopFactoryImpl();
// MessageLoopFactory methods.
virtual MessageLoop* GetMessageLoop(const std::string& name) OVERRIDE;
virtual scoped_refptr<base::MessageLoopProxy> GetMessageLoopProxy(
const std::string& name) OVERRIDE;
protected:
virtual ~MessageLoopFactoryImpl();
private:
// Lock used to serialize access for the following data members.
base::Lock lock_;
typedef std::map<std::string, base::Thread*> ThreadMap;
ThreadMap thread_map_;
DISALLOW_COPY_AND_ASSIGN(MessageLoopFactoryImpl);
};
} // namespace media
#endif // MEDIA_BASE_MESSAGE_LOOP_FACTORY_IMPL_H_

@ -19,7 +19,7 @@ using ::testing::AnyNumber;
namespace media {
PipelineIntegrationTestBase::PipelineIntegrationTestBase()
: message_loop_factory_(new MessageLoopFactoryImpl()),
: message_loop_factory_(new MessageLoopFactory()),
pipeline_(new Pipeline(&message_loop_, new MediaLog())),
ended_(false),
pipeline_status_(PIPELINE_OK) {

@ -7,7 +7,7 @@
#include "base/message_loop.h"
#include "media/base/filter_collection.h"
#include "media/base/message_loop_factory_impl.h"
#include "media/base/message_loop_factory.h"
#include "media/base/pipeline.h"
#include "media/filters/chunk_demuxer.h"
#include "testing/gmock/include/gmock/gmock.h"

@ -144,8 +144,6 @@
'base/media_win.cc',
'base/message_loop_factory.cc',
'base/message_loop_factory.h',
'base/message_loop_factory_impl.cc',
'base/message_loop_factory_impl.h',
'base/pipeline.cc',
'base/pipeline.h',
'base/pipeline_status.h',

@ -10,7 +10,7 @@
#include "media/audio/audio_manager.h"
#include "media/base/filter_collection.h"
#include "media/base/media_log.h"
#include "media/base/message_loop_factory_impl.h"
#include "media/base/message_loop_factory.h"
#include "media/base/pipeline.h"
#include "media/filters/ffmpeg_audio_decoder.h"
#include "media/filters/ffmpeg_demuxer_factory.h"
@ -62,7 +62,7 @@ bool Movie::Open(const wchar_t* url, VideoRendererBase* video_renderer) {
Close();
}
message_loop_factory_.reset(new media::MessageLoopFactoryImpl());
message_loop_factory_.reset(new media::MessageLoopFactory());
MessageLoop* pipeline_loop =
message_loop_factory_->GetMessageLoop("PipelineThread");

@ -20,7 +20,7 @@
#include "media/base/media.h"
#include "media/base/media_log.h"
#include "media/base/media_switches.h"
#include "media/base/message_loop_factory_impl.h"
#include "media/base/message_loop_factory.h"
#include "media/base/pipeline.h"
#include "media/base/video_frame.h"
#include "media/filters/ffmpeg_audio_decoder.h"
@ -269,7 +269,7 @@ int main(int argc, char** argv) {
// Initialize the pipeline thread and the pipeline.
scoped_ptr<media::MessageLoopFactory> message_loop_factory(
new media::MessageLoopFactoryImpl());
new media::MessageLoopFactory());
scoped_ptr<base::Thread> thread;
scoped_refptr<media::Pipeline> pipeline;
MessageLoop message_loop;

@ -127,7 +127,6 @@ WebMediaPlayerImpl::WebMediaPlayerImpl(
MessageLoop* pipeline_message_loop =
message_loop_factory_->GetMessageLoop("PipelineThread");
CHECK(pipeline_message_loop) << "Failed to create a new thread";
pipeline_ = new media::Pipeline(pipeline_message_loop, media_log_);
// Let V8 know we started new thread if we did not did it yet.

@ -30,7 +30,7 @@
#include "grit/webkit_chromium_resources.h"
#include "media/base/filter_collection.h"
#include "media/base/media_log.h"
#include "media/base/message_loop_factory_impl.h"
#include "media/base/message_loop_factory.h"
#include "net/base/escape.h"
#include "net/base/net_errors.h"
#include "net/base/net_util.h"
@ -325,7 +325,7 @@ WebKit::WebMediaPlayer* CreateMediaPlayer(
return NULL;
#else
scoped_ptr<media::MessageLoopFactory> message_loop_factory(
new media::MessageLoopFactoryImpl());
new media::MessageLoopFactory());
scoped_ptr<media::FilterCollection> collection(
new media::FilterCollection());

@ -18,7 +18,7 @@
#include "base/utf_string_conversions.h"
#include "media/base/filter_collection.h"
#include "media/base/media_log.h"
#include "media/base/message_loop_factory_impl.h"
#include "media/base/message_loop_factory.h"
#include "net/base/net_errors.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebAccessibilityObject.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebConsoleMessage.h"
@ -651,7 +651,7 @@ WebPlugin* TestWebViewDelegate::createPlugin(WebFrame* frame,
WebMediaPlayer* TestWebViewDelegate::createMediaPlayer(
WebFrame* frame, WebMediaPlayerClient* client) {
scoped_ptr<media::MessageLoopFactory> message_loop_factory(
new media::MessageLoopFactoryImpl());
new media::MessageLoopFactory());
scoped_ptr<media::FilterCollection> collection(
new media::FilterCollection());