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 | 10 |
11 namespace tracing { | 11 namespace tracing { |
12 | 12 |
13 TracingApp::TracingApp() : collector_binding_(this), tracing_active_(false) { | 13 TracingApp::TracingApp() : tracing_active_(false) {} |
14 } | |
15 | 14 |
16 TracingApp::~TracingApp() { | 15 TracingApp::~TracingApp() {} |
17 } | |
18 | 16 |
19 bool TracingApp::ConfigureIncomingConnection( | 17 bool TracingApp::ConfigureIncomingConnection( |
20 mojo::ApplicationConnection* connection) { | 18 mojo::ApplicationConnection* connection) { |
21 connection->AddService<TraceCollector>(this); | 19 connection->AddService<TraceCollector>(this); |
22 | 20 |
23 // If someone connects to us they may want to use the TraceCollector | 21 // If someone connects to us they may want to use the TraceCollector |
24 // interface and/or they may want to expose themselves to be traced. Attempt | 22 // interface and/or they may want to expose themselves to be traced. Attempt |
25 // to connect to the TraceProvider interface to see if the application | 23 // to connect to the TraceProvider interface to see if the application |
26 // connecting to us wants to be traced. They can refuse the connection or | 24 // connecting to us wants to be traced. They can refuse the connection or |
27 // close the pipe if not. | 25 // close the pipe if not. |
28 TraceProviderPtr provider_ptr; | 26 TraceProviderPtr provider_ptr; |
29 connection->ConnectToService(&provider_ptr); | 27 connection->ConnectToService(&provider_ptr); |
30 if (tracing_active_) { | 28 if (tracing_active_) { |
31 TraceRecorderPtr recorder_ptr; | 29 TraceRecorderPtr recorder_ptr; |
32 recorder_impls_.push_back( | 30 recorder_impls_.push_back( |
33 new TraceRecorderImpl(GetProxy(&recorder_ptr), sink_.get())); | 31 new TraceRecorderImpl(GetProxy(&recorder_ptr), sink_.get())); |
34 provider_ptr->StartTracing(tracing_categories_, recorder_ptr.Pass()); | 32 provider_ptr->StartTracing(tracing_categories_, recorder_ptr.Pass()); |
35 } | 33 } |
36 provider_ptrs_.AddInterfacePtr(provider_ptr.Pass()); | 34 provider_ptrs_.AddInterfacePtr(provider_ptr.Pass()); |
37 return true; | 35 return true; |
38 } | 36 } |
39 | 37 |
40 // mojo::InterfaceFactory<TraceCollector> implementation. | 38 // mojo::InterfaceFactory<TraceCollector> implementation. |
41 void TracingApp::Create(mojo::ApplicationConnection* connection, | 39 void TracingApp::Create(mojo::ApplicationConnection* connection, |
42 mojo::InterfaceRequest<TraceCollector> request) { | 40 mojo::InterfaceRequest<TraceCollector> request) { |
43 collector_binding_.Bind(request.Pass()); | 41 collector_bindings_.AddBinding(this, request.Pass()); |
44 } | 42 } |
45 | 43 |
46 // tracing::TraceCollector implementation. | 44 // tracing::TraceCollector implementation. |
47 void TracingApp::Start(mojo::ScopedDataPipeProducerHandle stream, | 45 void TracingApp::Start(mojo::ScopedDataPipeProducerHandle stream, |
48 const mojo::String& categories) { | 46 const mojo::String& categories) { |
49 tracing_categories_ = categories; | 47 tracing_categories_ = categories; |
50 sink_.reset(new TraceDataSink(stream.Pass())); | 48 sink_.reset(new TraceDataSink(stream.Pass())); |
51 provider_ptrs_.ForAllPtrs([categories, this](TraceProvider* controller) { | 49 provider_ptrs_.ForAllPtrs([categories, this](TraceProvider* controller) { |
52 TraceRecorderPtr ptr; | 50 TraceRecorderPtr ptr; |
53 recorder_impls_.push_back( | 51 recorder_impls_.push_back( |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 } | 119 } |
122 AllDataCollected(); | 120 AllDataCollected(); |
123 } | 121 } |
124 | 122 |
125 void TracingApp::AllDataCollected() { | 123 void TracingApp::AllDataCollected() { |
126 recorder_impls_.clear(); | 124 recorder_impls_.clear(); |
127 sink_.reset(); | 125 sink_.reset(); |
128 } | 126 } |
129 | 127 |
130 } // namespace tracing | 128 } // namespace tracing |
OLD | NEW |