From 49ab556cfe14de363a74ce771931832304a1a038 Mon Sep 17 00:00:00 2001 From: "satish@chromium.org" Date: Sat, 11 Dec 2010 09:13:54 +0000 Subject: Make members of Singleton private and only visible to the singleton type. This enforces that the Singleton pattern can only be used within classes which want singleton-ness. As part of this CL I have also fixed up files which got missed in my previous CLs to use a GetInstance() method and use Singleton from the source file. There are a small number of places where I have also switched to LazyInstance as that was more appropriate for types used in a single source file. BUG=65298 TEST=all existing tests should continue to pass. Review URL: http://codereview.chromium.org/5682008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@68932 0039d316-1c4b-4281-b951-d872f2087c98 --- media/tools/player_wtl/mainfrm.h | 61 ++++++++++++++++++------------------ media/tools/player_wtl/movie.cc | 5 +++ media/tools/player_wtl/movie.h | 7 +++-- media/tools/player_wtl/player_wtl.cc | 2 +- media/tools/player_wtl/props.h | 2 +- media/tools/player_wtl/seek.h | 8 ++--- media/tools/player_wtl/view.h | 5 +-- 7 files changed, 50 insertions(+), 40 deletions(-) (limited to 'media/tools') diff --git a/media/tools/player_wtl/mainfrm.h b/media/tools/player_wtl/mainfrm.h index f92a97d..6c73957 100644 --- a/media/tools/player_wtl/mainfrm.h +++ b/media/tools/player_wtl/mainfrm.h @@ -61,10 +61,10 @@ class CMainFrame : public CFrameWindowImpl, virtual BOOL OnIdle() { BOOL bEnable = !m_view.bmp_.IsNull(); - BOOL bMovieOpen = media::Movie::get()->IsOpen() ? true : false; + BOOL bMovieOpen = media::Movie::GetInstance()->IsOpen() ? true : false; - float current_position = media::Movie::get()->GetPosition(); - float duration = media::Movie::get()->GetDuration(); + float current_position = media::Movie::GetInstance()->GetPosition(); + float duration = media::Movie::GetInstance()->GetDuration(); if (enable_exit && bEnable && duration > 0.0f && current_position >= duration) { OnFileExit(0, 0, 0); @@ -304,8 +304,8 @@ class CMainFrame : public CFrameWindowImpl, } void UpdateSpeedUICheck() { - if (media::Movie::get()) { - float play_rate = media::Movie::get()->GetPlayRate(); + if (media::Movie::GetInstance()) { + float play_rate = media::Movie::GetInstance()->GetPlayRate(); UISetCheck(ID_PLAY_HALFSPEED, (play_rate == 0.5f)); UISetCheck(ID_PLAY_NORMALSPEED, (play_rate == 1.0f)); UISetCheck(ID_PLAY_DOUBLESPEED, (play_rate == 2.0f)); @@ -422,10 +422,10 @@ class CMainFrame : public CFrameWindowImpl, TogglePrintPreview(); // If a movie is open, close it. - media::Movie::get()->Close(); + media::Movie::GetInstance()->Close(); if (IsMovie(file_name)) { - success = media::Movie::get()->Open(file_name, m_view.renderer_); + success = media::Movie::GetInstance()->Open(file_name, m_view.renderer_); } else { HBITMAP hbmp = NULL; hbmp = (HBITMAP)::LoadImage(NULL, file_name, IMAGE_BITMAP, 0, 0, @@ -590,7 +590,7 @@ class CMainFrame : public CFrameWindowImpl, if (m_bPrintPreview) TogglePrintPreview(); - media::Movie::get()->Close(); + media::Movie::GetInstance()->Close(); m_view.Reset(); UpdateTitleBar(NULL); m_szFilePath[0] = 0; @@ -643,44 +643,44 @@ class CMainFrame : public CFrameWindowImpl, } void OnPlayPlayPause(UINT /*uNotifyCode*/, int /*nID*/, CWindow /*wnd*/) { - bool paused = !media::Movie::get()->GetPause(); - media::Movie::get()->SetPause(paused); + bool paused = !media::Movie::GetInstance()->GetPause(); + media::Movie::GetInstance()->SetPause(paused); } void OnPlayStepForward(UINT /*uNotifyCode*/, int /*nID*/, CWindow /*wnd*/) { - float current_position = media::Movie::get()->GetPosition(); - media::Movie::get()->SetPosition(current_position + 10.0f); + float current_position = media::Movie::GetInstance()->GetPosition(); + media::Movie::GetInstance()->SetPosition(current_position + 10.0f); } void OnPlayStepBackward(UINT /*uNotifyCode*/, int /*nID*/, CWindow /*wnd*/) { - float current_position = media::Movie::get()->GetPosition(); - media::Movie::get()->SetPosition(current_position - 10.0f); + float current_position = media::Movie::GetInstance()->GetPosition(); + media::Movie::GetInstance()->SetPosition(current_position - 10.0f); } void OnPlayGotoStart(UINT /*uNotifyCode*/, int /*nID*/, CWindow /*wnd*/) { - media::Movie::get()->SetPosition(0.0); + media::Movie::GetInstance()->SetPosition(0.0); } void OnPlayGotoEnd(UINT /*uNotifyCode*/, int /*nID*/, CWindow /*wnd*/) { - float current_position = media::Movie::get()->GetDuration(); - media::Movie::get()->SetPosition(current_position - 30.0f); + float current_position = media::Movie::GetInstance()->GetDuration(); + media::Movie::GetInstance()->SetPosition(current_position - 30.0f); } void SetPlayRate(int play_speed) { if (play_speed == 0) { - media::Movie::get()->Play(0.5f); + media::Movie::GetInstance()->Play(0.5f); } else if (play_speed == 2) { - media::Movie::get()->Play(2.0f); + media::Movie::GetInstance()->Play(2.0f); } else if (play_speed == 3) { - media::Movie::get()->Play(3.0f); + media::Movie::GetInstance()->Play(3.0f); } else if (play_speed == 4) { - media::Movie::get()->Play(4.0f); + media::Movie::GetInstance()->Play(4.0f); } else if (play_speed == 5) { - media::Movie::get()->Play(8.0f); + media::Movie::GetInstance()->Play(8.0f); } else if (play_speed == 6) { - media::Movie::get()->Play(16.0f); + media::Movie::GetInstance()->Play(16.0f); } else { - media::Movie::get()->Play(1.0f); + media::Movie::GetInstance()->Play(1.0f); } } @@ -699,22 +699,23 @@ class CMainFrame : public CFrameWindowImpl, } void OnOptionsDraw(UINT /*uNotifyCode*/, int /*nID*/, CWindow /*wnd*/) { - bool enable_draw = !media::Movie::get()->GetDrawEnable(); - media::Movie::get()->SetDrawEnable(enable_draw); + bool enable_draw = !media::Movie::GetInstance()->GetDrawEnable(); + media::Movie::GetInstance()->SetDrawEnable(enable_draw); UISetCheck(ID_OPTIONS_DRAW, enable_draw); UpdateLayout(); } void OnOptionsAudio(UINT /*uNotifyCode*/, int /*nID*/, CWindow /*wnd*/) { - bool enable_audio = !media::Movie::get()->GetAudioEnable(); - media::Movie::get()->SetAudioEnable(enable_audio); + bool enable_audio = !media::Movie::GetInstance()->GetAudioEnable(); + media::Movie::GetInstance()->SetAudioEnable(enable_audio); UISetCheck(ID_OPTIONS_AUDIO, enable_audio); UpdateLayout(); } void OnOptionsDumpYUVFile(UINT /*uNotify*/, int /*nID*/, CWindow /*wnd*/) { - bool enable_dump_yuv_file = !media::Movie::get()->GetDumpYuvFileEnable(); - media::Movie::get()->SetDumpYuvFileEnable(enable_dump_yuv_file); + bool enable_dump_yuv_file = + !media::Movie::GetInstance()->GetDumpYuvFileEnable(); + media::Movie::GetInstance()->SetDumpYuvFileEnable(enable_dump_yuv_file); UISetCheck(ID_OPTIONS_DUMPYUVFILE, enable_dump_yuv_file); UpdateLayout(); } diff --git a/media/tools/player_wtl/movie.cc b/media/tools/player_wtl/movie.cc index 70ede51..7a06cb9 100644 --- a/media/tools/player_wtl/movie.cc +++ b/media/tools/player_wtl/movie.cc @@ -4,6 +4,7 @@ #include "media/tools/player_wtl/movie.h" +#include "base/singleton.h" #include "base/utf_string_conversions.h" #include "media/base/filter_collection.h" #include "media/base/pipeline_impl.h" @@ -39,6 +40,10 @@ Movie::Movie() Movie::~Movie() { } +Movie* Movie::GetInstance() { + return Singleton::get(); +} + bool Movie::IsOpen() { return pipeline_ != NULL; } diff --git a/media/tools/player_wtl/movie.h b/media/tools/player_wtl/movie.h index e505165..581a0db 100644 --- a/media/tools/player_wtl/movie.h +++ b/media/tools/player_wtl/movie.h @@ -11,17 +11,20 @@ #include "base/ref_counted.h" #include "base/scoped_ptr.h" -#include "base/singleton.h" #include "base/thread.h" +template struct DefaultSingletonTraits; class WtlVideoRenderer; namespace media { class PipelineImpl; -class Movie : public Singleton { +class Movie { public: + // Returns the singleton instance. + static Movie* GetInstance(); + // Open a movie. bool Open(const wchar_t* url, WtlVideoRenderer* video_renderer); diff --git a/media/tools/player_wtl/player_wtl.cc b/media/tools/player_wtl/player_wtl.cc index 8fe9f1b..b1dbabc 100644 --- a/media/tools/player_wtl/player_wtl.cc +++ b/media/tools/player_wtl/player_wtl.cc @@ -55,7 +55,7 @@ int Run(wchar_t* win_cmd_line, int cmd_show) { int result = the_loop.Run(); - media::Movie::get()->Close(); + media::Movie::GetInstance()->Close(); g_module.RemoveMessageLoop(); return result; diff --git a/media/tools/player_wtl/props.h b/media/tools/player_wtl/props.h index 65224e5..d2b7dbb 100644 --- a/media/tools/player_wtl/props.h +++ b/media/tools/player_wtl/props.h @@ -124,7 +124,7 @@ class CPageOne : public CPropertyPageImpl { SetDlgItemText(IDC_FILESIZE, szBuff); // TODO(fbarchard): We need a pipeline property for frame rate. - float duration = media::Movie::get()->GetDuration(); + float duration = media::Movie::GetInstance()->GetDuration(); float fps = 29.97f; wsprintf(szBuff, L"%i.%2i Seconds, %i Frames", static_cast(duration), diff --git a/media/tools/player_wtl/seek.h b/media/tools/player_wtl/seek.h index 84f3c95..d5cf464 100644 --- a/media/tools/player_wtl/seek.h +++ b/media/tools/player_wtl/seek.h @@ -34,12 +34,12 @@ class CSeek : public CSimpleDialog, BOOL& bHandled) { static float previous_position = -1.0f; - float position = media::Movie::get()->GetPosition(); + float position = media::Movie::GetInstance()->GetPosition(); if (static_cast(position * 10) != static_cast(previous_position * 10)) { previous_position = position; wchar_t szBuff[200]; - float duration = media::Movie::get()->GetDuration(); + float duration = media::Movie::GetInstance()->GetDuration(); float fps = 29.97f; wsprintf(szBuff, L"%i.%i / %i.%i, %i / %i", static_cast(position), @@ -58,8 +58,8 @@ class CSeek : public CSimpleDialog, virtual BOOL OnIdle() { wchar_t szBuff[200]; - float position = media::Movie::get()->GetPosition(); - float duration = media::Movie::get()->GetDuration(); + float position = media::Movie::GetInstance()->GetPosition(); + float duration = media::Movie::GetInstance()->GetDuration(); // TODO(fbarchard): Use frame rate property when it exists. float fps = 29.97f; wsprintf(szBuff, L"%i.%i / %i.%i, %i / %i", diff --git a/media/tools/player_wtl/view.h b/media/tools/player_wtl/view.h index dd1aaaf..cbb0a48 100644 --- a/media/tools/player_wtl/view.h +++ b/media/tools/player_wtl/view.h @@ -182,7 +182,8 @@ class WtlVideoWindow : public CScrollWindowImpl { } // Append each frame to end of file. - bool enable_dump_yuv_file = media::Movie::get()->GetDumpYuvFileEnable(); + bool enable_dump_yuv_file = + media::Movie::GetInstance()->GetDumpYuvFileEnable(); if (enable_dump_yuv_file) { DumpYUV(video_frame); } @@ -191,7 +192,7 @@ class WtlVideoWindow : public CScrollWindowImpl { double yuv_time_start = GetTime(); // Start timer. #endif - bool enable_draw = media::Movie::get()->GetDrawEnable(); + bool enable_draw = media::Movie::GetInstance()->GetDrawEnable(); if (enable_draw) { DCHECK(bm.bmBitsPixel == 32); DrawYUV(video_frame, -- cgit v1.1