diff options
author | satish@chromium.org <satish@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-11 10:23:37 +0000 |
---|---|---|
committer | satish@chromium.org <satish@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-11 10:23:37 +0000 |
commit | 5820d2f0458c851b18df616ef3aff80cb4f8dba4 (patch) | |
tree | dda803c05296f1bd8ee622c6d708a494373dcd1a /net | |
parent | 9acd869ec5621373757a6959310f39e1f5ec3f3d (diff) | |
download | chromium_src-5820d2f0458c851b18df616ef3aff80cb4f8dba4.zip chromium_src-5820d2f0458c851b18df616ef3aff80cb4f8dba4.tar.gz chromium_src-5820d2f0458c851b18df616ef3aff80cb4f8dba4.tar.bz2 |
Revert 68932 - 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
TBR=satish@chromium.org
Review URL: http://codereview.chromium.org/5721005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@68936 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r-- | net/base/bandwidth_metrics.cc | 27 | ||||
-rw-r--r-- | net/base/bandwidth_metrics.h | 22 | ||||
-rw-r--r-- | net/base/cert_database_nss_unittest.cc | 19 | ||||
-rw-r--r-- | net/base/mime_util.cc | 39 | ||||
-rw-r--r-- | net/base/winsock_init.cc | 7 | ||||
-rw-r--r-- | net/base/x509_certificate_win.cc | 9 | ||||
-rw-r--r-- | net/disk_cache/file_win.cc | 11 | ||||
-rw-r--r-- | net/socket/client_socket_factory.cc | 7 | ||||
-rw-r--r-- | net/socket/dns_cert_provenance_checker.cc | 11 | ||||
-rw-r--r-- | net/socket/ssl_client_socket_mac.cc | 9 | ||||
-rw-r--r-- | net/socket/ssl_client_socket_nss.cc | 7 | ||||
-rw-r--r-- | net/socket/ssl_client_socket_win.cc | 16 | ||||
-rw-r--r-- | net/third_party/mozilla_security_manager/nsPKCS12Blob.cpp | 7 | ||||
-rw-r--r-- | net/tools/fetch/fetch_client.cc | 9 | ||||
-rw-r--r-- | net/websockets/websocket_job.cc | 9 |
15 files changed, 90 insertions, 119 deletions
diff --git a/net/base/bandwidth_metrics.cc b/net/base/bandwidth_metrics.cc index fa23a77..eaaa3c0 100644 --- a/net/base/bandwidth_metrics.cc +++ b/net/base/bandwidth_metrics.cc @@ -2,35 +2,14 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "base/lazy_instance.h" +#include "base/singleton.h" #include "net/base/bandwidth_metrics.h" -static base::LazyInstance<net::BandwidthMetrics> g_bandwidth_metrics( - base::LINKER_INITIALIZED); - namespace net { ScopedBandwidthMetrics::ScopedBandwidthMetrics() - : started_(false) { -} - -ScopedBandwidthMetrics::~ScopedBandwidthMetrics() { - if (started_) - g_bandwidth_metrics.Get().StopStream(); -} - -void ScopedBandwidthMetrics::StartStream() { - started_ = true; - g_bandwidth_metrics.Get().StartStream(); -} - -void ScopedBandwidthMetrics::StopStream() { - started_ = false; - g_bandwidth_metrics.Get().StopStream(); -} - -void ScopedBandwidthMetrics::RecordBytes(int bytes) { - g_bandwidth_metrics.Get().RecordBytes(bytes); + : metrics_(Singleton<BandwidthMetrics>::get()), + started_(false) { } } // namespace net diff --git a/net/base/bandwidth_metrics.h b/net/base/bandwidth_metrics.h index ce1a498..aef366d 100644 --- a/net/base/bandwidth_metrics.h +++ b/net/base/bandwidth_metrics.h @@ -122,16 +122,30 @@ class BandwidthMetrics { class ScopedBandwidthMetrics { public: ScopedBandwidthMetrics(); - ~ScopedBandwidthMetrics(); - void StartStream(); - void StopStream(); - void RecordBytes(int bytes); + ~ScopedBandwidthMetrics() { + if (started_) + metrics_->StopStream(); + } + + void StartStream() { + started_ = true; + metrics_->StartStream(); + } + + void StopStream() { + started_ = false; + metrics_->StopStream(); + } + + void RecordBytes(int bytes) { metrics_->RecordBytes(bytes); } private: + BandwidthMetrics* metrics_; bool started_; }; } // namespace net #endif // NET_BASE_BANDWIDTH_METRICS_H_ + diff --git a/net/base/cert_database_nss_unittest.cc b/net/base/cert_database_nss_unittest.cc index 8e69104..5056e5d 100644 --- a/net/base/cert_database_nss_unittest.cc +++ b/net/base/cert_database_nss_unittest.cc @@ -104,9 +104,16 @@ bool ReadCertIntoList(const std::string& name, CertificateList* certs) { class CertDatabaseNSSTest : public testing::Test { public: virtual void SetUp() { - ASSERT_TRUE(temp_db_dir_.CreateUniqueTempDir()); - ASSERT_TRUE( - base::OpenTestNSSDB(temp_db_dir_.path(), "CertDatabaseNSSTest db")); + if (!temp_db_initialized_) { + ScopedTempDir* temp_db_dir = Singleton< + ScopedTempDir, + DefaultSingletonTraits<ScopedTempDir>, + CertDatabaseNSSTest>::get(); + ASSERT_TRUE(temp_db_dir->CreateUniqueTempDir()); + ASSERT_TRUE( + base::OpenTestNSSDB(temp_db_dir->path(), "CertDatabaseNSSTest db")); + temp_db_initialized_ = true; + } slot_.reset(base::GetDefaultNSSKeySlot()); // Test db should be empty at start of test. @@ -114,6 +121,7 @@ class CertDatabaseNSSTest : public testing::Test { } virtual void TearDown() { // Don't try to cleanup if the setup failed. + ASSERT_TRUE(temp_db_initialized_); ASSERT_TRUE(slot_.get()); EXPECT_TRUE(CleanupSlotContents(slot_.get())); @@ -125,9 +133,12 @@ class CertDatabaseNSSTest : public testing::Test { CertDatabase cert_db_; private: - ScopedTempDir temp_db_dir_; + static bool temp_db_initialized_; }; +// static +bool CertDatabaseNSSTest::temp_db_initialized_ = false; + TEST_F(CertDatabaseNSSTest, ListCerts) { // This test isn't terribly useful, though it will at least let valgrind test // for leaks. diff --git a/net/base/mime_util.cc b/net/base/mime_util.cc index d95c029..ddcfc4b 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<std::string>& codecs) const; private: - friend struct base::DefaultLazyInstanceTraits<MimeUtil>; + friend struct DefaultSingletonTraits<MimeUtil>; MimeUtil() { InitializeMimeTypeMaps(); } @@ -71,8 +71,6 @@ class MimeUtil : public PlatformMimeUtil { StrictMappings strict_format_map_; }; // class MimeUtil -static base::LazyInstance<MimeUtil> g_mime_util(base::LINKER_INITIALIZED); - struct MimeInfo { const char* mime_type; const char* extensions; // comma separated list @@ -475,67 +473,70 @@ bool MimeUtil::IsSupportedStrictMediaMimeType(const std::string& mime_type, // Wrappers for the singleton //---------------------------------------------------------------------------- +static MimeUtil* GetMimeUtil() { + return Singleton<MimeUtil>::get(); +} + bool GetMimeTypeFromExtension(const FilePath::StringType& ext, std::string* mime_type) { - return g_mime_util.Get().GetMimeTypeFromExtension(ext, mime_type); + return GetMimeUtil()->GetMimeTypeFromExtension(ext, mime_type); } bool GetMimeTypeFromFile(const FilePath& file_path, std::string* mime_type) { - return g_mime_util.Get().GetMimeTypeFromFile(file_path, mime_type); + return GetMimeUtil()->GetMimeTypeFromFile(file_path, mime_type); } bool GetPreferredExtensionForMimeType(const std::string& mime_type, FilePath::StringType* extension) { - return g_mime_util.Get().GetPreferredExtensionForMimeType(mime_type, - extension); + return GetMimeUtil()->GetPreferredExtensionForMimeType(mime_type, extension); } bool IsSupportedImageMimeType(const char* mime_type) { - return g_mime_util.Get().IsSupportedImageMimeType(mime_type); + return GetMimeUtil()->IsSupportedImageMimeType(mime_type); } bool IsSupportedMediaMimeType(const char* mime_type) { - return g_mime_util.Get().IsSupportedMediaMimeType(mime_type); + return GetMimeUtil()->IsSupportedMediaMimeType(mime_type); } bool IsSupportedNonImageMimeType(const char* mime_type) { - return g_mime_util.Get().IsSupportedNonImageMimeType(mime_type); + return GetMimeUtil()->IsSupportedNonImageMimeType(mime_type); } bool IsSupportedJavascriptMimeType(const char* mime_type) { - return g_mime_util.Get().IsSupportedJavascriptMimeType(mime_type); + return GetMimeUtil()->IsSupportedJavascriptMimeType(mime_type); } bool IsViewSourceMimeType(const char* mime_type) { - return g_mime_util.Get().IsViewSourceMimeType(mime_type); + return GetMimeUtil()->IsViewSourceMimeType(mime_type); } bool IsSupportedMimeType(const std::string& mime_type) { - return g_mime_util.Get().IsSupportedMimeType(mime_type); + return GetMimeUtil()->IsSupportedMimeType(mime_type); } bool MatchesMimeType(const std::string &mime_type_pattern, const std::string &mime_type) { - return g_mime_util.Get().MatchesMimeType(mime_type_pattern, mime_type); + return GetMimeUtil()->MatchesMimeType(mime_type_pattern, mime_type); } bool AreSupportedMediaCodecs(const std::vector<std::string>& codecs) { - return g_mime_util.Get().AreSupportedMediaCodecs(codecs); + return GetMimeUtil()->AreSupportedMediaCodecs(codecs); } bool IsStrictMediaMimeType(const std::string& mime_type) { - return g_mime_util.Get().IsStrictMediaMimeType(mime_type); + return GetMimeUtil()->IsStrictMediaMimeType(mime_type); } bool IsSupportedStrictMediaMimeType(const std::string& mime_type, const std::vector<std::string>& codecs) { - return g_mime_util.Get().IsSupportedStrictMediaMimeType(mime_type, codecs); + return GetMimeUtil()->IsSupportedStrictMediaMimeType(mime_type, codecs); } void ParseCodecString(const std::string& codecs, std::vector<std::string>* codecs_out, const bool strip) { - g_mime_util.Get().ParseCodecString(codecs, codecs_out, strip); + GetMimeUtil()->ParseCodecString(codecs, codecs_out, strip); } namespace { diff --git a/net/base/winsock_init.cc b/net/base/winsock_init.cc index 41810ef..ccaf01c 100644 --- a/net/base/winsock_init.cc +++ b/net/base/winsock_init.cc @@ -6,8 +6,8 @@ #include "net/base/winsock_init.h" -#include "base/lazy_instance.h" #include "base/logging.h" +#include "base/singleton.h" namespace { @@ -37,15 +37,12 @@ class WinsockInitSingleton { } }; -static base::LazyInstance<WinsockInitSingleton> g_winsock_init_singleton( - base::LINKER_INITIALIZED); - } // namespace namespace net { void EnsureWinsockInit() { - g_winsock_init_singleton.Get(); + Singleton<WinsockInitSingleton>::get(); } } // namespace net diff --git a/net/base/x509_certificate_win.cc b/net/base/x509_certificate_win.cc index 71aa545..75cdf40 100644 --- a/net/base/x509_certificate_win.cc +++ b/net/base/x509_certificate_win.cc @@ -4,9 +4,9 @@ #include "net/base/x509_certificate.h" -#include "base/lazy_instance.h" #include "base/logging.h" #include "base/pickle.h" +#include "base/singleton.h" #include "base/string_tokenizer.h" #include "base/string_util.h" #include "base/utf_string_conversions.h" @@ -529,7 +529,7 @@ class GlobalCertStore { } private: - friend struct base::DefaultLazyInstanceTraits<GlobalCertStore>; + friend struct DefaultSingletonTraits<GlobalCertStore>; GlobalCertStore() : cert_store_(CertOpenStore(CERT_STORE_PROV_MEMORY, 0, NULL, 0, NULL)) { @@ -544,12 +544,9 @@ class GlobalCertStore { DISALLOW_COPY_AND_ASSIGN(GlobalCertStore); }; -static base::LazyInstance<GlobalCertStore> g_cert_store( - base::LINKER_INITIALIZED); - // static HCERTSTORE X509Certificate::cert_store() { - return g_cert_store.Get().cert_store(); + return Singleton<GlobalCertStore>::get()->cert_store(); } int X509Certificate::Verify(const std::string& hostname, diff --git a/net/disk_cache/file_win.cc b/net/disk_cache/file_win.cc index 737b8e8..5b01224 100644 --- a/net/disk_cache/file_win.cc +++ b/net/disk_cache/file_win.cc @@ -5,8 +5,8 @@ #include "net/disk_cache/file.h" #include "base/file_path.h" -#include "base/lazy_instance.h" #include "base/message_loop.h" +#include "base/singleton.h" #include "net/disk_cache/disk_cache.h" namespace { @@ -33,9 +33,6 @@ class CompletionHandler : public MessageLoopForIO::IOHandler { DWORD actual_bytes, DWORD error); }; -static base::LazyInstance<CompletionHandler> g_completion_handler( - base::LINKER_INITIALIZED); - void CompletionHandler::OnIOCompleted(MessageLoopForIO::IOContext* context, DWORD actual_bytes, DWORD error) { MyOverlapped* data = reinterpret_cast<MyOverlapped*>(context); @@ -55,7 +52,7 @@ void CompletionHandler::OnIOCompleted(MessageLoopForIO::IOContext* context, MyOverlapped::MyOverlapped(disk_cache::File* file, size_t offset, disk_cache::FileIOCallback* callback) { memset(this, 0, sizeof(*this)); - context_.handler = g_completion_handler.Pointer(); + context_.handler = Singleton<CompletionHandler>::get(); context_.overlapped.Offset = static_cast<DWORD>(offset); file_ = file; callback_ = callback; @@ -84,7 +81,7 @@ bool File::Init(const FilePath& name) { return false; MessageLoopForIO::current()->RegisterIOHandler( - platform_file_, g_completion_handler.Pointer()); + platform_file_, Singleton<CompletionHandler>::get()); init_ = true; sync_platform_file_ = CreateFile(name.value().c_str(), access, sharing, NULL, @@ -258,7 +255,7 @@ void File::WaitForPendingIO(int* num_pending_io) { while (*num_pending_io) { // Asynchronous IO operations may be in flight and the completion may end // up calling us back so let's wait for them. - MessageLoopForIO::IOHandler* handler = g_completion_handler.Pointer(); + MessageLoopForIO::IOHandler* handler = Singleton<CompletionHandler>::get(); MessageLoopForIO::current()->WaitForIOCompletion(100, handler); } } diff --git a/net/socket/client_socket_factory.cc b/net/socket/client_socket_factory.cc index 1c998c6..8965630 100644 --- a/net/socket/client_socket_factory.cc +++ b/net/socket/client_socket_factory.cc @@ -4,7 +4,7 @@ #include "net/socket/client_socket_factory.h" -#include "base/lazy_instance.h" +#include "base/singleton.h" #include "build/build_config.h" #include "net/socket/client_socket_handle.h" #if defined(OS_WIN) @@ -71,14 +71,11 @@ class DefaultClientSocketFactory : public ClientSocketFactory { } }; -static base::LazyInstance<DefaultClientSocketFactory> - g_default_client_socket_factory(base::LINKER_INITIALIZED); - } // namespace // static ClientSocketFactory* ClientSocketFactory::GetDefaultFactory() { - return g_default_client_socket_factory.Pointer(); + return Singleton<DefaultClientSocketFactory>::get(); } // static diff --git a/net/socket/dns_cert_provenance_checker.cc b/net/socket/dns_cert_provenance_checker.cc index 2243755..27c4982 100644 --- a/net/socket/dns_cert_provenance_checker.cc +++ b/net/socket/dns_cert_provenance_checker.cc @@ -19,10 +19,10 @@ #include "base/basictypes.h" #include "base/crypto/encryptor.h" #include "base/crypto/symmetric_key.h" -#include "base/lazy_instance.h" #include "base/non_thread_safe.h" #include "base/pickle.h" #include "base/scoped_ptr.h" +#include "base/singleton.h" #include "net/base/completion_callback.h" #include "net/base/dns_util.h" #include "net/base/dnsrr_resolver.h" @@ -72,16 +72,13 @@ class DnsCertLimits { } private: - friend struct base::DefaultLazyInstanceTraits<DnsCertLimits>; + friend struct DefaultSingletonTraits<DnsCertLimits>; std::set<std::string> uploaded_hostnames_; DISALLOW_COPY_AND_ASSIGN(DnsCertLimits); }; -static base::LazyInstance<DnsCertLimits> g_dns_cert_limits( - base::LINKER_INITIALIZED); - // DnsCertProvenanceCheck performs the DNS lookup of the certificate. This // class is self-deleting. class DnsCertProvenanceCheck : public NonThreadSafe { @@ -108,7 +105,7 @@ class DnsCertProvenanceCheck : public NonThreadSafe { if (der_certs_.empty()) return; - DnsCertLimits* const limits = g_dns_cert_limits.Pointer(); + DnsCertLimits* const limits = Singleton<DnsCertLimits>::get(); if (limits->HaveReachedMaxUploads() || limits->HaveUploadedForHostname(hostname_)) { return; @@ -149,7 +146,7 @@ class DnsCertProvenanceCheck : public NonThreadSafe { LOG(ERROR) << "FAILED" << " hostname:" << hostname_ << " domain:" << domain_; - g_dns_cert_limits.Get().DidUpload(hostname_); + Singleton<DnsCertLimits>::get()->DidUpload(hostname_); delegate_->OnDnsCertLookupFailed(hostname_, der_certs_); } else if (status == OK) { LOG(ERROR) << "GOOD" diff --git a/net/socket/ssl_client_socket_mac.cc b/net/socket/ssl_client_socket_mac.cc index 488beeb..fb0c26e 100644 --- a/net/socket/ssl_client_socket_mac.cc +++ b/net/socket/ssl_client_socket_mac.cc @@ -11,8 +11,8 @@ #include <algorithm> -#include "base/lazy_instance.h" #include "base/mac/scoped_cftyperef.h" +#include "base/singleton.h" #include "base/string_util.h" #include "net/base/address_list.h" #include "net/base/cert_verifier.h" @@ -475,7 +475,7 @@ class EnabledCipherSuites { const std::vector<SSLCipherSuite>& ciphers() const { return ciphers_; } private: - friend struct base::DefaultLazyInstanceTraits<EnabledCipherSuites>; + friend struct DefaultSingletonTraits<EnabledCipherSuites>; EnabledCipherSuites(); ~EnabledCipherSuites() {} @@ -484,9 +484,6 @@ class EnabledCipherSuites { DISALLOW_COPY_AND_ASSIGN(EnabledCipherSuites); }; -static base::LazyInstance<EnabledCipherSuites> g_enabled_cipher_suites( - base::LINKER_INITIALIZED); - EnabledCipherSuites::EnabledCipherSuites() { SSLContextRef ssl_context; OSStatus status = SSLNewContext(false, &ssl_context); @@ -789,7 +786,7 @@ int SSLClientSocketMac::InitializeSSLContext() { return NetErrorFromOSStatus(status); std::vector<SSLCipherSuite> enabled_ciphers = - g_enabled_cipher_suites.Get().ciphers(); + Singleton<EnabledCipherSuites>::get()->ciphers(); CipherSuiteIsDisabledFunctor is_disabled_cipher( ssl_config_.disabled_cipher_suites); diff --git a/net/socket/ssl_client_socket_nss.cc b/net/socket/ssl_client_socket_nss.cc index f946819..fff4352 100644 --- a/net/socket/ssl_client_socket_nss.cc +++ b/net/socket/ssl_client_socket_nss.cc @@ -63,9 +63,9 @@ #include "base/compiler_specific.h" #include "base/metrics/histogram.h" -#include "base/lazy_instance.h" #include "base/logging.h" #include "base/nss_util.h" +#include "base/singleton.h" #include "base/string_number_conversions.h" #include "base/string_util.h" #include "base/stringprintf.h" @@ -185,9 +185,6 @@ class NSSSSLInitSingleton { } }; -static base::LazyInstance<NSSSSLInitSingleton> g_nss_ssl_init_singleton( - base::LINKER_INITIALIZED); - // Initialize the NSS SSL library if it isn't already initialized. This must // be called before any other NSS SSL functions. This function is // thread-safe, and the NSS SSL library will only ever be initialized once. @@ -198,7 +195,7 @@ void EnsureNSSSSLInit() { // http://code.google.com/p/chromium/issues/detail?id=59847 base::ThreadRestrictions::ScopedAllowIO allow_io; - g_nss_ssl_init_singleton.Get(); + Singleton<NSSSSLInitSingleton>::get(); } // The default error mapping function. diff --git a/net/socket/ssl_client_socket_win.cc b/net/socket/ssl_client_socket_win.cc index 19c3814..fbe4913 100644 --- a/net/socket/ssl_client_socket_win.cc +++ b/net/socket/ssl_client_socket_win.cc @@ -8,8 +8,8 @@ #include <map> #include "base/compiler_specific.h" -#include "base/lazy_instance.h" #include "base/lock.h" +#include "base/singleton.h" #include "base/stl_util-inl.h" #include "base/string_util.h" #include "base/utf_string_conversions.h" @@ -194,9 +194,6 @@ class CredHandleTable { CredHandleMap client_cert_creds_; }; -static base::LazyInstance<CredHandleTable> g_cred_handle_table( - base::LINKER_INITIALIZED); - // static int CredHandleTable::InitializeHandle(CredHandle* handle, PCCERT_CONTEXT client_cert, @@ -288,9 +285,9 @@ static int GetCredHandle(PCCERT_CONTEXT client_cert, NOTREACHED(); return ERR_UNEXPECTED; } - return g_cred_handle_table.Get().GetHandle(client_cert, - ssl_version_mask, - handle_ptr); + return Singleton<CredHandleTable>::get()->GetHandle(client_cert, + ssl_version_mask, + handle_ptr); } //----------------------------------------------------------------------------- @@ -359,9 +356,6 @@ class ClientCertStore { HCERTSTORE store_; }; -static base::LazyInstance<ClientCertStore> g_client_cert_store( - base::LINKER_INITIALIZED); - //----------------------------------------------------------------------------- // Size of recv_buffer_ @@ -513,7 +507,7 @@ void SSLClientSocketWin::GetSSLCertRequestInfo( // Copy it to our own certificate store, so that we can close the "MY" // certificate store before returning from this function. PCCERT_CONTEXT cert_context2 = - g_client_cert_store.Get().CopyCertContext(cert_context); + Singleton<ClientCertStore>::get()->CopyCertContext(cert_context); if (!cert_context2) { NOTREACHED(); continue; diff --git a/net/third_party/mozilla_security_manager/nsPKCS12Blob.cpp b/net/third_party/mozilla_security_manager/nsPKCS12Blob.cpp index cf2b0cf..aae8d90 100644 --- a/net/third_party/mozilla_security_manager/nsPKCS12Blob.cpp +++ b/net/third_party/mozilla_security_manager/nsPKCS12Blob.cpp @@ -43,9 +43,9 @@ #include <secerr.h> #include "base/crypto/scoped_nss_types.h" -#include "base/lazy_instance.h" #include "base/logging.h" #include "base/nss_util_internal.h" +#include "base/singleton.h" #include "base/string_util.h" #include "net/base/net_errors.h" #include "net/base/x509_certificate.h" @@ -252,13 +252,10 @@ class PKCS12InitSingleton { } }; -static base::LazyInstance<PKCS12InitSingleton> g_pkcs12_init_singleton( - base::LINKER_INITIALIZED); - } // namespace void EnsurePKCS12Init() { - g_pkcs12_init_singleton.Get(); + Singleton<PKCS12InitSingleton>::get(); } // Based on nsPKCS12Blob::ImportFromFile. diff --git a/net/tools/fetch/fetch_client.cc b/net/tools/fetch/fetch_client.cc index 800f3070..138bed3 100644 --- a/net/tools/fetch/fetch_client.cc +++ b/net/tools/fetch/fetch_client.cc @@ -6,9 +6,9 @@ #include "base/at_exit.h" #include "base/command_line.h" -#include "base/lazy_instance.h" #include "base/message_loop.h" #include "base/metrics/stats_counters.h" +#include "base/singleton.h" #include "base/string_number_conversions.h" #include "base/string_util.h" #include "net/base/completion_callback.h" @@ -47,8 +47,6 @@ class Driver { int clients_; }; -static base::LazyInstance<Driver> g_driver(base::LINKER_INITIALIZED); - // A network client class Client { public: @@ -62,7 +60,7 @@ class Client { int rv = factory->CreateTransaction(&transaction_); DCHECK_EQ(net::OK, rv); buffer_->AddRef(); - g_driver.Get().ClientStarted(); + driver_->ClientStarted(); request_info_.url = url_; request_info_.method = "GET"; int state = transaction_->Start( @@ -103,7 +101,7 @@ class Client { void OnRequestComplete(int result) { static base::StatsCounter requests("FetchClient.requests"); requests.Increment(); - g_driver.Get().ClientStopped(); + driver_->ClientStopped(); printf("."); } @@ -114,6 +112,7 @@ class Client { scoped_refptr<net::IOBuffer> buffer_; net::CompletionCallbackImpl<Client> connect_callback_; net::CompletionCallbackImpl<Client> read_callback_; + Singleton<Driver> driver_; }; int main(int argc, char**argv) { diff --git a/net/websockets/websocket_job.cc b/net/websockets/websocket_job.cc index 44c944d..9adbaa3 100644 --- a/net/websockets/websocket_job.cc +++ b/net/websockets/websocket_job.cc @@ -6,7 +6,7 @@ #include <algorithm> -#include "base/lazy_instance.h" +#include "base/singleton.h" #include "base/string_tokenizer.h" #include "googleurl/src/gurl.h" #include "net/base/net_errors.h" @@ -40,23 +40,20 @@ net::SocketStreamJob* WebSocketJobFactory( class WebSocketJobInitSingleton { private: - friend struct base::DefaultLazyInstanceTraits<WebSocketJobInitSingleton>; + friend struct DefaultSingletonTraits<WebSocketJobInitSingleton>; WebSocketJobInitSingleton() { net::SocketStreamJob::RegisterProtocolFactory("ws", WebSocketJobFactory); net::SocketStreamJob::RegisterProtocolFactory("wss", WebSocketJobFactory); } }; -static base::LazyInstance<WebSocketJobInitSingleton> g_websocket_job_init( - base::LINKER_INITIALIZED); - } // anonymous namespace namespace net { // static void WebSocketJob::EnsureInit() { - g_websocket_job_init.Get(); + Singleton<WebSocketJobInitSingleton>::get(); } WebSocketJob::WebSocketJob(SocketStream::Delegate* delegate) |