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

Unified Diff: services/tracing/main.cc

Issue 791493006: De-client tracing.TraceController interface (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « services/surfaces/surfaces_service_application.cc ('k') | services/tracing/tracing.mojom » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: services/tracing/main.cc
diff --git a/services/tracing/main.cc b/services/tracing/main.cc
index 2c95ccdac4d35eec54242ca263da336b81057486..6d5e28ff08727ac93bcc6e87a90c1e86bb4aca30 100644
--- a/services/tracing/main.cc
+++ b/services/tracing/main.cc
@@ -5,6 +5,7 @@
#include "base/bind.h"
#include "mojo/application/application_runner_chromium.h"
#include "mojo/common/weak_binding_set.h"
+#include "mojo/common/weak_interface_ptr_set.h"
#include "mojo/public/c/system/main.h"
#include "mojo/public/cpp/application/application_delegate.h"
#include "mojo/public/cpp/application/application_impl.h"
@@ -16,7 +17,6 @@ namespace tracing {
class TracingApp : public mojo::ApplicationDelegate,
public mojo::InterfaceFactory<TraceCoordinator>,
public tracing::TraceCoordinator,
- public mojo::InterfaceFactory<TraceDataCollector>,
public tracing::TraceDataCollector {
public:
TracingApp() {}
@@ -27,7 +27,15 @@ class TracingApp : public mojo::ApplicationDelegate,
bool ConfigureIncomingConnection(
mojo::ApplicationConnection* connection) override {
connection->AddService<TraceCoordinator>(this);
- connection->AddService<TraceDataCollector>(this);
+
+ // If someone connects to us they may want to use the TraceCoordinator
+ // interface and/or they may want to expose themselves to be traced. Attempt
+ // to connect to the TraceController interface to see if the application
+ // connecting to us wants to be traced. They can refuse the connection or
+ // close the pipe if not.
+ mojo::InterfacePtr<TraceController> controller_ptr;
+ connection->ConnectToService(&controller_ptr);
+ controller_ptrs_.AddInterfacePtr(controller_ptr.Pass());
return true;
}
@@ -37,23 +45,23 @@ class TracingApp : public mojo::ApplicationDelegate,
coordinator_bindings_.AddBinding(this, request.Pass());
}
- // mojo::InterfaceFactory<TraceDataCollector> implementation.
- void Create(mojo::ApplicationConnection* connection,
- mojo::InterfaceRequest<TraceDataCollector> request) override {
- collector_bindings_.AddBinding(this, request.Pass());
- }
-
// tracing::TraceCoordinator implementation.
void Start(const mojo::String& base_name,
const mojo::String& categories) override {
base::FilePath base_name_path =
base::FilePath::FromUTF8Unsafe(base_name.To<std::string>());
sink_.reset(new TraceDataSink(base_name_path));
- collector_bindings_.ForAllBindings([categories](
- TraceController* controller) { controller->StartTracing(categories); });
+ controller_ptrs_.ForAllPtrs(
+ [categories, this](TraceController* controller) {
+ auto binding = new mojo::Binding<TraceDataCollector>(this);
+ TraceDataCollectorPtr ptr;
+ binding->Bind(&ptr);
+ collector_bindings_.push_back(binding);
+ controller->StartTracing(categories, ptr.Pass());
+ });
}
void StopAndFlush() override {
- collector_bindings_.ForAllBindings(
+ controller_ptrs_.ForAllPtrs(
[](TraceController* controller) { controller->StopTracing(); });
// TODO: We really should keep track of how many connections we have here
jamesr 2014/12/19 02:00:59 what i really want do to is join all controller me
@@ -61,20 +69,26 @@ class TracingApp : public mojo::ApplicationDelegate,
// pipe closure on all pipes.
base::MessageLoop::current()->PostDelayedTask(
FROM_HERE,
- base::Bind(&TraceDataSink::Flush, base::Unretained(sink_.get())),
+ base::Bind(&TracingApp::AllDataCollected, base::Unretained(this)),
base::TimeDelta::FromSeconds(1));
}
+ void AllDataCollected() {
+ for (auto p : collector_bindings_)
+ delete p;
+ collector_bindings_.clear();
+ sink_->Flush();
+ }
+
// tracing::TraceDataCollector implementation.
void DataCollected(const mojo::String& json) override {
if (sink_)
sink_->AddChunk(json.To<std::string>());
}
- // tracing::TraceDataCollector implementation.
- void EndTracing() override {}
scoped_ptr<TraceDataSink> sink_;
- mojo::WeakBindingSet<TraceDataCollector> collector_bindings_;
+ std::vector<mojo::Binding<TraceDataCollector>*> collector_bindings_;
+ mojo::WeakInterfacePtrSet<TraceController> controller_ptrs_;
mojo::WeakBindingSet<TraceCoordinator> coordinator_bindings_;
DISALLOW_COPY_AND_ASSIGN(TracingApp);
« no previous file with comments | « services/surfaces/surfaces_service_application.cc ('k') | services/tracing/tracing.mojom » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698