From 864b558217c75dbdebea9db3568056292d4cd274 Mon Sep 17 00:00:00 2001 From: "satish@chromium.org" Date: Sat, 4 Dec 2010 23:00:10 +0000 Subject: This CL add a GetInstance() method to singleton classes instead of relying on the callers to use Singleton. In some cases I have used the LazyInstance pattern as that was simpler. This is a small step towards making all singleton classes use the Singleton pattern within their code and not expect the callers to know about it. I have selected all files under src/app and src/base which use Singleton in this CL. Once this CL goes in I'll work on the rest of the files. BUG=65298 TEST=all existing tests should continue to pass. Review URL: http://codereview.chromium.org/5527004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@68300 0039d316-1c4b-4281-b951-d872f2087c98 --- base/crypto/cssm_init.cc | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'base/crypto') diff --git a/base/crypto/cssm_init.cc b/base/crypto/cssm_init.cc index b04cbe7..46a6ffe 100644 --- a/base/crypto/cssm_init.cc +++ b/base/crypto/cssm_init.cc @@ -22,6 +22,13 @@ namespace { class CSSMInitSingleton { public: + static CSSMInitSingleton* GetInstance() { + return Singleton::get(); + } + + CSSM_CSP_HANDLE csp_handle() const {return csp_handle_;} + + private: CSSMInitSingleton() : inited_(false), loaded_(false), csp_handle_(NULL) { static CSSM_VERSION version = {2, 0}; // TODO(wtc): what should our caller GUID be? @@ -68,18 +75,21 @@ class CSSMInitSingleton { } } - CSSM_CSP_HANDLE csp_handle() const {return csp_handle_;} - - private: bool inited_; // True if CSSM_Init has been called successfully. bool loaded_; // True if CSSM_ModuleLoad has been called successfully. CSSM_CSP_HANDLE csp_handle_; + + friend struct DefaultSingletonTraits; }; // This singleton is separate as it pertains to Apple's wrappers over // their own CSSM handles, as opposed to our own CSSM_CSP_HANDLE. class SecurityServicesSingleton { public: + static SecurityServicesSingleton* GetInstance() { + return Singleton::get(); + } + ~SecurityServicesSingleton() {} Lock& lock() { return lock_; } @@ -100,11 +110,11 @@ class SecurityServicesSingleton { namespace base { void EnsureCSSMInit() { - Singleton::get(); + CSSMInitSingleton::GetInstance(); } CSSM_CSP_HANDLE GetSharedCSPHandle() { - return Singleton::get()->csp_handle(); + return CSSMInitSingleton::GetInstance()->csp_handle(); } void* CSSMMalloc(CSSM_SIZE size, void *alloc_ref) { @@ -145,7 +155,7 @@ void LogCSSMError(const char *fn_name, CSSM_RETURN err) { } Lock& GetMacSecurityServicesLock() { - return Singleton::get()->lock(); + return SecurityServicesSingleton::GetInstance()->lock(); } } // namespace base -- cgit v1.1