Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "gin/public/v8_platform.h" | 5 #include "gin/public/v8_platform.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/sys_info.h" | 9 #include "base/sys_info.h" |
| 10 #include "base/threading/worker_pool.h" | 10 #include "base/threading/worker_pool.h" |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 118 | 118 |
| 119 void V8Platform::UpdateTraceEventDuration(const uint8_t* category_enabled_flag, | 119 void V8Platform::UpdateTraceEventDuration(const uint8_t* category_enabled_flag, |
| 120 const char* name, | 120 const char* name, |
| 121 uint64_t handle) { | 121 uint64_t handle) { |
| 122 base::trace_event::TraceEventHandle traceEventHandle; | 122 base::trace_event::TraceEventHandle traceEventHandle; |
| 123 memcpy(&traceEventHandle, &handle, sizeof(handle)); | 123 memcpy(&traceEventHandle, &handle, sizeof(handle)); |
| 124 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(category_enabled_flag, name, | 124 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(category_enabled_flag, name, |
| 125 traceEventHandle); | 125 traceEventHandle); |
| 126 } | 126 } |
| 127 | 127 |
| 128 namespace { | |
| 129 | |
| 130 class EnabledStateObserverImpl | |
| 131 : public base::trace_event::TraceLog::EnabledStateObserver { | |
| 132 public: | |
| 133 void OnTraceLogEnabled() final { | |
| 134 base::AutoLock lock(mutex_); | |
| 135 for (auto o : observers_) { | |
| 136 o->OnTraceEnabled(); | |
| 137 } | |
| 138 } | |
| 139 | |
| 140 void OnTraceLogDisabled() final { | |
| 141 base::AutoLock lock(mutex_); | |
| 142 for (auto o : observers_) { | |
| 143 o->OnTraceDisabled(); | |
| 144 } | |
| 145 } | |
| 146 | |
| 147 void AddObserver(v8::Platform::TraceStateObserver* observer) { | |
| 148 base::AutoLock lock(mutex_); | |
| 149 DCHECK(!observers_.count(observer)); | |
| 150 observers_.insert(observer); | |
| 151 if (observers_.size() == 1) { | |
| 152 base::trace_event::TraceLog::GetInstance()->AddEnabledStateObserver(this); | |
| 153 } | |
| 154 } | |
| 155 | |
| 156 void RemoveObserver(v8::Platform::TraceStateObserver* observer) { | |
| 157 base::AutoLock lock(mutex_); | |
| 158 DCHECK(observers_.count(observer) == 1); | |
| 159 observers_.erase(observer); | |
| 160 if (observers_.empty()) { | |
| 161 base::trace_event::TraceLog::GetInstance()->RemoveEnabledStateObserver( | |
| 162 this); | |
| 163 } | |
| 164 } | |
| 165 | |
| 166 private: | |
| 167 base::Lock mutex_; | |
| 168 std::unordered_set<v8::Platform::TraceStateObserver*> observers_; | |
| 169 }; | |
|
jochen (gone - plz use gerrit)
2016/09/19 14:24:18
disallow copy/ assign
alph
2016/09/20 21:19:45
Done.
| |
| 170 | |
| 171 base::LazyInstance<EnabledStateObserverImpl>::Leaky g_trace_state_dispatcher = | |
| 172 LAZY_INSTANCE_INITIALIZER; | |
| 173 | |
| 174 } // namespace | |
| 175 | |
| 176 void V8Platform::AddTraceStateObserver( | |
| 177 v8::Platform::TraceStateObserver* observer) { | |
| 178 g_trace_state_dispatcher.Get().AddObserver(observer); | |
| 179 } | |
| 180 | |
| 181 void V8Platform::RemoveTraceStateObserver( | |
| 182 v8::Platform::TraceStateObserver* observer) { | |
| 183 g_trace_state_dispatcher.Get().RemoveObserver(observer); | |
| 184 } | |
| 185 | |
| 128 } // namespace gin | 186 } // namespace gin |
| OLD | NEW |