Chromium Code Reviews| Index: mojo/common/trace_provider_impl.cc |
| diff --git a/mojo/common/trace_provider_impl.cc b/mojo/common/trace_provider_impl.cc |
| index 8ffc867a46f38192022891ad5fe9adb797c9fb06..4ebb1f0e60627abcbe1bb4619c51cd2ce427b597 100644 |
| --- a/mojo/common/trace_provider_impl.cc |
| +++ b/mojo/common/trace_provider_impl.cc |
| @@ -12,19 +12,16 @@ |
| namespace mojo { |
| -TraceProviderImpl::TraceProviderImpl( |
| - InterfaceRequest<tracing::TraceProvider> request) |
| - : tracing_already_started_(false), binding_(this, request.Pass()) { |
| -} |
| +TraceProviderImpl::TraceProviderImpl() : tracing_forced_(false) {} |
| -TraceProviderImpl::~TraceProviderImpl() { |
| -} |
| +TraceProviderImpl::~TraceProviderImpl() {} |
| void TraceProviderImpl::StartTracing(const String& categories, |
| tracing::TraceRecorderPtr collector) { |
| DCHECK(!recorder_.get()); |
| recorder_ = collector.Pass(); |
| - if (!tracing_already_started_) { |
| + tracing_forced_ = false; |
| + if (!base::trace_event::TraceLog::GetInstance()->IsEnabled()) { |
| std::string categories_str = categories.To<std::string>(); |
| base::trace_event::TraceLog::GetInstance()->SetEnabled( |
| base::trace_event::TraceConfig(categories_str, |
| @@ -41,6 +38,37 @@ void TraceProviderImpl::StopTracing() { |
| base::Bind(&TraceProviderImpl::SendChunk, base::Unretained(this))); |
| } |
| +void TraceProviderImpl::EnableTracingNow() { |
| + base::trace_event::TraceLog::GetInstance()->SetEnabled( |
| + base::trace_event::TraceConfig("*", base::trace_event::RECORD_UNTIL_FULL), |
| + base::trace_event::TraceLog::RECORDING_MODE); |
| + tracing_forced_ = true; |
| + base::MessageLoop::current()->PostTask( |
| + FROM_HERE, |
| + base::Bind(&TraceProviderImpl::DelayedStop, base::Unretained(this))); |
|
qsr
2015/09/11 14:44:04
What is the lifecycle of this object. Are you guar
etiennej
2015/09/11 15:07:32
Fixed.
|
| +} |
| + |
| +void TraceProviderImpl::DelayedStop() { |
| + // We use this indirection to account for cases where the Initialize app |
| + // method (within which TraceProviderImpl is created) takes more than one |
| + // second to finish; thus we start the countdown only when the current thread |
| + // is unblocked. |
| + base::MessageLoop::current()->PostDelayedTask( |
| + FROM_HERE, |
| + base::Bind(&TraceProviderImpl::StopIfForced, base::Unretained(this)), |
| + base::TimeDelta::FromSeconds(1)); |
| +} |
| + |
| +void TraceProviderImpl::StopIfForced() { |
| + if (!tracing_forced_) { |
| + return; |
| + } |
| + base::trace_event::TraceLog::GetInstance()->SetDisabled(); |
| + base::trace_event::TraceLog::GetInstance()->Flush( |
| + base::Callback<void(const scoped_refptr<base::RefCountedString>&, |
| + bool)>()); |
| +} |
| + |
| void TraceProviderImpl::SendChunk( |
| const scoped_refptr<base::RefCountedString>& events_str, |
| bool has_more_events) { |