Chromium Code Reviews| Index: content/browser/debugger/devtools_tracing_handler.cc |
| diff --git a/content/browser/debugger/devtools_tracing_handler.cc b/content/browser/debugger/devtools_tracing_handler.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..d7d9f9b25dc2afd78fbfa32350c5d0062225332f |
| --- /dev/null |
| +++ b/content/browser/debugger/devtools_tracing_handler.cc |
| @@ -0,0 +1,87 @@ |
| +// 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_tracing_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 { |
| + |
| +DevToolsTracingHandler::DevToolsTracingHandler() |
| + : has_completed_(false) { |
| +} |
| + |
| +DevToolsTracingHandler::~DevToolsTracingHandler() { |
| +} |
| + |
| +void DevToolsTracingHandler::OnEndTracingComplete() { |
| + has_completed_ = true; |
| +} |
| + |
| +void DevToolsTracingHandler::OnTraceDataCollected( |
| + const scoped_refptr<base::RefCountedString>& trace_fragment) { |
| + buffer_.push_back(trace_fragment->data()); |
| +} |
| + |
| +base::Value* DevToolsTracingHandler::OnProtocolCommand( |
| + const std::string& method, |
| + const base::DictionaryValue* params) { |
| + if (method == "Tracing.start") |
| + return Start(params); |
| + else if (method == "Tracing.end") |
| + return End(params); |
| + else if (method == "Tracing.hasCompleted") |
| + return HasCompleted(params); |
| + else if (method == "Tracing.getTraceAndReset") |
| + return GetTraceAndReset(params); |
| + return NULL; |
| +} |
| + |
| +base::Value* DevToolsTracingHandler::Start( |
| + const base::DictionaryValue* params) { |
| + std::string categories; |
| + if (params && params->HasKey("categories")) |
| + params->GetString("categories", &categories); |
| + TraceController::GetInstance()->BeginTracing(this, categories); |
| + |
| + return base::Value::CreateBooleanValue(true); |
| +} |
| + |
| +base::Value* DevToolsTracingHandler::End( |
| + const base::DictionaryValue* /* params */) { |
| + TraceController::GetInstance()->EndTracingAsync(this); |
| + |
| + return base::Value::CreateBooleanValue(true); |
| +} |
| + |
| + |
| +base::Value* DevToolsTracingHandler::HasCompleted( |
| + const base::DictionaryValue* /* params */) { |
| + |
| + return base::Value::CreateBooleanValue(has_completed_); |
| +} |
| + |
| +base::Value* DevToolsTracingHandler::GetTraceAndReset( |
| + const base::DictionaryValue* /* params */) { |
| + std::string ret; |
|
pfeldman
2012/12/14 18:35:05
Since you anyways use append with no pre-allocated
bulach
2012/12/14 19:53:39
tracking the size and reserve'ing..
|
| + for (std::vector<std::string>::const_iterator i = buffer_.begin(); |
| + i != buffer_.end(); ++i) { |
| + if (!ret.empty()) |
| + ret.append(","); |
| + ret.append(*i); |
| + } |
| + buffer_.clear(); |
| + has_completed_ = false; |
| + |
| + return base::Value::CreateStringValue(ret); |
| +} |
| + |
| +} // namespace content |