Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(608)

Side by Side Diff: services/tracing/tracing_app.cc

Issue 1932843002: Add TraceProviderRegistry and implementation in tracing service/application. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « services/tracing/tracing_app.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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->AddService<TraceCollector>(this);
21 21
22 // If someone connects to us they may want to use the TraceCollector 22 // If someone connects to us they may want to use the TraceCollector
23 // interface and/or they may want to expose themselves to be traced. Attempt 23 // interface and/or they may want to expose themselves to be traced. Attempt
24 // to connect to the TraceProvider interface to see if the application 24 // to connect to the TraceProvider interface to see if the application
25 // connecting to us wants to be traced. They can refuse the connection or 25 // connecting to us wants to be traced. They can refuse the connection or
26 // close the pipe if not. 26 // close the pipe if not.
27 // TODO(vtl): Remove this once we remove the "wrong way" ServiceProvider.
27 TraceProviderPtr provider_ptr; 28 TraceProviderPtr provider_ptr;
28 connection->ConnectToService(&provider_ptr); 29 connection->ConnectToService(&provider_ptr);
29 if (tracing_active_) { 30 RegisterTraceProvider(provider_ptr.PassInterfaceHandle());
30 TraceRecorderPtr recorder_ptr; 31
31 recorder_impls_.push_back(
32 new TraceRecorderImpl(GetProxy(&recorder_ptr), sink_.get()));
33 provider_ptr->StartTracing(tracing_categories_, recorder_ptr.Pass());
34 }
35 provider_ptrs_.AddInterfacePtr(provider_ptr.Pass());
36 return true; 32 return true;
37 } 33 }
38 34
39 // mojo::InterfaceFactory<TraceCollector> implementation.
40 void TracingApp::Create(mojo::ApplicationConnection* connection, 35 void TracingApp::Create(mojo::ApplicationConnection* connection,
41 mojo::InterfaceRequest<TraceCollector> request) { 36 mojo::InterfaceRequest<TraceCollector> request) {
42 if (collector_binding_.is_bound()) { 37 if (collector_binding_.is_bound()) {
43 LOG(ERROR) << "Another application is already connected to tracing."; 38 LOG(ERROR) << "Another application is already connected to tracing.";
44 return; 39 return;
45 } 40 }
46 41
47 collector_binding_.Bind(request.Pass()); 42 collector_binding_.Bind(request.Pass());
48 } 43 }
49 44
50 // tracing::TraceCollector implementation. 45 void TracingApp::Create(mojo::ApplicationConnection* connection,
46 mojo::InterfaceRequest<TraceProviderRegistry> request) {
47 provider_registry_bindings_.AddBinding(this, request.Pass());
jamesr 2016/04/28 20:59:02 at what point do we start saying std::move(request
48 }
49
51 void TracingApp::Start(mojo::ScopedDataPipeProducerHandle stream, 50 void TracingApp::Start(mojo::ScopedDataPipeProducerHandle stream,
52 const mojo::String& categories) { 51 const mojo::String& categories) {
53 tracing_categories_ = categories; 52 tracing_categories_ = categories;
54 sink_.reset(new TraceDataSink(stream.Pass())); 53 sink_.reset(new TraceDataSink(stream.Pass()));
55 provider_ptrs_.ForAllPtrs([categories, this](TraceProvider* controller) { 54 provider_ptrs_.ForAllPtrs([categories, this](TraceProvider* controller) {
56 TraceRecorderPtr ptr; 55 TraceRecorderPtr ptr;
57 recorder_impls_.push_back( 56 recorder_impls_.push_back(
58 new TraceRecorderImpl(GetProxy(&ptr), sink_.get())); 57 new TraceRecorderImpl(GetProxy(&ptr), sink_.get()));
59 controller->StartTracing(categories, ptr.Pass()); 58 controller->StartTracing(categories, ptr.Pass());
60 }); 59 });
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 else if (satisfied & MOJO_HANDLE_SIGNAL_PEER_CLOSED) 118 else if (satisfied & MOJO_HANDLE_SIGNAL_PEER_CLOSED)
120 recorder_impls_.erase(recorder_impls_.begin() + index); 119 recorder_impls_.erase(recorder_impls_.begin() + index);
121 } 120 }
122 // Something happened so push back the timeout deadline. 121 // Something happened so push back the timeout deadline.
123 end = MojoGetTimeTicksNow() + kTimeToWaitMicros; 122 end = MojoGetTimeTicksNow() + kTimeToWaitMicros;
124 } 123 }
125 } 124 }
126 AllDataCollected(); 125 AllDataCollected();
127 } 126 }
128 127
128 void TracingApp::RegisterTraceProvider(
129 mojo::InterfaceHandle<TraceProvider> trace_provider) {
130 auto provider_ptr = TraceProviderPtr::Create(trace_provider.Pass());
131 if (tracing_active_) {
132 TraceRecorderPtr recorder_ptr;
133 recorder_impls_.push_back(
134 new TraceRecorderImpl(GetProxy(&recorder_ptr), sink_.get()));
135 provider_ptr->StartTracing(tracing_categories_, recorder_ptr.Pass());
136 }
137 provider_ptrs_.AddInterfacePtr(provider_ptr.Pass());
138 }
139
129 void TracingApp::AllDataCollected() { 140 void TracingApp::AllDataCollected() {
130 recorder_impls_.clear(); 141 recorder_impls_.clear();
131 sink_.reset(); 142 sink_.reset();
132 } 143 }
133 144
134 } // namespace tracing 145 } // namespace tracing
OLDNEW
« no previous file with comments | « services/tracing/tracing_app.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698