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

Unified Diff: gin/v8_platform.cc

Issue 2349563002: [gin] Plumb TraceLogStateObserver into v8. (Closed)
Patch Set: fix build 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 2d49a12900b02f8901c0106551993411bf3ff561..f9d2d6acc3115673ac131143bf82709b6e4a92b9 100644
--- a/gin/v8_platform.cc
+++ b/gin/v8_platform.cc
@@ -127,4 +127,66 @@ void V8Platform::UpdateTraceEventDuration(const uint8_t* category_enabled_flag,
traceEventHandle);
}
+namespace {
+
+class EnabledStateObserverImpl final
+ : public base::trace_event::TraceLog::EnabledStateObserver {
+ public:
+ EnabledStateObserverImpl() = default;
+
+ 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_;
+
+ DISALLOW_COPY_AND_ASSIGN(EnabledStateObserverImpl);
+};
+
+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