| Index: content/browser/devtools/devtools_tracing_handler.cc
|
| diff --git a/content/browser/devtools/devtools_tracing_handler.cc b/content/browser/devtools/devtools_tracing_handler.cc
|
| index 0e1869a141d99280a416b84cb224822907057a44..0657b8e48d2a9c83cc2d171630eddcefc77913b4 100644
|
| --- a/content/browser/devtools/devtools_tracing_handler.cc
|
| +++ b/content/browser/devtools/devtools_tracing_handler.cc
|
| @@ -6,18 +6,14 @@
|
|
|
| #include "base/bind.h"
|
| #include "base/callback.h"
|
| -#include "base/file_util.h"
|
| -#include "base/json/json_reader.h"
|
| -#include "base/json/json_writer.h"
|
| #include "base/location.h"
|
| -#include "base/memory/ref_counted_memory.h"
|
| #include "base/strings/string_split.h"
|
| #include "base/strings/stringprintf.h"
|
| #include "base/values.h"
|
| #include "content/browser/devtools/devtools_http_handler_impl.h"
|
| #include "content/browser/devtools/devtools_protocol_constants.h"
|
| -#include "content/public/browser/browser_thread.h"
|
| -#include "content/public/browser/tracing_controller.h"
|
| +#include "content/public/browser/trace_controller.h"
|
| +#include "content/public/browser/trace_subscriber.h"
|
|
|
| namespace content {
|
|
|
| @@ -27,23 +23,10 @@
|
| const char kRecordContinuously[] = "record-continuously";
|
| const char kEnableSampling[] = "enable-sampling";
|
|
|
| -void ReadFile(
|
| - const base::FilePath& path,
|
| - const base::Callback<void(const scoped_refptr<base::RefCountedString>&)>
|
| - callback) {
|
| - std::string trace_data;
|
| - if (!base::ReadFileToString(path, &trace_data))
|
| - LOG(ERROR) << "Failed to read file: " << path.value();
|
| - base::DeleteFile(path, false);
|
| - BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
|
| - base::Bind(callback, make_scoped_refptr(
|
| - base::RefCountedString::TakeString(&trace_data))));
|
| -}
|
| -
|
| } // namespace
|
|
|
| DevToolsTracingHandler::DevToolsTracingHandler()
|
| - : weak_factory_(this) {
|
| + : is_running_(false) {
|
| RegisterCommandHandler(devtools::Tracing::start::kName,
|
| base::Bind(&DevToolsTracingHandler::OnStart,
|
| base::Unretained(this)));
|
| @@ -55,60 +38,28 @@
|
| DevToolsTracingHandler::~DevToolsTracingHandler() {
|
| }
|
|
|
| -void DevToolsTracingHandler::BeginReadingRecordingResult(
|
| - const base::FilePath& path) {
|
| - BrowserThread::PostTask(
|
| - BrowserThread::FILE, FROM_HERE,
|
| - base::Bind(&ReadFile, path,
|
| - base::Bind(&DevToolsTracingHandler::ReadRecordingResult,
|
| - weak_factory_.GetWeakPtr())));
|
| -}
|
| -
|
| -void DevToolsTracingHandler::ReadRecordingResult(
|
| - const scoped_refptr<base::RefCountedString>& trace_data) {
|
| - if (trace_data->data().size()) {
|
| - scoped_ptr<base::Value> trace_value(base::JSONReader::Read(
|
| - trace_data->data()));
|
| - DictionaryValue* dictionary = NULL;
|
| - bool ok = trace_value->GetAsDictionary(&dictionary);
|
| - DCHECK(ok);
|
| - ListValue* list = NULL;
|
| - ok = dictionary->GetList("traceEvents", &list);
|
| - DCHECK(ok);
|
| - std::string buffer;
|
| - for (size_t i = 0; i < list->GetSize(); ++i) {
|
| - std::string item;
|
| - base::Value* item_value;
|
| - list->Get(i, &item_value);
|
| - base::JSONWriter::Write(item_value, &item);
|
| - if (buffer.size())
|
| - buffer.append(",");
|
| - buffer.append(item);
|
| - if (i % 1000 == 0) {
|
| - OnTraceDataCollected(buffer);
|
| - buffer.clear();
|
| - }
|
| - }
|
| - if (buffer.size())
|
| - OnTraceDataCollected(buffer);
|
| - }
|
| -
|
| +void DevToolsTracingHandler::OnEndTracingComplete() {
|
| + is_running_ = false;
|
| SendNotification(devtools::Tracing::tracingComplete::kName, NULL);
|
| }
|
|
|
| void DevToolsTracingHandler::OnTraceDataCollected(
|
| - const std::string& trace_fragment) {
|
| - // Hand-craft protocol notification message so we can substitute JSON
|
| - // that we already got as string as a bare object, not a quoted string.
|
| - std::string message = base::StringPrintf(
|
| - "{ \"method\": \"%s\", \"params\": { \"%s\": [ %s ] } }",
|
| - devtools::Tracing::dataCollected::kName,
|
| - devtools::Tracing::dataCollected::kValue,
|
| - trace_fragment.c_str());
|
| - SendRawMessage(message);
|
| + const scoped_refptr<base::RefCountedString>& trace_fragment) {
|
| + if (is_running_) {
|
| + // Hand-craft protocol notification message so we can substitute JSON
|
| + // that we already got as string as a bare object, not a quoted string.
|
| + std::string message = base::StringPrintf(
|
| + "{ \"method\": \"%s\", \"params\": { \"%s\": [ %s ] } }",
|
| + devtools::Tracing::dataCollected::kName,
|
| + devtools::Tracing::dataCollected::kValue,
|
| + trace_fragment->data().c_str());
|
| + SendRawMessage(message);
|
| + }
|
| }
|
|
|
| -TracingController::Options DevToolsTracingHandler::TraceOptionsFromString(
|
| +// Note, if you add more options here you also need to update:
|
| +// base/debug/trace_event_impl:TraceOptionsFromString
|
| +base::debug::TraceLog::Options DevToolsTracingHandler::TraceOptionsFromString(
|
| const std::string& options) {
|
| std::vector<std::string> split;
|
| std::vector<std::string>::iterator iter;
|
| @@ -117,14 +68,18 @@
|
| base::SplitString(options, ',', &split);
|
| for (iter = split.begin(); iter != split.end(); ++iter) {
|
| if (*iter == kRecordUntilFull) {
|
| - ret &= ~TracingController::RECORD_CONTINUOUSLY;
|
| + ret |= base::debug::TraceLog::RECORD_UNTIL_FULL;
|
| } else if (*iter == kRecordContinuously) {
|
| - ret |= TracingController::RECORD_CONTINUOUSLY;
|
| + ret |= base::debug::TraceLog::RECORD_CONTINUOUSLY;
|
| } else if (*iter == kEnableSampling) {
|
| - ret |= TracingController::ENABLE_SAMPLING;
|
| + ret |= base::debug::TraceLog::ENABLE_SAMPLING;
|
| }
|
| }
|
| - return static_cast<TracingController::Options>(ret);
|
| + if (!(ret & base::debug::TraceLog::RECORD_UNTIL_FULL) &&
|
| + !(ret & base::debug::TraceLog::RECORD_CONTINUOUSLY))
|
| + ret |= base::debug::TraceLog::RECORD_UNTIL_FULL;
|
| +
|
| + return static_cast<base::debug::TraceLog::Options>(ret);
|
| }
|
|
|
| scoped_refptr<DevToolsProtocol::Response>
|
| @@ -135,26 +90,23 @@
|
| if (params)
|
| params->GetString(devtools::Tracing::start::kCategories, &categories);
|
|
|
| - TracingController::Options options = TracingController::DEFAULT_OPTIONS;
|
| + base::debug::TraceLog::Options options =
|
| + base::debug::TraceLog::RECORD_UNTIL_FULL;
|
| if (params && params->HasKey(devtools::Tracing::start::kTraceOptions)) {
|
| std::string options_param;
|
| params->GetString(devtools::Tracing::start::kTraceOptions, &options_param);
|
| options = TraceOptionsFromString(options_param);
|
| }
|
|
|
| - TracingController::GetInstance()->EnableRecording(
|
| - categories, options,
|
| - TracingController::EnableRecordingDoneCallback());
|
| + TraceController::GetInstance()->BeginTracing(this, categories, options);
|
| + is_running_ = true;
|
| return command->SuccessResponse(NULL);
|
| }
|
|
|
| scoped_refptr<DevToolsProtocol::Response>
|
| DevToolsTracingHandler::OnEnd(
|
| scoped_refptr<DevToolsProtocol::Command> command) {
|
| - TracingController::GetInstance()->DisableRecording(
|
| - base::FilePath(),
|
| - base::Bind(&DevToolsTracingHandler::BeginReadingRecordingResult,
|
| - weak_factory_.GetWeakPtr()));
|
| + TraceController::GetInstance()->EndTracingAsync(this);
|
| return command->SuccessResponse(NULL);
|
| }
|
|
|
|
|