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 /webkit/blob | |
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 'webkit/blob')
-rw-r--r-- | webkit/blob/deletable_file_reference.cc | 20 |
1 files changed, 9 insertions, 11 deletions
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 <map> #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<FilePath, DeletableFileReference*> DeleteableFileMap; - -DeleteableFileMap* map() { - return Singleton<DeleteableFileMap>::get(); -} +static base::LazyInstance<DeleteableFileMap> g_deletable_file_map( + base::LINKER_INITIALIZED); } // namespace // static scoped_refptr<DeletableFileReference> 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<DeletableFileReference>(reference); } @@ -36,7 +34,7 @@ scoped_refptr<DeletableFileReference> DeletableFileReference::GetOrCreate( const FilePath& path, base::MessageLoopProxy* file_thread) { DCHECK(file_thread); typedef std::pair<DeleteableFileMap::iterator, bool> 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<DeletableFileReference>(result.first->second); @@ -51,12 +49,12 @@ scoped_refptr<DeletableFileReference> 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); } |