From 625332e06437018bf696dce93a4b2bd2c5e0b118 Mon Sep 17 00:00:00 2001 From: "satish@chromium.org" Date: Tue, 14 Dec 2010 07:48:49 +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@69107 0039d316-1c4b-4281-b951-d872f2087c98 --- net/base/mime_util.cc | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) (limited to 'net/base/mime_util.cc') diff --git a/net/base/mime_util.cc b/net/base/mime_util.cc index ddcfc4b..d95c029 100644 --- a/net/base/mime_util.cc +++ b/net/base/mime_util.cc @@ -9,8 +9,8 @@ #include "net/base/platform_mime_util.h" #include "base/hash_tables.h" +#include "base/lazy_instance.h" #include "base/logging.h" -#include "base/singleton.h" #include "base/string_split.h" #include "base/string_util.h" #include "base/utf_string_conversions.h" @@ -51,7 +51,7 @@ class MimeUtil : public PlatformMimeUtil { const std::vector& codecs) const; private: - friend struct DefaultSingletonTraits; + friend struct base::DefaultLazyInstanceTraits; MimeUtil() { InitializeMimeTypeMaps(); } @@ -71,6 +71,8 @@ class MimeUtil : public PlatformMimeUtil { StrictMappings strict_format_map_; }; // class MimeUtil +static base::LazyInstance g_mime_util(base::LINKER_INITIALIZED); + struct MimeInfo { const char* mime_type; const char* extensions; // comma separated list @@ -473,70 +475,67 @@ bool MimeUtil::IsSupportedStrictMediaMimeType(const std::string& mime_type, // Wrappers for the singleton //---------------------------------------------------------------------------- -static MimeUtil* GetMimeUtil() { - return Singleton::get(); -} - bool GetMimeTypeFromExtension(const FilePath::StringType& ext, std::string* mime_type) { - return GetMimeUtil()->GetMimeTypeFromExtension(ext, mime_type); + return g_mime_util.Get().GetMimeTypeFromExtension(ext, mime_type); } bool GetMimeTypeFromFile(const FilePath& file_path, std::string* mime_type) { - return GetMimeUtil()->GetMimeTypeFromFile(file_path, mime_type); + return g_mime_util.Get().GetMimeTypeFromFile(file_path, mime_type); } bool GetPreferredExtensionForMimeType(const std::string& mime_type, FilePath::StringType* extension) { - return GetMimeUtil()->GetPreferredExtensionForMimeType(mime_type, extension); + return g_mime_util.Get().GetPreferredExtensionForMimeType(mime_type, + extension); } bool IsSupportedImageMimeType(const char* mime_type) { - return GetMimeUtil()->IsSupportedImageMimeType(mime_type); + return g_mime_util.Get().IsSupportedImageMimeType(mime_type); } bool IsSupportedMediaMimeType(const char* mime_type) { - return GetMimeUtil()->IsSupportedMediaMimeType(mime_type); + return g_mime_util.Get().IsSupportedMediaMimeType(mime_type); } bool IsSupportedNonImageMimeType(const char* mime_type) { - return GetMimeUtil()->IsSupportedNonImageMimeType(mime_type); + return g_mime_util.Get().IsSupportedNonImageMimeType(mime_type); } bool IsSupportedJavascriptMimeType(const char* mime_type) { - return GetMimeUtil()->IsSupportedJavascriptMimeType(mime_type); + return g_mime_util.Get().IsSupportedJavascriptMimeType(mime_type); } bool IsViewSourceMimeType(const char* mime_type) { - return GetMimeUtil()->IsViewSourceMimeType(mime_type); + return g_mime_util.Get().IsViewSourceMimeType(mime_type); } bool IsSupportedMimeType(const std::string& mime_type) { - return GetMimeUtil()->IsSupportedMimeType(mime_type); + return g_mime_util.Get().IsSupportedMimeType(mime_type); } bool MatchesMimeType(const std::string &mime_type_pattern, const std::string &mime_type) { - return GetMimeUtil()->MatchesMimeType(mime_type_pattern, mime_type); + return g_mime_util.Get().MatchesMimeType(mime_type_pattern, mime_type); } bool AreSupportedMediaCodecs(const std::vector& codecs) { - return GetMimeUtil()->AreSupportedMediaCodecs(codecs); + return g_mime_util.Get().AreSupportedMediaCodecs(codecs); } bool IsStrictMediaMimeType(const std::string& mime_type) { - return GetMimeUtil()->IsStrictMediaMimeType(mime_type); + return g_mime_util.Get().IsStrictMediaMimeType(mime_type); } bool IsSupportedStrictMediaMimeType(const std::string& mime_type, const std::vector& codecs) { - return GetMimeUtil()->IsSupportedStrictMediaMimeType(mime_type, codecs); + return g_mime_util.Get().IsSupportedStrictMediaMimeType(mime_type, codecs); } void ParseCodecString(const std::string& codecs, std::vector* codecs_out, const bool strip) { - GetMimeUtil()->ParseCodecString(codecs, codecs_out, strip); + g_mime_util.Get().ParseCodecString(codecs, codecs_out, strip); } namespace { -- cgit v1.1