| 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/services/tracing/tracing_app.h" | 5 #include "mojo/services/tracing/tracing_app.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
| 15 #include "mojo/shell/public/cpp/application_connection.h" | |
| 16 | 15 |
| 17 namespace tracing { | 16 namespace tracing { |
| 18 | 17 |
| 19 TracingApp::TracingApp() : collector_binding_(this), tracing_active_(false) { | 18 TracingApp::TracingApp() : collector_binding_(this), tracing_active_(false) { |
| 20 } | 19 } |
| 21 | 20 |
| 22 TracingApp::~TracingApp() { | 21 TracingApp::~TracingApp() { |
| 23 } | 22 } |
| 24 | 23 |
| 25 bool TracingApp::AcceptConnection( | 24 bool TracingApp::AcceptConnection(mojo::Connection* connection) { |
| 26 mojo::ApplicationConnection* connection) { | |
| 27 connection->AddService<TraceCollector>(this); | 25 connection->AddService<TraceCollector>(this); |
| 28 connection->AddService<StartupPerformanceDataCollector>(this); | 26 connection->AddService<StartupPerformanceDataCollector>(this); |
| 29 | 27 |
| 30 // If someone connects to us they may want to use the TraceCollector | 28 // If someone connects to us they may want to use the TraceCollector |
| 31 // interface and/or they may want to expose themselves to be traced. Attempt | 29 // interface and/or they may want to expose themselves to be traced. Attempt |
| 32 // to connect to the TraceProvider interface to see if the application | 30 // to connect to the TraceProvider interface to see if the application |
| 33 // connecting to us wants to be traced. They can refuse the connection or | 31 // connecting to us wants to be traced. They can refuse the connection or |
| 34 // close the pipe if not. | 32 // close the pipe if not. |
| 35 TraceProviderPtr provider_ptr; | 33 TraceProviderPtr provider_ptr; |
| 36 connection->ConnectToService(&provider_ptr); | 34 connection->ConnectToService(&provider_ptr); |
| 37 if (tracing_active_) { | 35 if (tracing_active_) { |
| 38 TraceRecorderPtr recorder_ptr; | 36 TraceRecorderPtr recorder_ptr; |
| 39 recorder_impls_.push_back( | 37 recorder_impls_.push_back( |
| 40 new TraceRecorderImpl(GetProxy(&recorder_ptr), sink_.get())); | 38 new TraceRecorderImpl(GetProxy(&recorder_ptr), sink_.get())); |
| 41 provider_ptr->StartTracing(tracing_categories_, std::move(recorder_ptr)); | 39 provider_ptr->StartTracing(tracing_categories_, std::move(recorder_ptr)); |
| 42 } | 40 } |
| 43 provider_ptrs_.AddInterfacePtr(std::move(provider_ptr)); | 41 provider_ptrs_.AddInterfacePtr(std::move(provider_ptr)); |
| 44 return true; | 42 return true; |
| 45 } | 43 } |
| 46 | 44 |
| 47 void TracingApp::Create(mojo::ApplicationConnection* connection, | 45 void TracingApp::Create(mojo::Connection* connection, |
| 48 mojo::InterfaceRequest<TraceCollector> request) { | 46 mojo::InterfaceRequest<TraceCollector> request) { |
| 49 collector_binding_.Bind(std::move(request)); | 47 collector_binding_.Bind(std::move(request)); |
| 50 } | 48 } |
| 51 | 49 |
| 52 void TracingApp::Create( | 50 void TracingApp::Create( |
| 53 mojo::ApplicationConnection* connection, | 51 mojo::Connection* connection, |
| 54 mojo::InterfaceRequest<StartupPerformanceDataCollector> request) { | 52 mojo::InterfaceRequest<StartupPerformanceDataCollector> request) { |
| 55 startup_performance_data_collector_bindings_.AddBinding(this, | 53 startup_performance_data_collector_bindings_.AddBinding(this, |
| 56 std::move(request)); | 54 std::move(request)); |
| 57 } | 55 } |
| 58 | 56 |
| 59 void TracingApp::Start(mojo::ScopedDataPipeProducerHandle stream, | 57 void TracingApp::Start(mojo::ScopedDataPipeProducerHandle stream, |
| 60 const mojo::String& categories) { | 58 const mojo::String& categories) { |
| 61 tracing_categories_ = categories; | 59 tracing_categories_ = categories; |
| 62 sink_.reset(new TraceDataSink(std::move(stream))); | 60 sink_.reset(new TraceDataSink(std::move(stream))); |
| 63 provider_ptrs_.ForAllPtrs([categories, this](TraceProvider* controller) { | 61 provider_ptrs_.ForAllPtrs([categories, this](TraceProvider* controller) { |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 const GetStartupPerformanceTimesCallback& callback) { | 169 const GetStartupPerformanceTimesCallback& callback) { |
| 172 callback.Run(startup_performance_times_.Clone()); | 170 callback.Run(startup_performance_times_.Clone()); |
| 173 } | 171 } |
| 174 | 172 |
| 175 void TracingApp::AllDataCollected() { | 173 void TracingApp::AllDataCollected() { |
| 176 recorder_impls_.clear(); | 174 recorder_impls_.clear(); |
| 177 sink_.reset(); | 175 sink_.reset(); |
| 178 } | 176 } |
| 179 | 177 |
| 180 } // namespace tracing | 178 } // namespace tracing |
| OLD | NEW |