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 --- webkit/blob/deletable_file_reference.cc | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'webkit/blob') diff --git a/webkit/blob/deletable_file_reference.cc b/webkit/blob/deletable_file_reference.cc index 87ef4cc..7a5cfac 100644 --- a/webkit/blob/deletable_file_reference.cc +++ b/webkit/blob/deletable_file_reference.cc @@ -7,27 +7,25 @@ #include #include "base/file_util.h" #include "base/file_util_proxy.h" +#include "base/lazy_instance.h" #include "base/message_loop_proxy.h" -#include "base/singleton.h" namespace webkit_blob { namespace { typedef std::map DeleteableFileMap; - -DeleteableFileMap* map() { - return Singleton::get(); -} +static base::LazyInstance g_deletable_file_map( + base::LINKER_INITIALIZED); } // namespace // static scoped_refptr DeletableFileReference::Get( const FilePath& path) { - DeleteableFileMap::iterator found = map()->find(path); + DeleteableFileMap::iterator found = g_deletable_file_map.Get().find(path); DeletableFileReference* reference = - (found == map()->end()) ? NULL : found->second; + (found == g_deletable_file_map.Get().end()) ? NULL : found->second; return scoped_refptr(reference); } @@ -36,7 +34,7 @@ scoped_refptr DeletableFileReference::GetOrCreate( const FilePath& path, base::MessageLoopProxy* file_thread) { DCHECK(file_thread); typedef std::pair InsertResult; - InsertResult result = map()->insert( + InsertResult result = g_deletable_file_map.Get().insert( DeleteableFileMap::value_type(path, NULL)); if (result.second == false) return scoped_refptr(result.first->second); @@ -51,12 +49,12 @@ scoped_refptr DeletableFileReference::GetOrCreate( DeletableFileReference::DeletableFileReference( const FilePath& path, base::MessageLoopProxy* file_thread) : path_(path), file_thread_(file_thread) { - DCHECK(map()->find(path_)->second == NULL); + DCHECK(g_deletable_file_map.Get().find(path_)->second == NULL); } DeletableFileReference::~DeletableFileReference() { - DCHECK(map()->find(path_)->second == this); - map()->erase(path_); + DCHECK(g_deletable_file_map.Get().find(path_)->second == this); + g_deletable_file_map.Get().erase(path_); base::FileUtilProxy::Delete(file_thread_, path_, false /* recursive */, NULL); } -- cgit v1.1