diff options
author | satish@chromium.org <satish@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-14 07:48:49 +0000 |
---|---|---|
committer | satish@chromium.org <satish@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-14 07:48:49 +0000 |
commit | 625332e06437018bf696dce93a4b2bd2c5e0b118 (patch) | |
tree | 56e128ddf94a81b6de1f29a9eabe59f0d79346c9 /chrome | |
parent | dc7cdcb970254f223262a66c812f240a8269ae87 (diff) | |
download | chromium_src-625332e06437018bf696dce93a4b2bd2c5e0b118.zip chromium_src-625332e06437018bf696dce93a4b2bd2c5e0b118.tar.gz chromium_src-625332e06437018bf696dce93a4b2bd2c5e0b118.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@69107 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/chromeos/browser_main_chromeos.cc | 9 | ||||
-rw-r--r-- | chrome/browser/chromeos/cros/cros_library.cc | 6 | ||||
-rw-r--r-- | chrome/browser/chromeos/cros/cros_library.h | 8 | ||||
-rw-r--r-- | chrome/browser/chromeos/login/screen_locker.cc | 7 | ||||
-rw-r--r-- | chrome/browser/chromeos/login/signed_settings_helper.cc | 9 | ||||
-rw-r--r-- | chrome/browser/chromeos/offline/offline_load_service.cc | 9 | ||||
-rw-r--r-- | chrome/browser/gtk/browser_toolbar_gtk.cc | 2 | ||||
-rw-r--r-- | chrome/browser/safe_browsing/safe_browsing_blocking_page.cc | 5 | ||||
-rw-r--r-- | chrome/browser/safe_browsing/safe_browsing_blocking_page.h | 6 | ||||
-rw-r--r-- | chrome/common/sqlite_utils.cc | 7 | ||||
-rw-r--r-- | chrome/common/time_format.cc | 12 | ||||
-rw-r--r-- | chrome/installer/util/master_preferences.cc | 7 | ||||
-rw-r--r-- | chrome/plugin/webplugin_proxy.cc | 12 | ||||
-rw-r--r-- | chrome/renderer/extensions/bindings_utils.cc | 10 | ||||
-rw-r--r-- | chrome/renderer/extensions/renderer_extension_bindings.cc | 13 | ||||
-rw-r--r-- | chrome/renderer/ggl/ggl.cc | 8 | ||||
-rw-r--r-- | chrome/renderer/render_view.cc | 13 |
17 files changed, 90 insertions, 53 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/cros/cros_library.cc b/chrome/browser/chromeos/cros/cros_library.cc index a294329..8efd3e1 100644 --- a/chrome/browser/chromeos/cros/cros_library.cc +++ b/chrome/browser/chromeos/cros/cros_library.cc @@ -4,6 +4,7 @@ #include "chrome/browser/chromeos/cros/cros_library.h" +#include "base/lazy_instance.h" #include "chrome/browser/chromeos/cros/brightness_library.h" #include "chrome/browser/chromeos/cros/burn_library.h" #include "chrome/browser/chromeos/cros/cros_library_loader.h" @@ -23,6 +24,9 @@ namespace chromeos { +static base::LazyInstance<CrosLibrary> g_cros_library( + base::LINKER_INITIALIZED); + CrosLibrary::CrosLibrary() : library_loader_(NULL), own_library_loader_(false), use_stub_impl_(false), @@ -38,7 +42,7 @@ CrosLibrary::~CrosLibrary() { // static CrosLibrary* CrosLibrary::Get() { - return Singleton<CrosLibrary>::get(); + return g_cros_library.Pointer(); } BrightnessLibrary* CrosLibrary::GetBrightnessLibrary() { diff --git a/chrome/browser/chromeos/cros/cros_library.h b/chrome/browser/chromeos/cros/cros_library.h index ae16fa7..deb2dfc6 100644 --- a/chrome/browser/chromeos/cros/cros_library.h +++ b/chrome/browser/chromeos/cros/cros_library.h @@ -10,8 +10,12 @@ #include "base/basictypes.h" #include "base/command_line.h" #include "base/scoped_ptr.h" -#include "base/singleton.h" #include "chrome/common/chrome_switches.h" + +namespace base { +template <typename T> struct DefaultLazyInstanceTraits; +} + namespace chromeos { class BrightnessLibrary; @@ -149,7 +153,7 @@ class CrosLibrary { } private: - friend struct DefaultSingletonTraits<chromeos::CrosLibrary>; + friend struct base::DefaultLazyInstanceTraits<chromeos::CrosLibrary>; friend class CrosLibrary::TestApi; CrosLibrary(); diff --git a/chrome/browser/chromeos/login/screen_locker.cc b/chrome/browser/chromeos/login/screen_locker.cc index a2beddc..c4ca040 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/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 245aea7..d683d97 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 @@ -555,7 +558,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 diff --git a/chrome/common/sqlite_utils.cc b/chrome/common/sqlite_utils.cc index d11b925..9d16c7f 100644 --- a/chrome/common/sqlite_utils.cc +++ b/chrome/common/sqlite_utils.cc @@ -8,8 +8,8 @@ #include "base/file_path.h" #include "base/lock.h" +#include "base/lazy_instance.h" #include "base/logging.h" -#include "base/singleton.h" #include "base/stl_util-inl.h" #include "base/string16.h" @@ -76,10 +76,13 @@ class DefaultSQLErrorHandlerFactory : public SQLErrorHandlerFactory { Lock lock_; }; +static base::LazyInstance<DefaultSQLErrorHandlerFactory> + g_default_sql_error_handler_factory(base::LINKER_INITIALIZED); + SQLErrorHandlerFactory* GetErrorHandlerFactory() { // TODO(cpu): Testing needs to override the error handler. // Destruction of DefaultSQLErrorHandlerFactory handled by at_exit manager. - return Singleton<DefaultSQLErrorHandlerFactory>::get(); + return g_default_sql_error_handler_factory.Pointer(); } namespace sqlite_utils { diff --git a/chrome/common/time_format.cc b/chrome/common/time_format.cc index c62f4f5..9de3a402 100644 --- a/chrome/common/time_format.cc +++ b/chrome/common/time_format.cc @@ -7,9 +7,9 @@ #include <vector> #include "app/l10n_util.h" +#include "base/lazy_instance.h" #include "base/logging.h" #include "base/scoped_ptr.h" -#include "base/singleton.h" #include "base/stl_util-inl.h" #include "base/string16.h" #include "base/time.h" @@ -168,8 +168,7 @@ class TimeFormatter { STLDeleteContainerPointers(time_elapsed_formatter_.begin(), time_elapsed_formatter_.end()); } - friend class Singleton<TimeFormatter>; - friend struct DefaultSingletonTraits<TimeFormatter>; + friend struct base::DefaultLazyInstanceTraits<TimeFormatter>; std::vector<icu::PluralFormat*> short_formatter_; std::vector<icu::PluralFormat*> time_left_formatter_; @@ -182,6 +181,9 @@ class TimeFormatter { DISALLOW_COPY_AND_ASSIGN(TimeFormatter); }; +static base::LazyInstance<TimeFormatter> g_time_formatter( + base::LINKER_INITIALIZED); + void TimeFormatter::BuildFormats( FormatType format_type, std::vector<icu::PluralFormat*>* time_formats) { static const icu::UnicodeString kKeywords[] = { @@ -253,8 +255,6 @@ icu::PluralFormat* TimeFormatter::createFallbackFormat( return format; } -Singleton<TimeFormatter> time_formatter; - static string16 FormatTimeImpl(const TimeDelta& delta, FormatType format_type) { if (delta.ToInternalValue() < 0) { NOTREACHED() << "Negative duration"; @@ -264,7 +264,7 @@ static string16 FormatTimeImpl(const TimeDelta& delta, FormatType format_type) { int number; const std::vector<icu::PluralFormat*>& formatters = - time_formatter->formatter(format_type); + g_time_formatter.Get().formatter(format_type); UErrorCode error = U_ZERO_ERROR; icu::UnicodeString time_string; diff --git a/chrome/installer/util/master_preferences.cc b/chrome/installer/util/master_preferences.cc index 9fc3bd4..a5f763c 100644 --- a/chrome/installer/util/master_preferences.cc +++ b/chrome/installer/util/master_preferences.cc @@ -5,9 +5,9 @@ #include "chrome/installer/util/master_preferences.h" #include "base/file_util.h" +#include "base/lazy_instance.h" #include "base/logging.h" #include "base/path_service.h" -#include "base/singleton.h" #include "base/string_util.h" #include "chrome/common/json_value_serializer.h" #include "chrome/installer/util/master_preferences_constants.h" @@ -19,6 +19,9 @@ namespace { const char kDistroDict[] = "distribution"; const char kFirstRunTabs[] = "first_run_tabs"; +base::LazyInstance<installer_util::MasterPreferences> g_master_preferences( + base::LINKER_INITIALIZED); + bool GetGURLFromValue(const Value* in_value, GURL* out_value) { if (!in_value || !out_value) return false; @@ -254,6 +257,6 @@ bool MasterPreferences::GetExtensionsBlock(DictionaryValue** extensions) const { // static const MasterPreferences& MasterPreferences::ForCurrentProcess() { - return *Singleton<MasterPreferences>::get(); + return g_master_preferences.Get(); } } // installer_util diff --git a/chrome/plugin/webplugin_proxy.cc b/chrome/plugin/webplugin_proxy.cc index 87a4772..bb77108 100644 --- a/chrome/plugin/webplugin_proxy.cc +++ b/chrome/plugin/webplugin_proxy.cc @@ -9,13 +9,13 @@ #if defined(OS_WIN) #include "app/win_util.h" #endif +#include "base/lazy_instance.h" #if defined(OS_MACOSX) #include "base/mac_util.h" #include "base/mac/scoped_cftyperef.h" #endif #include "base/scoped_handle.h" #include "base/shared_memory.h" -#include "base/singleton.h" #include "build/build_config.h" #include "chrome/common/child_process_logging.h" #include "chrome/common/plugin_messages.h" @@ -47,9 +47,7 @@ using webkit_glue::WebPluginAcceleratedSurface; #endif typedef std::map<CPBrowsingContext, WebPluginProxy*> ContextMap; -static ContextMap& GetContextMap() { - return *Singleton<ContextMap>::get(); -} +static base::LazyInstance<ContextMap> g_context_map(base::LINKER_INITIALIZED); WebPluginProxy::WebPluginProxy( PluginChannel* channel, @@ -93,7 +91,7 @@ WebPluginProxy::WebPluginProxy( WebPluginProxy::~WebPluginProxy() { if (cp_browsing_context_) - GetContextMap().erase(cp_browsing_context_); + g_context_map.Get().erase(cp_browsing_context_); #if defined(USE_X11) if (windowless_shm_pixmap_ != None) @@ -271,14 +269,14 @@ CPBrowsingContext WebPluginProxy::GetCPBrowsingContext() { if (cp_browsing_context_ == 0) { Send(new PluginHostMsg_GetCPBrowsingContext(route_id_, &cp_browsing_context_)); - GetContextMap()[cp_browsing_context_] = this; + g_context_map.Get()[cp_browsing_context_] = this; } return cp_browsing_context_; } WebPluginProxy* WebPluginProxy::FromCPBrowsingContext( CPBrowsingContext context) { - return GetContextMap()[context]; + return g_context_map.Get()[context]; } WebPluginResourceClient* WebPluginProxy::GetResourceClient(int id) { diff --git a/chrome/renderer/extensions/bindings_utils.cc b/chrome/renderer/extensions/bindings_utils.cc index 5b213c4..4776966 100644 --- a/chrome/renderer/extensions/bindings_utils.cc +++ b/chrome/renderer/extensions/bindings_utils.cc @@ -4,6 +4,7 @@ #include "chrome/renderer/extensions/bindings_utils.h" +#include "base/lazy_instance.h" #include "base/string_split.h" #include "base/string_util.h" #include "chrome/renderer/render_view.h" @@ -21,11 +22,14 @@ struct SingletonData { ContextList contexts; PendingRequestMap pending_requests; }; +static base::LazyInstance<SingletonData> g_singleton_data( + base::LINKER_INITIALIZED); typedef std::map<int, std::string> StringMap; +static base::LazyInstance<StringMap> g_string_map(base::LINKER_INITIALIZED); const char* GetStringResource(int resource_id) { - StringMap* strings = Singleton<StringMap>::get(); + StringMap* strings = g_string_map.Pointer(); StringMap::iterator it = strings->find(resource_id); if (it == strings->end()) { it = strings->insert(std::make_pair( @@ -84,7 +88,7 @@ ContextInfo::ContextInfo(v8::Persistent<v8::Context> context, ContextInfo::~ContextInfo() {} ContextList& GetContexts() { - return Singleton<SingletonData>::get()->contexts; + return g_singleton_data.Get().contexts; } ContextList GetContextsForExtension(const std::string& extension_id) { @@ -134,7 +138,7 @@ ContextList::iterator FindContext(v8::Handle<v8::Context> context) { } PendingRequestMap& GetPendingRequestMap() { - return Singleton<SingletonData>::get()->pending_requests; + return g_singleton_data.Get().pending_requests; } RenderView* GetRenderViewForCurrentContext() { diff --git a/chrome/renderer/extensions/renderer_extension_bindings.cc b/chrome/renderer/extensions/renderer_extension_bindings.cc index 9555672..ab7a8eb 100644 --- a/chrome/renderer/extensions/renderer_extension_bindings.cc +++ b/chrome/renderer/extensions/renderer_extension_bindings.cc @@ -8,7 +8,7 @@ #include <string> #include "base/basictypes.h" -#include "base/singleton.h" +#include "base/lazy_instance.h" #include "base/values.h" #include "chrome/common/extensions/extension_message_bundle.h" #include "chrome/common/render_messages.h" @@ -43,17 +43,20 @@ struct ExtensionData { std::map<int, PortData> ports; // port ID -> data }; +static base::LazyInstance<ExtensionData> g_extension_data( + base::LINKER_INITIALIZED); + static bool HasPortData(int port_id) { - return Singleton<ExtensionData>::get()->ports.find(port_id) != - Singleton<ExtensionData>::get()->ports.end(); + return g_extension_data.Get().ports.find(port_id) != + g_extension_data.Get().ports.end(); } static ExtensionData::PortData& GetPortData(int port_id) { - return Singleton<ExtensionData>::get()->ports[port_id]; + return g_extension_data.Get().ports[port_id]; } static void ClearPortData(int port_id) { - Singleton<ExtensionData>::get()->ports.erase(port_id); + g_extension_data.Get().ports.erase(port_id); } const char kPortClosedError[] = "Attempting to use a disconnected port object"; diff --git a/chrome/renderer/ggl/ggl.cc b/chrome/renderer/ggl/ggl.cc index 577e853..c95bbb5 100644 --- a/chrome/renderer/ggl/ggl.cc +++ b/chrome/renderer/ggl/ggl.cc @@ -4,8 +4,8 @@ #include "build/build_config.h" +#include "base/lazy_instance.h" #include "base/ref_counted.h" -#include "base/singleton.h" #include "base/weak_ptr.h" #include "chrome/renderer/command_buffer_proxy.h" #include "chrome/renderer/ggl/ggl.h" @@ -48,6 +48,10 @@ class GLES2Initializer { private: DISALLOW_COPY_AND_ASSIGN(GLES2Initializer); }; + +static base::LazyInstance<GLES2Initializer> g_gles2_initializer( + base::LINKER_INITIALIZED); + } // namespace anonymous // Manages a GL context. @@ -163,7 +167,7 @@ bool Context::Initialize(gfx::NativeViewId view, return false; // Ensure the gles2 library is initialized first in a thread safe way. - Singleton<GLES2Initializer>::get(); + g_gles2_initializer.Get(); // Allocate a frame buffer ID with respect to the parent. if (parent_.get()) { diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc index 609725b..b639dd0 100644 --- a/chrome/renderer/render_view.cc +++ b/chrome/renderer/render_view.cc @@ -15,10 +15,10 @@ #include "base/callback.h" #include "base/command_line.h" #include "base/compiler_specific.h" +#include "base/lazy_instance.h" #include "base/metrics/histogram.h" #include "base/path_service.h" #include "base/process_util.h" -#include "base/singleton.h" #include "base/string_piece.h" #include "base/string_util.h" #include "base/sys_string_conversions.h" @@ -278,6 +278,7 @@ using webkit_glue::WebAccessibility; //----------------------------------------------------------------------------- typedef std::map<WebKit::WebView*, RenderView*> ViewMap; +static base::LazyInstance<ViewMap> g_view_map(base::LINKER_INITIALIZED); // define to write the time necessary for thumbnail/DOM text retrieval, // respectively, into the system debug log @@ -616,7 +617,7 @@ RenderView::~RenderView() { #ifndef NDEBUG // Make sure we are no longer referenced by the ViewMap. - ViewMap* views = Singleton<ViewMap>::get(); + ViewMap* views = g_view_map.Pointer(); for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) DCHECK_NE(this, it->second) << "Failed to call Close?"; #endif @@ -624,7 +625,7 @@ RenderView::~RenderView() { /*static*/ void RenderView::ForEach(RenderViewVisitor* visitor) { - ViewMap* views = Singleton<ViewMap>::get(); + ViewMap* views = g_view_map.Pointer(); for (ViewMap::iterator it = views->begin(); it != views->end(); ++it) { if (!visitor->Visit(it->second)) return; @@ -633,7 +634,7 @@ void RenderView::ForEach(RenderViewVisitor* visitor) { /*static*/ RenderView* RenderView::FromWebView(WebView* webview) { - ViewMap* views = Singleton<ViewMap>::get(); + ViewMap* views = g_view_map.Pointer(); ViewMap::iterator it = views->find(webview); return it == views->end() ? NULL : it->second; } @@ -896,7 +897,7 @@ void RenderView::Init(gfx::NativeViewId parent_hwnd, devtools_agent_.reset(new DevToolsAgent(routing_id, this)); webwidget_ = WebView::create(this, devtools_agent_.get()); - Singleton<ViewMap>::get()->insert(std::make_pair(webview(), this)); + g_view_map.Get().insert(std::make_pair(webview(), this)); webkit_preferences_.Apply(webview()); webview()->initializeMainFrame(this); if (!frame_name.empty()) @@ -5448,7 +5449,7 @@ void RenderView::Close() { // We need to grab a pointer to the doomed WebView before we destroy it. WebView* doomed = webview(); RenderWidget::Close(); - Singleton<ViewMap>::get()->erase(doomed); + g_view_map.Get().erase(doomed); } void RenderView::DidHandleKeyEvent() { |