| 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 "services/tracing/tracing_app.h" | 5 #include "services/tracing/tracing_app.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "mojo/public/cpp/system/wait.h" | 10 #include "mojo/public/cpp/system/wait.h" |
| 11 | 11 |
| 12 namespace tracing { | 12 namespace tracing { |
| 13 | 13 |
| 14 TracingApp::TracingApp() : collector_binding_(this), tracing_active_(false) {} | 14 TracingApp::TracingApp() : collector_binding_(this), tracing_active_(false) {} |
| 15 | 15 |
| 16 TracingApp::~TracingApp() {} | 16 TracingApp::~TracingApp() {} |
| 17 | 17 |
| 18 bool TracingApp::ConfigureIncomingConnection( | 18 bool TracingApp::ConfigureIncomingConnection( |
| 19 mojo::ApplicationConnection* connection) { | 19 mojo::ApplicationConnection* connection) { |
| 20 connection->AddService<TraceCollector>(this); | 20 connection->GetServiceProviderImpl().AddService<TraceCollector>( |
| 21 [this](const mojo::ConnectionContext& connection_context, |
| 22 mojo::InterfaceRequest<TraceCollector> trace_collector_request) { |
| 23 if (collector_binding_.is_bound()) { |
| 24 LOG(ERROR) << "Another application is already connected to tracing."; |
| 25 return; |
| 26 } |
| 27 |
| 28 collector_binding_.Bind(trace_collector_request.Pass()); |
| 29 }); |
| 30 connection->GetServiceProviderImpl().AddService<TraceProviderRegistry>( |
| 31 [this](const mojo::ConnectionContext& connection_context, |
| 32 mojo::InterfaceRequest<TraceProviderRegistry> |
| 33 trace_provider_registry_request) { |
| 34 provider_registry_bindings_.AddBinding( |
| 35 this, trace_provider_registry_request.Pass()); |
| 36 }); |
| 21 return true; | 37 return true; |
| 22 } | 38 } |
| 23 | 39 |
| 24 void TracingApp::Create(const mojo::ConnectionContext& connection_context, | |
| 25 mojo::InterfaceRequest<TraceCollector> request) { | |
| 26 if (collector_binding_.is_bound()) { | |
| 27 LOG(ERROR) << "Another application is already connected to tracing."; | |
| 28 return; | |
| 29 } | |
| 30 | |
| 31 collector_binding_.Bind(request.Pass()); | |
| 32 } | |
| 33 | |
| 34 void TracingApp::Create(const mojo::ConnectionContext& connection_context, | |
| 35 mojo::InterfaceRequest<TraceProviderRegistry> request) { | |
| 36 provider_registry_bindings_.AddBinding(this, request.Pass()); | |
| 37 } | |
| 38 | |
| 39 void TracingApp::Start(mojo::ScopedDataPipeProducerHandle stream, | 40 void TracingApp::Start(mojo::ScopedDataPipeProducerHandle stream, |
| 40 const mojo::String& categories) { | 41 const mojo::String& categories) { |
| 41 tracing_categories_ = categories; | 42 tracing_categories_ = categories; |
| 42 sink_.reset(new TraceDataSink(stream.Pass())); | 43 sink_.reset(new TraceDataSink(stream.Pass())); |
| 43 provider_ptrs_.ForAllPtrs([categories, this](TraceProvider* controller) { | 44 provider_ptrs_.ForAllPtrs([categories, this](TraceProvider* controller) { |
| 44 TraceRecorderPtr ptr; | 45 TraceRecorderPtr ptr; |
| 45 recorder_impls_.push_back( | 46 recorder_impls_.push_back( |
| 46 new TraceRecorderImpl(GetProxy(&ptr), sink_.get())); | 47 new TraceRecorderImpl(GetProxy(&ptr), sink_.get())); |
| 47 controller->StartTracing(categories, ptr.Pass()); | 48 controller->StartTracing(categories, ptr.Pass()); |
| 48 }); | 49 }); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 } | 126 } |
| 126 provider_ptrs_.AddInterfacePtr(provider_ptr.Pass()); | 127 provider_ptrs_.AddInterfacePtr(provider_ptr.Pass()); |
| 127 } | 128 } |
| 128 | 129 |
| 129 void TracingApp::AllDataCollected() { | 130 void TracingApp::AllDataCollected() { |
| 130 recorder_impls_.clear(); | 131 recorder_impls_.clear(); |
| 131 sink_.reset(); | 132 sink_.reset(); |
| 132 } | 133 } |
| 133 | 134 |
| 134 } // namespace tracing | 135 } // namespace tracing |
| OLD | NEW |