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

Unified Diff: mojo/common/trace_controller_impl.cc

Issue 791493006: De-client tracing.TraceController interface (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: hook mojo shell up again 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
Index: mojo/common/trace_controller_impl.cc
diff --git a/mojo/common/trace_controller_impl.cc b/mojo/common/trace_controller_impl.cc
new file mode 100644
index 0000000000000000000000000000000000000000..2af8cc5aeb9e24c9a4df3d4aa17ee7afa71cb1bb
--- /dev/null
+++ b/mojo/common/trace_controller_impl.cc
@@ -0,0 +1,63 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "mojo/common/trace_controller_impl.h"
+
+#include "base/debug/trace_event.h"
+#include "mojo/public/cpp/application/application_connection.h"
+#include "mojo/public/cpp/application/application_impl.h"
+
+namespace mojo {
+
+TraceControllerImpl::TraceControllerImpl()
+ : binding_(this), delete_on_error_(false) {
+}
+
+TraceControllerImpl::~TraceControllerImpl() {
+}
+
+void TraceControllerImpl::Bind(
+ InterfaceRequest<tracing::TraceController> request) {
+ binding_.Bind(request.Pass());
+ delete_on_error_ = true;
+}
+
+void TraceControllerImpl::Bind(ScopedMessagePipeHandle client_handle) {
+ binding_.Bind(client_handle.Pass());
+}
+
+void TraceControllerImpl::StartTracing(
+ const String& categories,
+ tracing::TraceDataCollectorPtr collector) {
+ DCHECK(!collector_.get());
+ collector_ = collector.Pass();
+ std::string categories_str = categories.To<std::string>();
+ base::debug::TraceLog::GetInstance()->SetEnabled(
+ base::debug::CategoryFilter(categories_str),
+ base::debug::TraceLog::RECORDING_MODE,
+ base::debug::TraceOptions(base::debug::RECORD_UNTIL_FULL));
+}
+
+void TraceControllerImpl::StopTracing() {
+ base::debug::TraceLog::GetInstance()->SetDisabled();
+
+ base::debug::TraceLog::GetInstance()->Flush(
+ base::Bind(&TraceControllerImpl::SendChunk, base::Unretained(this)));
+}
+
+void TraceControllerImpl::SendChunk(
+ const scoped_refptr<base::RefCountedString>& events_str,
+ bool has_more_events) {
+ collector_->DataCollected(mojo::String(events_str->data()));
+ if (!has_more_events) {
+ collector_.reset();
+ }
+}
+
+void TraceControllerImpl::OnConnectionError() {
+ if (delete_on_error_)
+ delete this;
+}
+
+} // namespace mojo

Powered by Google App Engine
This is Rietveld 408576698