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

Unified Diff: gin/v8_platform.cc

Issue 2349563002: [gin] Plumb TraceLogStateObserver into v8. (Closed)
Patch Set: Created 4 years, 3 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 | « gin/public/v8_platform.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gin/v8_platform.cc
diff --git a/gin/v8_platform.cc b/gin/v8_platform.cc
index ece038cb0c20d85affddb07c0bdbee458d8df564..63a9135b2e79c5c064d6589f538b84870d2a30a1 100644
--- a/gin/v8_platform.cc
+++ b/gin/v8_platform.cc
@@ -125,4 +125,62 @@ void V8Platform::UpdateTraceEventDuration(const uint8_t* category_enabled_flag,
traceEventHandle);
}
+namespace {
+
+class EnabledStateObserverImpl
+ : public base::trace_event::TraceLog::EnabledStateObserver {
+ public:
+ void OnTraceLogEnabled() final {
+ base::AutoLock lock(mutex_);
+ for (auto o : observers_) {
+ o->OnTraceEnabled();
+ }
+ }
+
+ void OnTraceLogDisabled() final {
+ base::AutoLock lock(mutex_);
+ for (auto o : observers_) {
+ o->OnTraceDisabled();
+ }
+ }
+
+ void AddObserver(v8::Platform::TraceStateObserver* observer) {
+ base::AutoLock lock(mutex_);
+ DCHECK(!observers_.count(observer));
+ observers_.insert(observer);
+ if (observers_.size() == 1) {
+ base::trace_event::TraceLog::GetInstance()->AddEnabledStateObserver(this);
+ }
+ }
+
+ void RemoveObserver(v8::Platform::TraceStateObserver* observer) {
+ base::AutoLock lock(mutex_);
+ DCHECK(observers_.count(observer) == 1);
+ observers_.erase(observer);
+ if (observers_.empty()) {
+ base::trace_event::TraceLog::GetInstance()->RemoveEnabledStateObserver(
+ this);
+ }
+ }
+
+ private:
+ base::Lock mutex_;
+ std::unordered_set<v8::Platform::TraceStateObserver*> observers_;
+};
jochen (gone - plz use gerrit) 2016/09/19 14:24:18 disallow copy/ assign
alph 2016/09/20 21:19:45 Done.
+
+base::LazyInstance<EnabledStateObserverImpl>::Leaky g_trace_state_dispatcher =
+ LAZY_INSTANCE_INITIALIZER;
+
+} // namespace
+
+void V8Platform::AddTraceStateObserver(
+ v8::Platform::TraceStateObserver* observer) {
+ g_trace_state_dispatcher.Get().AddObserver(observer);
+}
+
+void V8Platform::RemoveTraceStateObserver(
+ v8::Platform::TraceStateObserver* observer) {
+ g_trace_state_dispatcher.Get().RemoveObserver(observer);
+}
+
} // namespace gin
« no previous file with comments | « gin/public/v8_platform.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698