| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "mojo/common/trace_controller_impl.h" | 5 #include "mojo/common/trace_provider_impl.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/trace_event/trace_config.h" | 8 #include "base/trace_event/trace_config.h" |
| 9 #include "base/trace_event/trace_event.h" | 9 #include "base/trace_event/trace_event.h" |
| 10 #include "mojo/public/cpp/application/application_connection.h" | 10 #include "mojo/public/cpp/application/application_connection.h" |
| 11 #include "mojo/public/cpp/application/application_impl.h" | 11 #include "mojo/public/cpp/application/application_impl.h" |
| 12 | 12 |
| 13 namespace mojo { | 13 namespace mojo { |
| 14 | 14 |
| 15 TraceControllerImpl::TraceControllerImpl( | 15 TraceProviderImpl::TraceProviderImpl( |
| 16 InterfaceRequest<tracing::TraceController> request) | 16 InterfaceRequest<tracing::TraceProvider> request) |
| 17 : tracing_already_started_(false), binding_(this, request.Pass()) { | 17 : tracing_already_started_(false), binding_(this, request.Pass()) { |
| 18 } | 18 } |
| 19 | 19 |
| 20 TraceControllerImpl::~TraceControllerImpl() { | 20 TraceProviderImpl::~TraceProviderImpl() { |
| 21 } | 21 } |
| 22 | 22 |
| 23 void TraceControllerImpl::StartTracing( | 23 void TraceProviderImpl::StartTracing(const String& categories, |
| 24 const String& categories, | 24 tracing::TraceRecorderPtr collector) { |
| 25 tracing::TraceDataCollectorPtr collector) { | 25 DCHECK(!recorder_.get()); |
| 26 DCHECK(!collector_.get()); | 26 recorder_ = collector.Pass(); |
| 27 collector_ = collector.Pass(); | |
| 28 if (!tracing_already_started_) { | 27 if (!tracing_already_started_) { |
| 29 std::string categories_str = categories.To<std::string>(); | 28 std::string categories_str = categories.To<std::string>(); |
| 30 base::trace_event::TraceLog::GetInstance()->SetEnabled( | 29 base::trace_event::TraceLog::GetInstance()->SetEnabled( |
| 31 base::trace_event::TraceConfig(categories_str, | 30 base::trace_event::TraceConfig(categories_str, |
| 32 base::trace_event::RECORD_UNTIL_FULL), | 31 base::trace_event::RECORD_UNTIL_FULL), |
| 33 base::trace_event::TraceLog::RECORDING_MODE); | 32 base::trace_event::TraceLog::RECORDING_MODE); |
| 34 } | 33 } |
| 35 } | 34 } |
| 36 | 35 |
| 37 void TraceControllerImpl::StopTracing() { | 36 void TraceProviderImpl::StopTracing() { |
| 38 DCHECK(collector_); | 37 DCHECK(recorder_); |
| 39 base::trace_event::TraceLog::GetInstance()->SetDisabled(); | 38 base::trace_event::TraceLog::GetInstance()->SetDisabled(); |
| 40 | 39 |
| 41 base::trace_event::TraceLog::GetInstance()->Flush( | 40 base::trace_event::TraceLog::GetInstance()->Flush( |
| 42 base::Bind(&TraceControllerImpl::SendChunk, base::Unretained(this))); | 41 base::Bind(&TraceProviderImpl::SendChunk, base::Unretained(this))); |
| 43 } | 42 } |
| 44 | 43 |
| 45 void TraceControllerImpl::SendChunk( | 44 void TraceProviderImpl::SendChunk( |
| 46 const scoped_refptr<base::RefCountedString>& events_str, | 45 const scoped_refptr<base::RefCountedString>& events_str, |
| 47 bool has_more_events) { | 46 bool has_more_events) { |
| 48 DCHECK(collector_); | 47 DCHECK(recorder_); |
| 49 collector_->DataCollected(mojo::String(events_str->data())); | 48 recorder_->Record(mojo::String(events_str->data())); |
| 50 if (!has_more_events) { | 49 if (!has_more_events) { |
| 51 collector_.reset(); | 50 recorder_.reset(); |
| 52 } | 51 } |
| 53 } | 52 } |
| 54 | 53 |
| 55 } // namespace mojo | 54 } // namespace mojo |
| OLD | NEW |