Chromium Code Reviews| Index: content/browser/trace_subscriber_stdio.cc |
| diff --git a/content/browser/trace_subscriber_stdio.cc b/content/browser/trace_subscriber_stdio.cc |
| index bf6a8fccd2adc84ad88e86535eaf5a7495d81ce7..e5ab81468400b23133da3b568418754ad3c80b63 100644 |
| --- a/content/browser/trace_subscriber_stdio.cc |
| +++ b/content/browser/trace_subscriber_stdio.cc |
| @@ -22,8 +22,6 @@ bool TraceSubscriberStdio::OpenFile(const FilePath& path) { |
| CloseFile(); |
| file_ = file_util::OpenFile(path, "w+"); |
| if (IsValid()) { |
| - // FIXME: the file format expects it to start with "[". |
| - fputc('[', file_); |
| return true; |
| } else { |
| LOG(ERROR) << "Failed to open performance trace file: " << path.value(); |
| @@ -33,8 +31,6 @@ bool TraceSubscriberStdio::OpenFile(const FilePath& path) { |
| void TraceSubscriberStdio::CloseFile() { |
| if (file_) { |
| - // FIXME: the file format expects it to end with "]". |
| - fputc(']', file_); |
| fclose(file_); |
| file_ = 0; |
| } |
| @@ -45,27 +41,21 @@ bool TraceSubscriberStdio::IsValid() { |
| } |
| void TraceSubscriberStdio::OnEndTracingComplete() { |
| + if (IsValid()) { |
| + std::string json_trace_data; |
| + trace_buffer_.GetJSON(&json_trace_data); |
| + size_t written = fwrite(json_trace_data.c_str(), 1, json_trace_data.size(), |
|
nduca
2011/10/20 00:28:03
/me worries about this blowing out memory on clank
jbates
2011/10/20 22:18:49
Done.
|
| + file_); |
| + if (written != json_trace_data.size()) { |
| + LOG(ERROR) << "Error " << ferror(file_) << " when writing to trace file"; |
| + fclose(file_); |
| + file_ = 0; |
| + } |
| + } |
| CloseFile(); |
| } |
| void TraceSubscriberStdio::OnTraceDataCollected( |
| - const std::string& json_events) { |
| - if (!IsValid()) { |
| - return; |
| - } |
| - |
| - // FIXME: "json_events" currently comes with "[" and "]". But the file doesn't |
| - // expect them. So remove them when writing to the file. |
| - CHECK_GE(json_events.size(), 2u); |
| - const char* data = json_events.data() + 1; |
| - size_t size = json_events.size() - 2; |
| - |
| - size_t written = fwrite(data, 1, size, file_); |
| - if (written != size) { |
| - LOG(ERROR) << "Error " << ferror(file_) << " when writing to trace file"; |
| - fclose(file_); |
| - file_ = 0; |
| - } else { |
| - fputc(',', file_); |
| - } |
| + const std::string& trace_fragment) { |
| + trace_buffer_.AddFragment(trace_fragment); |
| } |