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 /net | |
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 '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, 119 insertions, 90 deletions
diff --git a/net/base/bandwidth_metrics.cc b/net/base/bandwidth_metrics.cc index eaaa3c0..fa23a77 100644 --- a/net/base/bandwidth_metrics.cc +++ b/net/base/bandwidth_metrics.cc @@ -2,14 +2,35 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "base/singleton.h" +#include "base/lazy_instance.h" #include "net/base/bandwidth_metrics.h" +static base::LazyInstance<net::BandwidthMetrics> g_bandwidth_metrics( + base::LINKER_INITIALIZED); + namespace net { ScopedBandwidthMetrics::ScopedBandwidthMetrics() - : metrics_(Singleton<BandwidthMetrics>::get()), - started_(false) { + : 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); } } // namespace net diff --git a/net/base/bandwidth_metrics.h b/net/base/bandwidth_metrics.h index aef366d..ce1a498 100644 --- a/net/base/bandwidth_metrics.h +++ b/net/base/bandwidth_metrics.h @@ -122,30 +122,16 @@ class BandwidthMetrics { class ScopedBandwidthMetrics { public: ScopedBandwidthMetrics(); + ~ScopedBandwidthMetrics(); - ~ScopedBandwidthMetrics() { - if (started_) - metrics_->StopStream(); - } - - void StartStream() { - started_ = true; - metrics_->StartStream(); - } - - void StopStream() { - started_ = false; - metrics_->StopStream(); - } - - void RecordBytes(int bytes) { metrics_->RecordBytes(bytes); } + void StartStream(); + void StopStream(); + void RecordBytes(int 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 5056e5d..8e69104 100644 --- a/net/base/cert_database_nss_unittest.cc +++ b/net/base/cert_database_nss_unittest.cc @@ -104,16 +104,9 @@ bool ReadCertIntoList(const std::string& name, CertificateList* certs) { class CertDatabaseNSSTest : public testing::Test { public: virtual void SetUp() { - 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; - } + ASSERT_TRUE(temp_db_dir_.CreateUniqueTempDir()); + ASSERT_TRUE( + base::OpenTestNSSDB(temp_db_dir_.path(), "CertDatabaseNSSTest db")); slot_.reset(base::GetDefaultNSSKeySlot()); // Test db should be empty at start of test. @@ -121,7 +114,6 @@ 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())); @@ -133,12 +125,9 @@ class CertDatabaseNSSTest : public testing::Test { CertDatabase cert_db_; private: - static bool temp_db_initialized_; + ScopedTempDir temp_db_dir_; }; -// 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 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<std::string>& codecs) const; private: - friend struct DefaultSingletonTraits<MimeUtil>; + friend struct base::DefaultLazyInstanceTraits<MimeUtil>; MimeUtil() { InitializeMimeTypeMaps(); } @@ -71,6 +71,8 @@ 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 @@ -473,70 +475,67 @@ 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 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<std::string>& 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<std::string>& codecs) { - return GetMimeUtil()->IsSupportedStrictMediaMimeType(mime_type, codecs); + return g_mime_util.Get().IsSupportedStrictMediaMimeType(mime_type, codecs); } void ParseCodecString(const std::string& codecs, std::vector<std::string>* codecs_out, const bool strip) { - GetMimeUtil()->ParseCodecString(codecs, codecs_out, strip); + g_mime_util.Get().ParseCodecString(codecs, codecs_out, strip); } namespace { diff --git a/net/base/winsock_init.cc b/net/base/winsock_init.cc index ccaf01c..41810ef 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,12 +37,15 @@ class WinsockInitSingleton { } }; +static base::LazyInstance<WinsockInitSingleton> g_winsock_init_singleton( + base::LINKER_INITIALIZED); + } // namespace namespace net { void EnsureWinsockInit() { - Singleton<WinsockInitSingleton>::get(); + g_winsock_init_singleton.Get(); } } // namespace net diff --git a/net/base/x509_certificate_win.cc b/net/base/x509_certificate_win.cc index 75cdf40..71aa545 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 DefaultSingletonTraits<GlobalCertStore>; + friend struct base::DefaultLazyInstanceTraits<GlobalCertStore>; GlobalCertStore() : cert_store_(CertOpenStore(CERT_STORE_PROV_MEMORY, 0, NULL, 0, NULL)) { @@ -544,9 +544,12 @@ class GlobalCertStore { DISALLOW_COPY_AND_ASSIGN(GlobalCertStore); }; +static base::LazyInstance<GlobalCertStore> g_cert_store( + base::LINKER_INITIALIZED); + // static HCERTSTORE X509Certificate::cert_store() { - return Singleton<GlobalCertStore>::get()->cert_store(); + return g_cert_store.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 5b01224..737b8e8 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,6 +33,9 @@ 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); @@ -52,7 +55,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 = Singleton<CompletionHandler>::get(); + context_.handler = g_completion_handler.Pointer(); context_.overlapped.Offset = static_cast<DWORD>(offset); file_ = file; callback_ = callback; @@ -81,7 +84,7 @@ bool File::Init(const FilePath& name) { return false; MessageLoopForIO::current()->RegisterIOHandler( - platform_file_, Singleton<CompletionHandler>::get()); + platform_file_, g_completion_handler.Pointer()); init_ = true; sync_platform_file_ = CreateFile(name.value().c_str(), access, sharing, NULL, @@ -255,7 +258,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 = Singleton<CompletionHandler>::get(); + MessageLoopForIO::IOHandler* handler = g_completion_handler.Pointer(); MessageLoopForIO::current()->WaitForIOCompletion(100, handler); } } diff --git a/net/socket/client_socket_factory.cc b/net/socket/client_socket_factory.cc index 8965630..1c998c6 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/singleton.h" +#include "base/lazy_instance.h" #include "build/build_config.h" #include "net/socket/client_socket_handle.h" #if defined(OS_WIN) @@ -71,11 +71,14 @@ class DefaultClientSocketFactory : public ClientSocketFactory { } }; +static base::LazyInstance<DefaultClientSocketFactory> + g_default_client_socket_factory(base::LINKER_INITIALIZED); + } // namespace // static ClientSocketFactory* ClientSocketFactory::GetDefaultFactory() { - return Singleton<DefaultClientSocketFactory>::get(); + return g_default_client_socket_factory.Pointer(); } // static diff --git a/net/socket/dns_cert_provenance_checker.cc b/net/socket/dns_cert_provenance_checker.cc index 27c4982..2243755 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,13 +72,16 @@ class DnsCertLimits { } private: - friend struct DefaultSingletonTraits<DnsCertLimits>; + friend struct base::DefaultLazyInstanceTraits<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 { @@ -105,7 +108,7 @@ class DnsCertProvenanceCheck : public NonThreadSafe { if (der_certs_.empty()) return; - DnsCertLimits* const limits = Singleton<DnsCertLimits>::get(); + DnsCertLimits* const limits = g_dns_cert_limits.Pointer(); if (limits->HaveReachedMaxUploads() || limits->HaveUploadedForHostname(hostname_)) { return; @@ -146,7 +149,7 @@ class DnsCertProvenanceCheck : public NonThreadSafe { LOG(ERROR) << "FAILED" << " hostname:" << hostname_ << " domain:" << domain_; - Singleton<DnsCertLimits>::get()->DidUpload(hostname_); + g_dns_cert_limits.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 fb0c26e..488beeb 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 DefaultSingletonTraits<EnabledCipherSuites>; + friend struct base::DefaultLazyInstanceTraits<EnabledCipherSuites>; EnabledCipherSuites(); ~EnabledCipherSuites() {} @@ -484,6 +484,9 @@ 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); @@ -786,7 +789,7 @@ int SSLClientSocketMac::InitializeSSLContext() { return NetErrorFromOSStatus(status); std::vector<SSLCipherSuite> enabled_ciphers = - Singleton<EnabledCipherSuites>::get()->ciphers(); + g_enabled_cipher_suites.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 713fce3..435af0a 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,6 +185,9 @@ 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. @@ -195,7 +198,7 @@ void EnsureNSSSSLInit() { // http://code.google.com/p/chromium/issues/detail?id=59847 base::ThreadRestrictions::ScopedAllowIO allow_io; - Singleton<NSSSSLInitSingleton>::get(); + g_nss_ssl_init_singleton.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 fbe4913..19c3814 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,6 +194,9 @@ 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, @@ -285,9 +288,9 @@ static int GetCredHandle(PCCERT_CONTEXT client_cert, NOTREACHED(); return ERR_UNEXPECTED; } - return Singleton<CredHandleTable>::get()->GetHandle(client_cert, - ssl_version_mask, - handle_ptr); + return g_cred_handle_table.Get().GetHandle(client_cert, + ssl_version_mask, + handle_ptr); } //----------------------------------------------------------------------------- @@ -356,6 +359,9 @@ class ClientCertStore { HCERTSTORE store_; }; +static base::LazyInstance<ClientCertStore> g_client_cert_store( + base::LINKER_INITIALIZED); + //----------------------------------------------------------------------------- // Size of recv_buffer_ @@ -507,7 +513,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 = - Singleton<ClientCertStore>::get()->CopyCertContext(cert_context); + g_client_cert_store.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 aae8d90..cf2b0cf 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,10 +252,13 @@ class PKCS12InitSingleton { } }; +static base::LazyInstance<PKCS12InitSingleton> g_pkcs12_init_singleton( + base::LINKER_INITIALIZED); + } // namespace void EnsurePKCS12Init() { - Singleton<PKCS12InitSingleton>::get(); + g_pkcs12_init_singleton.Get(); } // Based on nsPKCS12Blob::ImportFromFile. diff --git a/net/tools/fetch/fetch_client.cc b/net/tools/fetch/fetch_client.cc index 138bed3..800f3070 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,6 +47,8 @@ class Driver { int clients_; }; +static base::LazyInstance<Driver> g_driver(base::LINKER_INITIALIZED); + // A network client class Client { public: @@ -60,7 +62,7 @@ class Client { int rv = factory->CreateTransaction(&transaction_); DCHECK_EQ(net::OK, rv); buffer_->AddRef(); - driver_->ClientStarted(); + g_driver.Get().ClientStarted(); request_info_.url = url_; request_info_.method = "GET"; int state = transaction_->Start( @@ -101,7 +103,7 @@ class Client { void OnRequestComplete(int result) { static base::StatsCounter requests("FetchClient.requests"); requests.Increment(); - driver_->ClientStopped(); + g_driver.Get().ClientStopped(); printf("."); } @@ -112,7 +114,6 @@ 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 9adbaa3..44c944d 100644 --- a/net/websockets/websocket_job.cc +++ b/net/websockets/websocket_job.cc @@ -6,7 +6,7 @@ #include <algorithm> -#include "base/singleton.h" +#include "base/lazy_instance.h" #include "base/string_tokenizer.h" #include "googleurl/src/gurl.h" #include "net/base/net_errors.h" @@ -40,20 +40,23 @@ net::SocketStreamJob* WebSocketJobFactory( class WebSocketJobInitSingleton { private: - friend struct DefaultSingletonTraits<WebSocketJobInitSingleton>; + friend struct base::DefaultLazyInstanceTraits<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() { - Singleton<WebSocketJobInitSingleton>::get(); + g_websocket_job_init.Get(); } WebSocketJob::WebSocketJob(SocketStream::Delegate* delegate) |