Chromium Code Reviews| 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 |