diff options
author | satish@chromium.org <satish@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-11 09:13:54 +0000 |
---|---|---|
committer | satish@chromium.org <satish@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-11 09:13:54 +0000 |
commit | 49ab556cfe14de363a74ce771931832304a1a038 (patch) | |
tree | 7703457c54a035f2eebe38babecaba12b6bfb975 /chrome/browser | |
parent | 0310169705d607a78bc288e74038fe104b4474fd (diff) | |
download | chromium_src-49ab556cfe14de363a74ce771931832304a1a038.zip chromium_src-49ab556cfe14de363a74ce771931832304a1a038.tar.gz chromium_src-49ab556cfe14de363a74ce771931832304a1a038.tar.bz2 |
Make members of Singleton<T> private and only visible to the singleton type. This enforces that the Singleton<T> 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<T> 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
Diffstat (limited to 'chrome/browser')
9 files changed, 36 insertions, 20 deletions
diff --git a/chrome/browser/chromeos/browser_main_chromeos.cc b/chrome/browser/chromeos/browser_main_chromeos.cc index df4653a..776a82b 100644 --- a/chrome/browser/chromeos/browser_main_chromeos.cc +++ b/chrome/browser/chromeos/browser_main_chromeos.cc @@ -4,8 +4,8 @@ #include "chrome/browser/chromeos/browser_main_chromeos.h" +#include "base/lazy_instance.h" #include "base/message_loop.h" -#include "base/singleton.h" #include <gtk/gtk.h> @@ -38,12 +38,13 @@ class MessageLoopObserver : public MessageLoopForUI::Observer { } }; -void BrowserMainPartsChromeos::PostMainMessageLoopStart() { - static Singleton<MessageLoopObserver> observer; +static base::LazyInstance<MessageLoopObserver> g_message_loop_observer( + base::LINKER_INITIALIZED); +void BrowserMainPartsChromeos::PostMainMessageLoopStart() { BrowserMainPartsPosix::PostMainMessageLoopStart(); MessageLoopForUI* message_loop = MessageLoopForUI::current(); - message_loop->AddObserver(observer.get()); + message_loop->AddObserver(g_message_loop_observer.Pointer()); } // static diff --git a/chrome/browser/chromeos/login/screen_locker.cc b/chrome/browser/chromeos/login/screen_locker.cc index f59307b..2167650 100644 --- a/chrome/browser/chromeos/login/screen_locker.cc +++ b/chrome/browser/chromeos/login/screen_locker.cc @@ -16,9 +16,9 @@ #include "app/resource_bundle.h" #include "app/x11_util.h" #include "base/command_line.h" +#include "base/lazy_instance.h" #include "base/metrics/histogram.h" #include "base/message_loop.h" -#include "base/singleton.h" #include "base/string_util.h" #include "base/timer.h" #include "base/utf_string_conversions.h" @@ -194,6 +194,9 @@ class ScreenLockObserver : public chromeos::ScreenLockLibrary::Observer, DISALLOW_COPY_AND_ASSIGN(ScreenLockObserver); }; +static base::LazyInstance<ScreenLockObserver> g_screen_lock_observer( + base::LINKER_INITIALIZED); + // A ScreenLock window that covers entire screen to keep the keyboard // focus/events inside the grab widget. class LockWindow : public views::WidgetGtk { @@ -901,7 +904,7 @@ void ScreenLocker::UnlockScreenFailed() { // static void ScreenLocker::InitClass() { - Singleton<ScreenLockObserver>::get(); + g_screen_lock_observer.Get(); } //////////////////////////////////////////////////////////////////////////////// diff --git a/chrome/browser/chromeos/login/signed_settings_helper.cc b/chrome/browser/chromeos/login/signed_settings_helper.cc index ad86e83..6a1a735 100644 --- a/chrome/browser/chromeos/login/signed_settings_helper.cc +++ b/chrome/browser/chromeos/login/signed_settings_helper.cc @@ -7,9 +7,9 @@ #include <string> #include <vector> +#include "base/lazy_instance.h" #include "base/logging.h" #include "base/ref_counted.h" -#include "base/singleton.h" #include "chrome/browser/browser_thread.h" #include "chrome/browser/chromeos/login/signed_settings.h" @@ -262,10 +262,13 @@ class SignedSettingsHelperImpl : public SignedSettingsHelper, std::vector<OpContext*> pending_contexts_; - friend struct DefaultSingletonTraits<SignedSettingsHelperImpl>; + friend struct base::DefaultLazyInstanceTraits<SignedSettingsHelperImpl>; DISALLOW_COPY_AND_ASSIGN(SignedSettingsHelperImpl); }; +static base::LazyInstance<SignedSettingsHelperImpl> + g_signed_settings_helper_impl(base::LINKER_INITIALIZED); + SignedSettingsHelperImpl::SignedSettingsHelperImpl() { } @@ -371,7 +374,7 @@ void SignedSettingsHelperImpl::OnOpCompleted(OpContext* context) { } SignedSettingsHelper* SignedSettingsHelper::Get() { - return Singleton<SignedSettingsHelperImpl>::get(); + return g_signed_settings_helper_impl.Pointer(); } } // namespace chromeos diff --git a/chrome/browser/chromeos/offline/offline_load_service.cc b/chrome/browser/chromeos/offline/offline_load_service.cc index 08f2362..ace85d8 100644 --- a/chrome/browser/chromeos/offline/offline_load_service.cc +++ b/chrome/browser/chromeos/offline/offline_load_service.cc @@ -4,8 +4,8 @@ #include "chrome/browser/chromeos/offline/offline_load_service.h" +#include "base/lazy_instance.h" #include "base/ref_counted.h" -#include "base/singleton.h" #include "chrome/browser/browser_thread.h" #include "chrome/browser/tab_contents/navigation_controller.h" #include "chrome/browser/tab_contents/tab_contents.h" @@ -24,7 +24,7 @@ class OfflineLoadServiceSingleton { } private: - friend struct DefaultSingletonTraits<OfflineLoadServiceSingleton>; + friend struct base::DefaultLazyInstanceTraits<OfflineLoadServiceSingleton>; OfflineLoadServiceSingleton() : offline_load_service_(new chromeos::OfflineLoadService()) {} virtual ~OfflineLoadServiceSingleton() {} @@ -34,9 +34,12 @@ class OfflineLoadServiceSingleton { DISALLOW_COPY_AND_ASSIGN(OfflineLoadServiceSingleton); }; +static base::LazyInstance<OfflineLoadServiceSingleton> + g_offline_load_service_singleton(base::LINKER_INITIALIZED); + // static OfflineLoadService* OfflineLoadService::Get() { - return Singleton<OfflineLoadServiceSingleton>::get()->offline_load_service(); + return g_offline_load_service_singleton.Get().offline_load_service(); } void OfflineLoadService::Observe(NotificationType type, diff --git a/chrome/browser/enumerate_modules_model_win.cc b/chrome/browser/enumerate_modules_model_win.cc index b521b6c..cff39c6 100644 --- a/chrome/browser/enumerate_modules_model_win.cc +++ b/chrome/browser/enumerate_modules_model_win.cc @@ -672,6 +672,11 @@ string16 ModuleEnumerator::GetSubjectNameFromDigitalSignature( // ---------------------------------------------------------------------------- +// static +EnumerateModulesModel* EnumerateModulesModel::GetSingleton() { + return Singleton<EnumerateModulesModel>::get(); +} + void EnumerateModulesModel::ScanNow() { if (scanning_) return; // A scan is already in progress. diff --git a/chrome/browser/enumerate_modules_model_win.h b/chrome/browser/enumerate_modules_model_win.h index 9000a6c..15492a5 100644 --- a/chrome/browser/enumerate_modules_model_win.h +++ b/chrome/browser/enumerate_modules_model_win.h @@ -218,9 +218,7 @@ class ModuleEnumerator : public base::RefCountedThreadSafe<ModuleEnumerator> { // notification. class EnumerateModulesModel { public: - static EnumerateModulesModel* GetSingleton() { - return Singleton<EnumerateModulesModel>::get(); - } + static EnumerateModulesModel* GetSingleton(); // Returns the number of suspected bad modules found in the last scan. // Returns 0 if no scan has taken place yet. diff --git a/chrome/browser/gtk/browser_toolbar_gtk.cc b/chrome/browser/gtk/browser_toolbar_gtk.cc index ad10e51..d3dffff 100644 --- a/chrome/browser/gtk/browser_toolbar_gtk.cc +++ b/chrome/browser/gtk/browser_toolbar_gtk.cc @@ -626,7 +626,7 @@ bool BrowserToolbarGtk::ShouldOnlyShowLocation() const { gboolean BrowserToolbarGtk::OnWrenchMenuButtonExpose(GtkWidget* sender, GdkEventExpose* expose) { - if (!Singleton<UpgradeDetector>::get()->notify_upgrade()) + if (!UpgradeDetector::GetInstance()->notify_upgrade()) return FALSE; const SkBitmap& badge = diff --git a/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc b/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc index 7ec0303..2bc0a49 100644 --- a/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc +++ b/chrome/browser/safe_browsing/safe_browsing_blocking_page.cc @@ -76,6 +76,9 @@ static const char* const kTakeMeBackCommand = "takeMeBack"; // static SafeBrowsingBlockingPageFactory* SafeBrowsingBlockingPage::factory_ = NULL; +static base::LazyInstance<SafeBrowsingBlockingPage::UnsafeResourceMap> + g_unsafe_resource_map(base::LINKER_INITIALIZED); + // The default SafeBrowsingBlockingPageFactory. Global, made a singleton so we // don't leak it. class SafeBrowsingBlockingPageFactoryImpl @@ -559,7 +562,7 @@ void SafeBrowsingBlockingPage::NotifySafeBrowsingService( // static SafeBrowsingBlockingPage::UnsafeResourceMap* SafeBrowsingBlockingPage::GetUnsafeResourcesMap() { - return Singleton<UnsafeResourceMap>::get(); + return g_unsafe_resource_map.Pointer(); } // static diff --git a/chrome/browser/safe_browsing/safe_browsing_blocking_page.h b/chrome/browser/safe_browsing/safe_browsing_blocking_page.h index 53b21a0..cfe2358 100644 --- a/chrome/browser/safe_browsing/safe_browsing_blocking_page.h +++ b/chrome/browser/safe_browsing/safe_browsing_blocking_page.h @@ -44,6 +44,9 @@ class TabContents; class SafeBrowsingBlockingPage : public InterstitialPage { public: + typedef std::vector<SafeBrowsingService::UnsafeResource> UnsafeResourceList; + typedef std::map<TabContents*, UnsafeResourceList> UnsafeResourceMap; + virtual ~SafeBrowsingBlockingPage(); // Shows a blocking page warning the user about phishing/malware for a @@ -66,8 +69,6 @@ class SafeBrowsingBlockingPage : public InterstitialPage { virtual void Proceed(); virtual void DontProceed(); - typedef std::vector<SafeBrowsingService::UnsafeResource> UnsafeResourceList; - protected: friend class SafeBrowsingBlockingPageTest; @@ -118,7 +119,6 @@ class SafeBrowsingBlockingPage : public InterstitialPage { // A list of SafeBrowsingService::UnsafeResource for a tab that the user // should be warned about. They are queued when displaying more than one // interstitial at a time. - typedef std::map<TabContents*, UnsafeResourceList> UnsafeResourceMap; static UnsafeResourceMap* GetUnsafeResourcesMap(); // Notifies the SafeBrowsingService on the IO thread whether to proceed or not |