| Index: components/feedback/tracing_manager.cc
|
| diff --git a/components/feedback/tracing_manager.cc b/components/feedback/tracing_manager.cc
|
| index f35fe80876f44763eee829050efbe73d4febb7b0..4539a9a1265abe7f5869b023ab71298174ea5bfa 100644
|
| --- a/components/feedback/tracing_manager.cc
|
| +++ b/components/feedback/tracing_manager.cc
|
| @@ -5,14 +5,49 @@
|
| #include "components/feedback/tracing_manager.h"
|
|
|
| #include "base/bind.h"
|
| -#include "base/file_util.h"
|
| -#include "base/location.h"
|
| #include "base/memory/ref_counted_memory.h"
|
| #include "base/message_loop/message_loop_proxy.h"
|
| #include "components/feedback/feedback_util.h"
|
| #include "content/public/browser/tracing_controller.h"
|
|
|
| namespace {
|
| +
|
| +class StringTraceDataSink : public content::TracingController::TraceDataSink {
|
| + public:
|
| + typedef base::Callback<void(const std::string&)> CompletionCallback;
|
| +
|
| + explicit StringTraceDataSink(CompletionCallback callback)
|
| + : completion_callback_(callback) {
|
| + }
|
| +
|
| + // TracingController::TraceDataSink implementation
|
| + virtual void AddTraceChunk(const std::string& chunk) OVERRIDE {
|
| + if (!trace_.empty())
|
| + trace_ += ",";
|
| + trace_ += chunk;
|
| + }
|
| + virtual void SetSystemTrace(const std::string& data) OVERRIDE {
|
| + system_trace_ = data;
|
| + }
|
| + virtual void Close() OVERRIDE {
|
| + std::string result = "{\"traceEvents\":[" + trace_ + "]";
|
| + if (!system_trace_.empty())
|
| + result += ",\"systemTraceEvents\":[" + system_trace_ + "]";
|
| + result += "}";
|
| +
|
| + completion_callback_.Run(result);
|
| + delete this;
|
| + }
|
| +
|
| + private:
|
| + virtual ~StringTraceDataSink() {}
|
| +
|
| + std::string trace_;
|
| + std::string system_trace_;
|
| + CompletionCallback completion_callback_;
|
| +};
|
| +
|
| +
|
| // Only once trace manager can exist at a time.
|
| TracingManager* g_tracing_manager = NULL;
|
| // Trace IDs start at 1 and increase.
|
| @@ -43,9 +78,8 @@ int TracingManager::RequestTrace() {
|
| current_trace_id_ = g_next_trace_id;
|
| ++g_next_trace_id;
|
| content::TracingController::GetInstance()->DisableRecording(
|
| - base::FilePath(),
|
| - base::Bind(&TracingManager::OnTraceDataCollected,
|
| - weak_ptr_factory_.GetWeakPtr()));
|
| + new StringTraceDataSink(base::Bind(&TracingManager::OnTraceDataCollected,
|
| + weak_ptr_factory_.GetWeakPtr())));
|
| return current_trace_id_;
|
| }
|
|
|
| @@ -96,20 +130,13 @@ void TracingManager::StartTracing() {
|
| content::TracingController::EnableRecordingDoneCallback());
|
| }
|
|
|
| -void TracingManager::OnTraceDataCollected(const base::FilePath& path) {
|
| +void TracingManager::OnTraceDataCollected(const std::string& trace_data) {
|
| if (!current_trace_id_)
|
| return;
|
|
|
| - std::string data;
|
| - if (!base::ReadFileToString(path, &data)) {
|
| - LOG(ERROR) << "Failed to read trace data from: " << path.value();
|
| - return;
|
| - }
|
| - base::DeleteFile(path, false);
|
| -
|
| std::string output_val;
|
| feedback_util::ZipString(
|
| - base::FilePath(kTracingFilename), data, &output_val);
|
| + base::FilePath(kTracingFilename), trace_data, &output_val);
|
|
|
| scoped_refptr<base::RefCountedString> output(
|
| base::RefCountedString::TakeString(&output_val));
|
|
|