From 625332e06437018bf696dce93a4b2bd2c5e0b118 Mon Sep 17 00:00:00 2001 From: "satish@chromium.org" Date: Tue, 14 Dec 2010 07:48:49 +0000 Subject: Make members of Singleton private and only visible to the singleton type. This enforces that the Singleton 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 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 --- remoting/base/tracer.cc | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'remoting') diff --git a/remoting/base/tracer.cc b/remoting/base/tracer.cc index 3245887..3cef3a0 100644 --- a/remoting/base/tracer.cc +++ b/remoting/base/tracer.cc @@ -8,6 +8,7 @@ #include "base/basictypes.h" #include "base/condition_variable.h" +#include "base/lazy_instance.h" #include "base/message_loop.h" #include "base/rand_util.h" #include "base/ref_counted.h" @@ -88,7 +89,7 @@ class OutputLogger { } private: - friend struct DefaultSingletonTraits; + friend struct base::DefaultLazyInstanceTraits; ~OutputLogger() { { @@ -108,6 +109,11 @@ class OutputLogger { std::list buffers_; }; +static base::LazyInstance g_output_logger( + base::LINKER_INITIALIZED); +static base::LazyInstance > + g_thread_local_trace_context(base::LINKER_INITIALIZED); + } // namespace Tracer::Tracer(const std::string& name, double sample_percent) { @@ -136,7 +142,7 @@ Tracer::~Tracer() { AutoLock l(lock_); if (buffer_.get()) { - Singleton::get()->OutputTrace(buffer_.release()); + g_output_logger.Get().OutputTrace(buffer_.release()); } } @@ -158,11 +164,11 @@ void TraceContext::PopTracer() { // static TraceContext* TraceContext::Get() { TraceContext* context = - Singleton >::get()->Get(); + g_thread_local_trace_context.Get().Get(); if (context == NULL) { context = new TraceContext(); context->PushTracerInternal(new Tracer("default", 0.0)); - Singleton >::get()->Set(context); + g_thread_local_trace_context.Get().Set(context); } return context; } -- cgit v1.1