summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfischman@chromium.org <fischman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-23 22:56:41 +0000
committerfischman@chromium.org <fischman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-23 22:56:41 +0000
commit9fc441643df5e17c19133a637c1a9d1a70fbb07c (patch)
tree6c4cdb1e8c1ff0b6b132187be94e9968e2c83da1
parent096b0317209cfa8ef79cbf9fb9351f00c1f60087 (diff)
downloadchromium_src-9fc441643df5e17c19133a637c1a9d1a70fbb07c.zip
chromium_src-9fc441643df5e17c19133a637c1a9d1a70fbb07c.tar.gz
chromium_src-9fc441643df5e17c19133a637c1a9d1a70fbb07c.tar.bz2
Add a convenience typedef LazyInstance<T>::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
-rw-r--r--base/android/jni_android.cc4
-rw-r--r--base/debug/trace_event_impl.cc3
-rw-r--r--base/lazy_instance.h11
-rw-r--r--base/lazy_instance_unittest.cc5
-rw-r--r--base/nix/mime_util_xdg.cc5
-rw-r--r--base/threading/watchdog.cc3
-rw-r--r--base/tracked_objects.cc5
-rw-r--r--base/tracked_objects.h5
-rw-r--r--base/tracked_objects_unittest.cc2
-rw-r--r--base/win/sampling_profiler.cc3
-rw-r--r--chrome/common/profiling.cc5
-rw-r--r--crypto/nss_util.cc8
-rw-r--r--media/base/media_log.cc4
-rw-r--r--net/base/dns_reloader.cc5
-rw-r--r--net/base/net_util.cc6
-rw-r--r--net/base/test_root_certs.cc5
-rw-r--r--net/base/x509_certificate.cc3
-rw-r--r--net/ocsp/nss_ocsp.cc2
-rw-r--r--printing/pdf_metafile_cg_mac.cc8
-rw-r--r--ui/gfx/gl/gl_context.cc8
-rw-r--r--ui/gfx/gl/gl_surface.cc8
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<MethodIdentifier, jmethodID> MethodIDMap;
-base::LazyInstance<MethodIDMap, base::LeakyLazyInstanceTraits<MethodIDMap> >
+base::LazyInstance<MethodIDMap>::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<ThreadLocalPointer<const char>,
- LeakyLazyInstanceTraits<ThreadLocalPointer<const char> > >
+LazyInstance<ThreadLocalPointer<const char> >::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<T>::Leaky for a less-verbose call-site typedef; e.g.:
+// base::LazyInstance<T>::Leaky my_leaky_lazy_instance;
+// instead of:
+// base::LazyInstance<T, LeakyLazyInstanceTraits<T> > my_leaky_lazy_instance;
+// (especially when T is MyLongTypeNameImplClientHolderFactory).
template <typename Type>
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<Type, LeakyLazyInstanceTraits<Type> > 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<DeleteLogger,
- base::LeakyLazyInstanceTraits<DeleteLogger> >
+ static base::LazyInstance<DeleteLogger>::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<base::Lock,
- base::LeakyLazyInstanceTraits<base::Lock> >
+static base::LazyInstance<base::Lock>::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<Lock, LeakyLazyInstanceTraits<Lock> > g_static_lock =
- LAZY_INSTANCE_INITIALIZER;
+LazyInstance<Lock>::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::Lock,
- base::LeakyLazyInstanceTraits<base::Lock> >
+base::LazyInstance<base::Lock>::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<base::Lock,
- base::LeakyLazyInstanceTraits<base::Lock> > list_lock_;
+ static base::LazyInstance<base::Lock>::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<ProfilerFuncs, base::LeakyLazyInstanceTraits<ProfilerFuncs> >
- funcs = LAZY_INSTANCE_INITIALIZER;
+base::LazyInstance<ProfilerFuncs>::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<ProfilingThreadControl,
- base::LeakyLazyInstanceTraits<ProfilingThreadControl> >
+base::LazyInstance<ProfilingThreadControl>::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<NSPRInitSingleton,
- base::LeakyLazyInstanceTraits<NSPRInitSingleton> >
+base::LazyInstance<NSPRInitSingleton>::Leaky
g_nspr_singleton = LAZY_INSTANCE_INITIALIZER;
class NSSInitSingleton {
@@ -612,8 +611,7 @@ class NSSInitSingleton {
// static
bool NSSInitSingleton::force_nodb_init_ = false;
-base::LazyInstance<NSSInitSingleton,
- base::LeakyLazyInstanceTraits<NSSInitSingleton> >
+base::LazyInstance<NSSInitSingleton>::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<base::AtomicSequenceNumber> > media_log_count =
+static base::LazyInstance<base::AtomicSequenceNumber>::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<DnsReloader,
- base::LeakyLazyInstanceTraits<DnsReloader> >
+base::LazyInstance<DnsReloader>::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<base::Lock,
- base::LeakyLazyInstanceTraits<base::Lock> >
+static base::LazyInstance<base::Lock>::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<std::multiset<int>,
- base::LeakyLazyInstanceTraits<std::multiset<int> > >
+static base::LazyInstance<std::multiset<int> >::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<TestRootCerts,
- base::LeakyLazyInstanceTraits<TestRootCerts> >
+base::LazyInstance<TestRootCerts>::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<X509CertificateCache,
- base::LeakyLazyInstanceTraits<X509CertificateCache> >
+base::LazyInstance<X509CertificateCache>::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<OCSPIOLoop, base::LeakyLazyInstanceTraits<OCSPIOLoop> >
+base::LazyInstance<OCSPIOLoop>::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<struct __CFSet>,
- base::LeakyLazyInstanceTraits<base::ThreadLocalPointer<struct __CFSet> > >
- thread_pdf_docs = LAZY_INSTANCE_INITIALIZER;
+base::LazyInstance<base::ThreadLocalPointer<struct __CFSet> >::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<GLContext>,
- base::LeakyLazyInstanceTraits<base::ThreadLocalPointer<GLContext> > >
- current_context_ = LAZY_INSTANCE_INITIALIZER;
+base::LazyInstance<base::ThreadLocalPointer<GLContext> >::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<GLSurface>,
- base::LeakyLazyInstanceTraits<base::ThreadLocalPointer<GLSurface> > >
- current_surface_ = LAZY_INSTANCE_INITIALIZER;
+base::LazyInstance<base::ThreadLocalPointer<GLSurface> >::Leaky
+ current_surface_ = LAZY_INSTANCE_INITIALIZER;
} // namespace
// static