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

Unified Diff: content/browser/debugger/devtools_trace_domain_handler.cc

Issue 11548032: Telemetry / Devtools TraceHandler: exposes tracing via dev tools. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Pavel comment Created 8 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: content/browser/debugger/devtools_trace_domain_handler.cc
diff --git a/content/browser/debugger/devtools_trace_domain_handler.cc b/content/browser/debugger/devtools_trace_domain_handler.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c9a71d10fbacfd306b92b32a9665e3e7cb3dc3c7
--- /dev/null
+++ b/content/browser/debugger/devtools_trace_domain_handler.cc
@@ -0,0 +1,94 @@
+// Copyright (c) 2012 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 "content/browser/debugger/devtools_trace_domain_handler.h"
+
+#include "base/bind.h"
+#include "base/callback.h"
+#include "base/location.h"
+#include "base/values.h"
+#include "content/browser/debugger/devtools_http_handler_impl.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/trace_controller.h"
+#include "content/public/browser/trace_subscriber.h"
+
+namespace content {
+
+DevToolsTraceDomainHandler::DevToolsTraceDomainHandler()
pfeldman 2012/12/14 10:39:33 I think it should be called *TracingHandler
bulach 2012/12/14 16:03:52 Done.
+ : has_completed_(false) {
+}
+
+DevToolsTraceDomainHandler::~DevToolsTraceDomainHandler() {
+}
+
+void DevToolsTraceDomainHandler::OnEndTracingComplete() {
+ has_completed_ = true;
+}
+
+void DevToolsTraceDomainHandler::OnTraceDataCollected(
+ const scoped_refptr<base::RefCountedString>& trace_fragment) {
+ if (!buffer_.empty())
+ buffer_.append(",");
+ buffer_.append(trace_fragment->data());
pfeldman 2012/12/14 10:39:33 nit: You might want to store them in a vector of s
bulach 2012/12/14 16:03:52 good point. although it requires more memory when
+}
+
+base::Value* DevToolsTraceDomainHandler::OnProtocolCommand(
+ int connection_id,
pfeldman 2012/12/14 10:39:33 So no connection_id, no request_id usage here!
bulach 2012/12/14 16:03:52 Done.
+ int request_id,
+ const std::string& method,
+ const base::DictionaryValue* params) {
+ if (method == "Trace.BeginTracing")
pfeldman 2012/12/14 10:39:33 Tracing.start / end
bulach 2012/12/14 16:03:52 Done.
+ return BeginTracing(params);
+ else if (method == "Trace.EndTracingAsync")
+ return EndTracingAsync(params);
+ else if (method == "Trace.HasCompleted")
+ return HasCompleted(params);
pfeldman 2012/12/14 10:39:33 Why would you need this one? We typically rely upo
bulach 2012/12/14 16:03:52 the trouble is that the stop is asynchronous, so b
pfeldman 2012/12/14 18:35:05 So are you saying that you will poll for hasComple
+ else if (method == "Trace.GetAndResetTrace")
pfeldman 2012/12/14 10:39:33 Tracing.getTraceAndReset ?
bulach 2012/12/14 16:03:52 Done.
+ return GetAndResetTrace(params);
+ return NULL;
+}
+
+
+base::Value* DevToolsTraceDomainHandler::BeginTracing(
+ const base::DictionaryValue* params) {
+ std::string categories;
+ if (params && params->HasKey("categories"))
+ params->GetString("categories", &categories);
+ TraceController::GetInstance()->BeginTracing(this, categories);
+
+ DictionaryValue* response = new DictionaryValue();
+ response->Set("result", base::Value::CreateBooleanValue(true));
+ return response;
pfeldman 2012/12/14 10:39:33 I think you want to return base::Value::CreateBool
bulach 2012/12/14 16:03:52 yeah, I was originally thinking this level could p
+}
+
+base::Value* DevToolsTraceDomainHandler::EndTracingAsync(
+ const base::DictionaryValue* /* params */) {
+ TraceController::GetInstance()->EndTracingAsync(this);
+
+ DictionaryValue* response = new DictionaryValue();
+ response->Set("result", base::Value::CreateBooleanValue(true));
+ return response;
+}
+
+
+base::Value* DevToolsTraceDomainHandler::HasCompleted(
pfeldman 2012/12/14 10:39:33 I don't think you need this.
bulach 2012/12/14 16:03:52 as above, line 67 is async, so we need some mechan
+ const base::DictionaryValue* /* params */) {
+
+ DictionaryValue* response = new DictionaryValue();
+ response->Set("result", base::Value::CreateBooleanValue(has_completed_));
+ return response;
+}
+
+base::Value* DevToolsTraceDomainHandler::GetAndResetTrace(
+ const base::DictionaryValue* /* params */) {
+ std::string ret(buffer_);
+ buffer_.clear();
+ has_completed_ = false;
+
+ DictionaryValue* response = new DictionaryValue();
+ response->Set("result", base::Value::CreateStringValue(ret));
+ return response;
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698