| 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 238cf24d5f8d2f8b8f4bc31a90126e0254cb4e60..9a53cc0376dad10330b906341e16fbd1430f8bc2 100644
|
| --- a/content/browser/devtools/devtools_tracing_handler.cc
|
| +++ b/content/browser/devtools/devtools_tracing_handler.cc
|
| @@ -7,13 +7,7 @@
|
| #include <cmath>
|
|
|
| #include "base/bind.h"
|
| -#include "base/callback.h"
|
| #include "base/debug/trace_event_impl.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/time/time.h"
|
| @@ -33,18 +27,27 @@ const char kRecordContinuously[] = "record-continuously";
|
| const char kRecordAsMuchAsPossible[] = "record-as-much-as-possible";
|
| 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))));
|
| -}
|
| +class DevToolsTraceSinkProxy : public TracingController::TraceDataSink {
|
| + public:
|
| + explicit DevToolsTraceSinkProxy(base::WeakPtr<DevToolsTracingHandler> handler)
|
| + : tracing_handler_(handler) {
|
| + }
|
| +
|
| + virtual void AddTraceChunk(const std::string& chunk) OVERRIDE {
|
| + if (DevToolsTracingHandler* h = tracing_handler_.get())
|
| + h->OnTraceDataCollected(chunk);
|
| + }
|
| + virtual void Close() OVERRIDE {
|
| + if (DevToolsTracingHandler* h = tracing_handler_.get())
|
| + h->OnTraceComplete();
|
| + delete this;
|
| + }
|
| +
|
| + private:
|
| + virtual ~DevToolsTraceSinkProxy() {}
|
| +
|
| + base::WeakPtr<DevToolsTracingHandler> tracing_handler_;
|
| +};
|
|
|
| } // namespace
|
|
|
| @@ -70,48 +73,6 @@ DevToolsTracingHandler::DevToolsTracingHandler(
|
| 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()));
|
| - base::DictionaryValue* dictionary = NULL;
|
| - bool ok = trace_value->GetAsDictionary(&dictionary);
|
| - DCHECK(ok);
|
| - base::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);
|
| - const size_t kMessageSizeThreshold = 1024 * 1024;
|
| - if (buffer.size() > kMessageSizeThreshold) {
|
| - OnTraceDataCollected(buffer);
|
| - buffer.clear();
|
| - }
|
| - }
|
| - if (buffer.size())
|
| - OnTraceDataCollected(buffer);
|
| - }
|
| -
|
| - SendNotification(devtools::Tracing::tracingComplete::kName, NULL);
|
| -}
|
| -
|
| void DevToolsTracingHandler::OnTraceDataCollected(
|
| const std::string& trace_fragment) {
|
| // Hand-craft protocol notification message so we can substitute JSON
|
| @@ -124,6 +85,10 @@ void DevToolsTracingHandler::OnTraceDataCollected(
|
| SendRawMessage(message);
|
| }
|
|
|
| +void DevToolsTracingHandler::OnTraceComplete() {
|
| + SendNotification(devtools::Tracing::tracingComplete::kName, NULL);
|
| +}
|
| +
|
| base::debug::TraceOptions DevToolsTracingHandler::TraceOptionsFromString(
|
| const std::string& options) {
|
| std::vector<std::string> split;
|
| @@ -221,23 +186,20 @@ DevToolsTracingHandler::OnEnd(
|
| // tracing agent in the renderer.
|
| if (target_ == Renderer)
|
| return NULL;
|
| - DisableRecording(
|
| - base::Bind(&DevToolsTracingHandler::BeginReadingRecordingResult,
|
| - weak_factory_.GetWeakPtr()));
|
| + DisableRecording(false);
|
| return command->SuccessResponse(NULL);
|
| }
|
|
|
| -void DevToolsTracingHandler::DisableRecording(
|
| - const TracingController::TracingFileResultCallback& callback) {
|
| +void DevToolsTracingHandler::DisableRecording(bool abort) {
|
| is_recording_ = false;
|
| buffer_usage_poll_timer_.reset();
|
| - TracingController::GetInstance()->DisableRecording(base::FilePath(),
|
| - callback);
|
| + TracingController::GetInstance()->DisableRecording(
|
| + abort ? NULL : new DevToolsTraceSinkProxy(weak_factory_.GetWeakPtr()));
|
| }
|
|
|
| void DevToolsTracingHandler::OnClientDetached() {
|
| if (is_recording_)
|
| - DisableRecording();
|
| + DisableRecording(true);
|
| }
|
|
|
| scoped_refptr<DevToolsProtocol::Response>
|
| @@ -283,9 +245,7 @@ void DevToolsTracingHandler::DisableTracing() {
|
| if (!is_recording_)
|
| return;
|
| is_recording_ = false;
|
| - DisableRecording(
|
| - base::Bind(&DevToolsTracingHandler::BeginReadingRecordingResult,
|
| - weak_factory_.GetWeakPtr()));
|
| + DisableRecording(false);
|
| }
|
|
|
|
|
|
|