summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authorsatish@chromium.org <satish@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-08 10:43:08 +0000
committersatish@chromium.org <satish@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-08 10:43:08 +0000
commit687b96058845cdaa59f9d81c468f81222e60bdfd (patch)
tree9c97670a35e5f6abe40f3c4bf50ee7b5a257a0e3 /media
parentd22618c155cd40c5740755a5f0bcaab59f13f9a7 (diff)
downloadchromium_src-687b96058845cdaa59f9d81c468f81222e60bdfd.zip
chromium_src-687b96058845cdaa59f9d81c468f81222e60bdfd.tar.gz
chromium_src-687b96058845cdaa59f9d81c468f81222e60bdfd.tar.bz2
Add a new GetInstance() method for singleton classes, take 2.
This is a small step towards making all singleton classes use the Singleton<T> pattern within their code and not expect the callers to know about it. This CL includes all files except those under chrome/browser, chrome/net, chrome/service and third_party/WebKit (these will be done in future CLs). Suggested files to focus for reviewers: - joi@ for files under src/ceee - tommi@ for files under src/chrome_frame - maruel@ for the rest of the files. BUG=65298 TEST=all existing tests should continue to pass. Review URL: http://codereview.chromium.org/5581008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@68577 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media')
-rw-r--r--media/filters/ffmpeg_demuxer.cc4
-rw-r--r--media/filters/ffmpeg_glue.cc7
-rw-r--r--media/filters/ffmpeg_glue.h5
-rw-r--r--media/filters/ffmpeg_glue_unittest.cc12
4 files changed, 18 insertions, 10 deletions
diff --git a/media/filters/ffmpeg_demuxer.cc b/media/filters/ffmpeg_demuxer.cc
index 1ab307e..3024050 100644
--- a/media/filters/ffmpeg_demuxer.cc
+++ b/media/filters/ffmpeg_demuxer.cc
@@ -391,7 +391,7 @@ void FFmpegDemuxer::InitializeTask(DataSource* data_source,
data_source_ = data_source;
// Add ourself to Protocol list and get our unique key.
- std::string key = FFmpegGlue::get()->AddProtocol(this);
+ std::string key = FFmpegGlue::GetInstance()->AddProtocol(this);
// Open FFmpeg AVFormatContext.
DCHECK(!format_context_);
@@ -399,7 +399,7 @@ void FFmpegDemuxer::InitializeTask(DataSource* data_source,
int result = av_open_input_file(&context, key.c_str(), NULL, 0, NULL);
// Remove ourself from protocol list.
- FFmpegGlue::get()->RemoveProtocol(this);
+ FFmpegGlue::GetInstance()->RemoveProtocol(this);
if (result < 0) {
host()->SetError(DEMUXER_ERROR_COULD_NOT_OPEN);
diff --git a/media/filters/ffmpeg_glue.cc b/media/filters/ffmpeg_glue.cc
index 6f637c3..663fff7 100644
--- a/media/filters/ffmpeg_glue.cc
+++ b/media/filters/ffmpeg_glue.cc
@@ -16,7 +16,7 @@ media::FFmpegURLProtocol* ToProtocol(void* data) {
// FFmpeg protocol interface.
int OpenContext(URLContext* h, const char* filename, int flags) {
media::FFmpegURLProtocol* protocol;
- media::FFmpegGlue::get()->GetProtocol(filename, &protocol);
+ media::FFmpegGlue::GetInstance()->GetProtocol(filename, &protocol);
if (!protocol)
return AVERROR_IO;
@@ -145,6 +145,11 @@ FFmpegGlue::~FFmpegGlue() {
av_lockmgr_register(NULL);
}
+// static
+FFmpegGlue* FFmpegGlue::GetInstance() {
+ return Singleton<FFmpegGlue>::get();
+}
+
std::string FFmpegGlue::AddProtocol(FFmpegURLProtocol* protocol) {
AutoLock auto_lock(lock_);
std::string key = GetProtocolKey(protocol);
diff --git a/media/filters/ffmpeg_glue.h b/media/filters/ffmpeg_glue.h
index 1ae4ded..4f991d1 100644
--- a/media/filters/ffmpeg_glue.h
+++ b/media/filters/ffmpeg_glue.h
@@ -64,8 +64,11 @@ class FFmpegURLProtocol {
DISALLOW_COPY_AND_ASSIGN(FFmpegURLProtocol);
};
-class FFmpegGlue : public Singleton<FFmpegGlue> {
+class FFmpegGlue {
public:
+ // Returns the singleton instance.
+ static FFmpegGlue* GetInstance();
+
// Adds a FFmpegProtocol to the FFmpeg glue layer and returns a unique string
// that can be passed to FFmpeg to identify the data source.
std::string AddProtocol(FFmpegURLProtocol* protocol);
diff --git a/media/filters/ffmpeg_glue_unittest.cc b/media/filters/ffmpeg_glue_unittest.cc
index d217f9c..f823669 100644
--- a/media/filters/ffmpeg_glue_unittest.cc
+++ b/media/filters/ffmpeg_glue_unittest.cc
@@ -43,7 +43,7 @@ class FFmpegGlueTest : public ::testing::Test {
MockFFmpeg::set(&mock_ffmpeg_);
// Singleton should initialize FFmpeg.
- CHECK(FFmpegGlue::get());
+ CHECK(FFmpegGlue::GetInstance());
// Assign our static copy of URLProtocol for the rest of the tests.
protocol_ = MockFFmpeg::protocol();
@@ -61,10 +61,10 @@ class FFmpegGlueTest : public ::testing::Test {
EXPECT_CALL(*protocol, IsStreaming()).WillOnce(Return(true));
// Add the protocol to the glue layer and open a context.
- std::string key = FFmpegGlue::get()->AddProtocol(protocol);
+ std::string key = FFmpegGlue::GetInstance()->AddProtocol(protocol);
memset(context, 0, sizeof(*context));
EXPECT_EQ(0, protocol_->url_open(context, key.c_str(), 0));
- FFmpegGlue::get()->RemoveProtocol(protocol);
+ FFmpegGlue::GetInstance()->RemoveProtocol(protocol);
}
protected:
@@ -90,7 +90,7 @@ TEST_F(FFmpegGlueTest, InitializeFFmpeg) {
TEST_F(FFmpegGlueTest, AddRemoveGetProtocol) {
// Prepare testing data.
- FFmpegGlue* glue = FFmpegGlue::get();
+ FFmpegGlue* glue = FFmpegGlue::GetInstance();
// Create our protocols and add them to the glue layer.
scoped_ptr<StrictMock<Destroyable<MockProtocol> > > protocol_a(
@@ -144,7 +144,7 @@ TEST_F(FFmpegGlueTest, AddRemoveGetProtocol) {
TEST_F(FFmpegGlueTest, OpenClose) {
// Prepare testing data.
- FFmpegGlue* glue = FFmpegGlue::get();
+ FFmpegGlue* glue = FFmpegGlue::GetInstance();
// Create our protocol and add them to the glue layer.
scoped_ptr<StrictMock<Destroyable<MockProtocol> > > protocol(
@@ -311,7 +311,7 @@ TEST_F(FFmpegGlueTest, Destroy) {
// Create our protocol and add them to the glue layer.
scoped_ptr<StrictMock<Destroyable<MockProtocol> > > protocol(
new StrictMock<Destroyable<MockProtocol> >());
- std::string key = FFmpegGlue::get()->AddProtocol(protocol.get());
+ std::string key = FFmpegGlue::GetInstance()->AddProtocol(protocol.get());
// We should expect the protocol to get destroyed when the unit test
// exits.