OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "mojo/common/trace_controller_impl.h" |
| 6 |
| 7 #include "base/debug/trace_event.h" |
| 8 #include "mojo/public/cpp/application/application_connection.h" |
| 9 #include "mojo/public/cpp/application/application_impl.h" |
| 10 |
| 11 namespace mojo { |
| 12 |
| 13 TraceControllerImpl::TraceControllerImpl() |
| 14 : binding_(this), delete_on_error_(false) { |
| 15 } |
| 16 |
| 17 TraceControllerImpl::~TraceControllerImpl() { |
| 18 } |
| 19 |
| 20 void TraceControllerImpl::Bind( |
| 21 InterfaceRequest<tracing::TraceController> request) { |
| 22 binding_.Bind(request.Pass()); |
| 23 delete_on_error_ = true; |
| 24 } |
| 25 |
| 26 void TraceControllerImpl::Bind(ScopedMessagePipeHandle client_handle) { |
| 27 binding_.Bind(client_handle.Pass()); |
| 28 } |
| 29 |
| 30 void TraceControllerImpl::StartTracing( |
| 31 const String& categories, |
| 32 tracing::TraceDataCollectorPtr collector) { |
| 33 DCHECK(!collector_.get()); |
| 34 collector_ = collector.Pass(); |
| 35 std::string categories_str = categories.To<std::string>(); |
| 36 base::debug::TraceLog::GetInstance()->SetEnabled( |
| 37 base::debug::CategoryFilter(categories_str), |
| 38 base::debug::TraceLog::RECORDING_MODE, |
| 39 base::debug::TraceOptions(base::debug::RECORD_UNTIL_FULL)); |
| 40 } |
| 41 |
| 42 void TraceControllerImpl::StopTracing() { |
| 43 base::debug::TraceLog::GetInstance()->SetDisabled(); |
| 44 |
| 45 base::debug::TraceLog::GetInstance()->Flush( |
| 46 base::Bind(&TraceControllerImpl::SendChunk, base::Unretained(this))); |
| 47 } |
| 48 |
| 49 void TraceControllerImpl::SendChunk( |
| 50 const scoped_refptr<base::RefCountedString>& events_str, |
| 51 bool has_more_events) { |
| 52 collector_->DataCollected(mojo::String(events_str->data())); |
| 53 if (!has_more_events) { |
| 54 collector_.reset(); |
| 55 } |
| 56 } |
| 57 |
| 58 void TraceControllerImpl::OnConnectionError() { |
| 59 if (delete_on_error_) |
| 60 delete this; |
| 61 } |
| 62 |
| 63 } // namespace mojo |
OLD | NEW |