summaryrefslogtreecommitdiffstats
path: root/base/debug
diff options
context:
space:
mode:
authorsatish@chromium.org <satish@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-04 23:00:10 +0000
committersatish@chromium.org <satish@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-04 23:00:10 +0000
commit864b558217c75dbdebea9db3568056292d4cd274 (patch)
tree06bd9f240065ed47fab9ff415ae4cd49f21facf1 /base/debug
parent8c9e61a02aad4d8baa0f75ae7ac2f2f1963fffd6 (diff)
downloadchromium_src-864b558217c75dbdebea9db3568056292d4cd274.zip
chromium_src-864b558217c75dbdebea9db3568056292d4cd274.tar.gz
chromium_src-864b558217c75dbdebea9db3568056292d4cd274.tar.bz2
This CL add a GetInstance() method to singleton classes instead of relying on the callers to use Singleton<T>.
In some cases I have used the LazyInstance<T> pattern as that was simpler. This is a small step towards making all singleton classes use the Singleton<T> pattern within their code and not expect the callers to know about it. I have selected all files under src/app and src/base which use Singleton<T> in this CL. Once this CL goes in I'll work on the rest of the files. BUG=65298 TEST=all existing tests should continue to pass. Review URL: http://codereview.chromium.org/5527004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@68300 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/debug')
-rw-r--r--base/debug/trace_event.cc14
-rw-r--r--base/debug/trace_event.h8
-rw-r--r--base/debug/trace_event_win.cc6
-rw-r--r--base/debug/trace_event_win.h2
-rw-r--r--base/debug/trace_event_win_unittest.cc4
5 files changed, 19 insertions, 15 deletions
diff --git a/base/debug/trace_event.cc b/base/debug/trace_event.cc
index 4d1d315..f50422c 100644
--- a/base/debug/trace_event.cc
+++ b/base/debug/trace_event.cc
@@ -45,15 +45,18 @@ TraceLog::~TraceLog() {
}
// static
+TraceLog* TraceLog::GetInstance() {
+ return Singleton<TraceLog, DefaultSingletonTraits<TraceLog> >::get();
+}
+
+// static
bool TraceLog::IsTracing() {
- TraceLog* trace = Singleton<TraceLog>::get();
- return trace->enabled_;
+ return TraceLog::GetInstance()->enabled_;
}
// static
bool TraceLog::StartTracing() {
- TraceLog* trace = Singleton<TraceLog>::get();
- return trace->Start();
+ return TraceLog::GetInstance()->Start();
}
bool TraceLog::Start() {
@@ -70,8 +73,7 @@ bool TraceLog::Start() {
// static
void TraceLog::StopTracing() {
- TraceLog* trace = Singleton<TraceLog>::get();
- return trace->Stop();
+ return TraceLog::GetInstance()->Stop();
}
void TraceLog::Stop() {
diff --git a/base/debug/trace_event.h b/base/debug/trace_event.h
index 49ba4bd..160bbc8 100644
--- a/base/debug/trace_event.h
+++ b/base/debug/trace_event.h
@@ -52,7 +52,7 @@
// Record that an event (of name, id) has begun. All BEGIN events should have
// corresponding END events with a matching (name, id).
#define TRACE_EVENT_BEGIN(name, id, extra) \
- Singleton<base::debug::TraceLog>::get()->Trace( \
+ base::debug::TraceLog::GetInstance()->Trace( \
name, \
base::debug::TraceLog::EVENT_BEGIN, \
reinterpret_cast<const void*>(id), \
@@ -63,7 +63,7 @@
// Record that an event (of name, id) has ended. All END events should have
// corresponding BEGIN events with a matching (name, id).
#define TRACE_EVENT_END(name, id, extra) \
- Singleton<base::debug::TraceLog>::get()->Trace( \
+ base::debug::TraceLog::GetInstance()->Trace( \
name, \
base::debug::TraceLog::EVENT_END, \
reinterpret_cast<const void*>(id), \
@@ -73,7 +73,7 @@
// Record that an event (of name, id) with no duration has happened.
#define TRACE_EVENT_INSTANT(name, id, extra) \
- Singleton<base::debug::TraceLog>::get()->Trace( \
+ base::debug::TraceLog::GetInstance()->Trace( \
name, \
base::debug::TraceLog::EVENT_INSTANT, \
reinterpret_cast<const void*>(id), \
@@ -96,6 +96,8 @@ class TraceLog {
EVENT_INSTANT
};
+ static TraceLog* GetInstance();
+
// Is tracing currently enabled.
static bool IsTracing();
// Start logging trace events.
diff --git a/base/debug/trace_event_win.cc b/base/debug/trace_event_win.cc
index 8405699..005ff62 100644
--- a/base/debug/trace_event_win.cc
+++ b/base/debug/trace_event_win.cc
@@ -31,8 +31,8 @@ TraceLog::TraceLog() : EtwTraceProvider(kChromeTraceProviderName) {
Register();
}
-TraceLog* TraceLog::Get() {
- return Singleton<TraceLog, StaticMemorySingletonTraits<TraceLog>>::get();
+TraceLog* TraceLog::GetInstance() {
+ return Singleton<TraceLog, StaticMemorySingletonTraits<TraceLog> >::get();
}
bool TraceLog::StartTracing() {
@@ -99,7 +99,7 @@ void TraceLog::Trace(const char* name,
const void* id,
const char* extra,
size_t extra_len) {
- TraceLog* provider = TraceLog::Get();
+ TraceLog* provider = TraceLog::GetInstance();
if (provider && provider->IsTracing()) {
// Compute the name & extra lengths if not supplied already.
if (name_len == -1)
diff --git a/base/debug/trace_event_win.h b/base/debug/trace_event_win.h
index dd3f512..a1c79ba 100644
--- a/base/debug/trace_event_win.h
+++ b/base/debug/trace_event_win.h
@@ -85,7 +85,7 @@ class TraceLog : public base::win::EtwTraceProvider {
// Retrieves the singleton.
// Note that this may return NULL post-AtExit processing.
- static TraceLog* Get();
+ static TraceLog* GetInstance();
// Returns true iff tracing is turned on.
bool IsTracing() {
diff --git a/base/debug/trace_event_win_unittest.cc b/base/debug/trace_event_win_unittest.cc
index 8544bc7..4c5ed45 100644
--- a/base/debug/trace_event_win_unittest.cc
+++ b/base/debug/trace_event_win_unittest.cc
@@ -106,7 +106,7 @@ class TraceEventTest: public testing::Test {
TraceLog* tracelog = NULL;
if (!is_xp) {
TraceLog::Resurrect();
- tracelog = TraceLog::Get();
+ tracelog = TraceLog::GetInstance();
ASSERT_TRUE(tracelog != NULL);
ASSERT_FALSE(tracelog->IsTracing());
}
@@ -142,7 +142,7 @@ class TraceEventTest: public testing::Test {
if (is_xp) {
TraceLog::Resurrect();
- tracelog = TraceLog::Get();
+ tracelog = TraceLog::GetInstance();
}
ASSERT_TRUE(tracelog != NULL);
EXPECT_TRUE(tracelog->IsTracing());