Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(586)

Unified Diff: base/trace_event/blame_context.cc

Issue 1956333002: Change the base class of BlameContext into AsyncEnabledStateObserver (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ThreadSafeObserver
Patch Set: Add note on thread safety for Enter() and Leave() Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/trace_event/blame_context.h ('k') | base/trace_event/blame_context_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/trace_event/blame_context.cc
diff --git a/base/trace_event/blame_context.cc b/base/trace_event/blame_context.cc
index 27d2d2eb7509c2b57f161aa5263c2787cc337a3c..ae5c6790d6e12a1bc6cfa8a8f56a606070bc015c 100644
--- a/base/trace_event/blame_context.cc
+++ b/base/trace_event/blame_context.cc
@@ -24,17 +24,19 @@ BlameContext::BlameContext(const char* category,
id_(id),
parent_scope_(parent_context ? parent_context->scope() : nullptr),
parent_id_(parent_context ? parent_context->id() : 0),
- category_group_enabled_(nullptr) {
+ category_group_enabled_(nullptr),
+ weak_factory_(this) {
DCHECK(!parent_context || !std::strcmp(name_, parent_context->name()))
<< "Parent blame context must have the same name";
}
BlameContext::~BlameContext() {
+ DCHECK(thread_checker_.CalledOnValidThread());
DCHECK(WasInitialized());
TRACE_EVENT_API_ADD_TRACE_EVENT(
TRACE_EVENT_PHASE_DELETE_OBJECT, category_group_enabled_, type_, scope_,
id_, 0, nullptr, nullptr, nullptr, nullptr, TRACE_EVENT_FLAG_HAS_ID);
- trace_event::TraceLog::GetInstance()->RemoveEnabledStateObserver(this);
+ trace_event::TraceLog::GetInstance()->RemoveAsyncEnabledStateObserver(this);
}
void BlameContext::Enter() {
@@ -54,6 +56,7 @@ void BlameContext::Leave() {
}
void BlameContext::TakeSnapshot() {
+ DCHECK(thread_checker_.CalledOnValidThread());
DCHECK(WasInitialized());
if (!*category_group_enabled_)
return;
@@ -89,12 +92,14 @@ void BlameContext::AsValueInto(trace_event::TracedValue* state) {
}
void BlameContext::Initialize() {
+ DCHECK(thread_checker_.CalledOnValidThread());
category_group_enabled_ =
TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(category_);
TRACE_EVENT_API_ADD_TRACE_EVENT(
TRACE_EVENT_PHASE_CREATE_OBJECT, category_group_enabled_, type_, scope_,
id_, 0, nullptr, nullptr, nullptr, nullptr, TRACE_EVENT_FLAG_HAS_ID);
- trace_event::TraceLog::GetInstance()->AddEnabledStateObserver(this);
+ trace_event::TraceLog::GetInstance()->AddAsyncEnabledStateObserver(
+ weak_factory_.GetWeakPtr());
TakeSnapshot();
}
« no previous file with comments | « base/trace_event/blame_context.h ('k') | base/trace_event/blame_context_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698