From 9fc441643df5e17c19133a637c1a9d1a70fbb07c Mon Sep 17 00:00:00 2001 From: "fischman@chromium.org" Date: Mon, 23 Jan 2012 22:56:41 +0000 Subject: Add a convenience typedef LazyInstance::Leaky to avoid repeating T. Converted the first 20 or so hits for LeakyLazyInstanceTraits on codesearch to demonstrate the benefit at callsites. The real change is base/lazy_instance.h; everything else is example. BUG=none TEST=none Review URL: https://chromiumcodereview.appspot.com/9192024 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@118754 0039d316-1c4b-4281-b951-d872f2087c98 --- base/android/jni_android.cc | 4 ++-- base/debug/trace_event_impl.cc | 3 +-- base/lazy_instance.h | 11 ++++++++++- base/lazy_instance_unittest.cc | 5 ++--- base/nix/mime_util_xdg.cc | 5 ++--- base/threading/watchdog.cc | 3 +-- base/tracked_objects.cc | 5 ++--- base/tracked_objects.h | 5 ++--- base/tracked_objects_unittest.cc | 2 +- base/win/sampling_profiler.cc | 3 +-- chrome/common/profiling.cc | 5 ++--- crypto/nss_util.cc | 8 +++----- media/base/media_log.cc | 4 +--- net/base/dns_reloader.cc | 5 ++--- net/base/net_util.cc | 6 ++---- net/base/test_root_certs.cc | 5 ++--- net/base/x509_certificate.cc | 3 +-- net/ocsp/nss_ocsp.cc | 2 +- printing/pdf_metafile_cg_mac.cc | 8 +++----- ui/gfx/gl/gl_context.cc | 8 +++----- ui/gfx/gl/gl_surface.cc | 8 +++----- 21 files changed, 47 insertions(+), 61 deletions(-) diff --git a/base/android/jni_android.cc b/base/android/jni_android.cc index a746fd4..f99f1ab 100644 --- a/base/android/jni_android.cc +++ b/base/android/jni_android.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -40,7 +40,7 @@ struct MethodIdentifier { }; typedef std::map MethodIDMap; -base::LazyInstance > +base::LazyInstance::Leaky g_method_id_map = LAZY_INSTANCE_INITIALIZER; const base::subtle::AtomicWord kUnlocked = 0; const base::subtle::AtomicWord kLocked = 1; diff --git a/base/debug/trace_event_impl.cc b/base/debug/trace_event_impl.cc index 0608c78..a591bac 100644 --- a/base/debug/trace_event_impl.cc +++ b/base/debug/trace_event_impl.cc @@ -64,8 +64,7 @@ const int g_category_metadata = 2; int g_category_index = 3; // skip initial 3 categories // The most-recently captured name of the current thread -LazyInstance, - LeakyLazyInstanceTraits > > +LazyInstance >::Leaky g_current_thread_name = LAZY_INSTANCE_INITIALIZER; void AppendValueAsJSON(unsigned char type, diff --git a/base/lazy_instance.h b/base/lazy_instance.h index ededc73..4ed471a 100644 --- a/base/lazy_instance.h +++ b/base/lazy_instance.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -73,6 +73,11 @@ struct DefaultLazyInstanceTraits { } }; +// Use LazyInstance::Leaky for a less-verbose call-site typedef; e.g.: +// base::LazyInstance::Leaky my_leaky_lazy_instance; +// instead of: +// base::LazyInstance > my_leaky_lazy_instance; +// (especially when T is MyLongTypeNameImplClientHolderFactory). template struct LeakyLazyInstanceTraits { static const bool kRegisterOnExit = false; @@ -117,6 +122,10 @@ class LazyInstance { // the OnExit member function, where needed. // ~LazyInstance() {} + // Convenience typedef to avoid having to repeat Type for leaky lazy + // instances. + typedef LazyInstance > Leaky; + Type& Get() { return *Pointer(); } diff --git a/base/lazy_instance_unittest.cc b/base/lazy_instance_unittest.cc index 9ccbbd5..1bd3ab4 100644 --- a/base/lazy_instance_unittest.cc +++ b/base/lazy_instance_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -133,8 +133,7 @@ TEST(LazyInstanceTest, LeakyLazyInstance) { bool deleted2 = false; { base::ShadowingAtExitManager shadow; - static base::LazyInstance > + static base::LazyInstance::Leaky test = LAZY_INSTANCE_INITIALIZER; test.Get().SetDeletedPtr(&deleted2); } diff --git a/base/nix/mime_util_xdg.cc b/base/nix/mime_util_xdg.cc index fa08bc0..8d21d52 100644 --- a/base/nix/mime_util_xdg.cc +++ b/base/nix/mime_util_xdg.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -33,8 +33,7 @@ namespace { // None of the XDG stuff is thread-safe, so serialize all access under // this lock. -static base::LazyInstance > +static base::LazyInstance::Leaky g_mime_util_xdg_lock = LAZY_INSTANCE_INITIALIZER; class IconTheme; diff --git a/base/threading/watchdog.cc b/base/threading/watchdog.cc index 0219817..d060655 100644 --- a/base/threading/watchdog.cc +++ b/base/threading/watchdog.cc @@ -21,8 +21,7 @@ namespace { // on alarms from callers that specify old times. // Lock for access of static data... -LazyInstance > g_static_lock = - LAZY_INSTANCE_INITIALIZER; +LazyInstance::Leaky g_static_lock = LAZY_INSTANCE_INITIALIZER; // When did we last alarm and get stuck (for a while) in a debugger? TimeTicks g_last_debugged_alarm_time; diff --git a/base/tracked_objects.cc b/base/tracked_objects.cc index b399111..884cd56 100644 --- a/base/tracked_objects.cc +++ b/base/tracked_objects.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -196,8 +196,7 @@ ThreadData* ThreadData::all_thread_data_list_head_ = NULL; ThreadData* ThreadData::first_retired_worker_ = NULL; // static -base::LazyInstance > +base::LazyInstance::Leaky ThreadData::list_lock_ = LAZY_INSTANCE_INITIALIZER; // static diff --git a/base/tracked_objects.h b/base/tracked_objects.h index a088ee2..b1bf02e 100644 --- a/base/tracked_objects.h +++ b/base/tracked_objects.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -575,8 +575,7 @@ class BASE_EXPORT ThreadData { // unregistered_thread_data_pool_. This lock is leaked at shutdown. // The lock is very infrequently used, so we can afford to just make a lazy // instance and be safe. - static base::LazyInstance > list_lock_; + static base::LazyInstance::Leaky list_lock_; // We set status_ to SHUTDOWN when we shut down the tracking service. static Status status_; diff --git a/base/tracked_objects_unittest.cc b/base/tracked_objects_unittest.cc index fad8a9c6..68911bb 100644 --- a/base/tracked_objects_unittest.cc +++ b/base/tracked_objects_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. diff --git a/base/win/sampling_profiler.cc b/base/win/sampling_profiler.cc index dd510ac..150452c 100644 --- a/base/win/sampling_profiler.cc +++ b/base/win/sampling_profiler.cc @@ -104,8 +104,7 @@ ProfilerFuncs::ProfilerFuncs() } } -base::LazyInstance > - funcs = LAZY_INSTANCE_INITIALIZER; +base::LazyInstance::Leaky funcs = LAZY_INSTANCE_INITIALIZER; } // namespace diff --git a/chrome/common/profiling.cc b/chrome/common/profiling.cc index f355052..24914d5 100644 --- a/chrome/common/profiling.cc +++ b/chrome/common/profiling.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -89,8 +89,7 @@ class ProfilingThreadControl { DISALLOW_COPY_AND_ASSIGN(ProfilingThreadControl); }; -base::LazyInstance > +base::LazyInstance::Leaky g_flush_thread_control = LAZY_INSTANCE_INITIALIZER; } // namespace diff --git a/crypto/nss_util.cc b/crypto/nss_util.cc index 2540c0c..c60b7ea 100644 --- a/crypto/nss_util.cc +++ b/crypto/nss_util.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -217,8 +217,7 @@ class NSPRInitSingleton { } }; -base::LazyInstance > +base::LazyInstance::Leaky g_nspr_singleton = LAZY_INSTANCE_INITIALIZER; class NSSInitSingleton { @@ -612,8 +611,7 @@ class NSSInitSingleton { // static bool NSSInitSingleton::force_nodb_init_ = false; -base::LazyInstance > +base::LazyInstance::Leaky g_nss_singleton = LAZY_INSTANCE_INITIALIZER; } // namespace diff --git a/media/base/media_log.cc b/media/base/media_log.cc index d223b51..d77b16d 100644 --- a/media/base/media_log.cc +++ b/media/base/media_log.cc @@ -18,9 +18,7 @@ namespace media { // A count of all MediaLogs created on this render process. // Used to generate unique ids. -static base::LazyInstance< - base::AtomicSequenceNumber, - base::LeakyLazyInstanceTraits > media_log_count = +static base::LazyInstance::Leaky media_log_count = LAZY_INSTANCE_INITIALIZER; const char* MediaLog::EventTypeToString(MediaLogEvent::Type type) { diff --git a/net/base/dns_reloader.cc b/net/base/dns_reloader.cc index d29ae6ac..ff79388 100644 --- a/net/base/dns_reloader.cc +++ b/net/base/dns_reloader.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -103,8 +103,7 @@ class DnsReloader : public net::NetworkChangeNotifier::DNSObserver { base::ThreadLocalStorage::Slot DnsReloader::tls_index_( base::LINKER_INITIALIZED); -base::LazyInstance > +base::LazyInstance::Leaky g_dns_reloader = LAZY_INSTANCE_INITIALIZER; } // namespace diff --git a/net/base/net_util.cc b/net/base/net_util.cc index 9417c1a..05115c9 100644 --- a/net/base/net_util.cc +++ b/net/base/net_util.cc @@ -484,8 +484,7 @@ void SetExemplarSetForLang(const std::string& lang, map.insert(std::make_pair(lang, lang_set)); } -static base::LazyInstance > +static base::LazyInstance::Leaky g_lang_set_lock = LAZY_INSTANCE_INITIALIZER; // Returns true if all the characters in component_characters are used by @@ -1110,8 +1109,7 @@ const FormatUrlType kFormatUrlOmitTrailingSlashOnBareHostname = 1 << 2; const FormatUrlType kFormatUrlOmitAll = kFormatUrlOmitUsernamePassword | kFormatUrlOmitHTTP | kFormatUrlOmitTrailingSlashOnBareHostname; -static base::LazyInstance, - base::LeakyLazyInstanceTraits > > +static base::LazyInstance >::Leaky g_explicitly_allowed_ports = LAZY_INSTANCE_INITIALIZER; size_t GetCountOfExplicitlyAllowedPorts() { diff --git a/net/base/test_root_certs.cc b/net/base/test_root_certs.cc index 6eaf0e7..1742e71 100644 --- a/net/base/test_root_certs.cc +++ b/net/base/test_root_certs.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -17,8 +17,7 @@ namespace { bool g_has_instance = false; -base::LazyInstance > +base::LazyInstance::Leaky g_test_root_certs = LAZY_INSTANCE_INITIALIZER; CertificateList LoadCertificates(const FilePath& filename) { diff --git a/net/base/x509_certificate.cc b/net/base/x509_certificate.cc index 38e65a1..2b35c03 100644 --- a/net/base/x509_certificate.cc +++ b/net/base/x509_certificate.cc @@ -110,8 +110,7 @@ class X509CertificateCache { DISALLOW_COPY_AND_ASSIGN(X509CertificateCache); }; -base::LazyInstance > +base::LazyInstance::Leaky g_x509_certificate_cache = LAZY_INSTANCE_INITIALIZER; void X509CertificateCache::InsertOrUpdate( diff --git a/net/ocsp/nss_ocsp.cc b/net/ocsp/nss_ocsp.cc index 868f5cd..1eb0b21 100644 --- a/net/ocsp/nss_ocsp.cc +++ b/net/ocsp/nss_ocsp.cc @@ -87,7 +87,7 @@ class OCSPIOLoop { DISALLOW_COPY_AND_ASSIGN(OCSPIOLoop); }; -base::LazyInstance > +base::LazyInstance::Leaky g_ocsp_io_loop = LAZY_INSTANCE_INITIALIZER; const int kRecvBufferSize = 4096; diff --git a/printing/pdf_metafile_cg_mac.cc b/printing/pdf_metafile_cg_mac.cc index bf2f68d..6ac1d6b 100644 --- a/printing/pdf_metafile_cg_mac.cc +++ b/printing/pdf_metafile_cg_mac.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -35,10 +35,8 @@ namespace { // single-process mode. TODO(avi): This Apple bug appears fixed in 10.7; when // 10.7 is the minimum required version for Chromium, remove this hack. -base::LazyInstance< - base::ThreadLocalPointer, - base::LeakyLazyInstanceTraits > > - thread_pdf_docs = LAZY_INSTANCE_INITIALIZER; +base::LazyInstance >::Leaky + thread_pdf_docs = LAZY_INSTANCE_INITIALIZER; } // namespace diff --git a/ui/gfx/gl/gl_context.cc b/ui/gfx/gl/gl_context.cc index 199ee7d..dc94b04 100644 --- a/ui/gfx/gl/gl_context.cc +++ b/ui/gfx/gl/gl_context.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -17,10 +17,8 @@ namespace gfx { namespace { -base::LazyInstance< - base::ThreadLocalPointer, - base::LeakyLazyInstanceTraits > > - current_context_ = LAZY_INSTANCE_INITIALIZER; +base::LazyInstance >::Leaky + current_context_ = LAZY_INSTANCE_INITIALIZER; } // namespace GLContext::GLContext(GLShareGroup* share_group) : share_group_(share_group) { diff --git a/ui/gfx/gl/gl_surface.cc b/ui/gfx/gl/gl_surface.cc index 4347185..858fb93b 100644 --- a/ui/gfx/gl/gl_surface.cc +++ b/ui/gfx/gl/gl_surface.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -17,10 +17,8 @@ namespace gfx { namespace { -base::LazyInstance< - base::ThreadLocalPointer, - base::LeakyLazyInstanceTraits > > - current_surface_ = LAZY_INSTANCE_INITIALIZER; +base::LazyInstance >::Leaky + current_surface_ = LAZY_INSTANCE_INITIALIZER; } // namespace // static -- cgit v1.1