Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1541)

Unified Diff: content/browser/tracing/tracing_controller_impl.cc

Issue 1088673003: CompressedStringDataSink for trace_controller. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix win compile and tests. Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/tracing/tracing_controller_impl.cc
diff --git a/content/browser/tracing/tracing_controller_impl.cc b/content/browser/tracing/tracing_controller_impl.cc
index 34e384a343703101f1d7d82e65b3fcd33619d7b1..04d9fa4716d7e6564a6066cd6c05a5d96b5561ed 100644
--- a/content/browser/tracing/tracing_controller_impl.cc
+++ b/content/browser/tracing/tracing_controller_impl.cc
@@ -35,127 +35,6 @@ namespace {
base::LazyInstance<TracingControllerImpl>::Leaky g_controller =
LAZY_INSTANCE_INITIALIZER;
-class FileTraceDataSink : public TracingController::TraceDataSink {
- public:
- explicit FileTraceDataSink(const base::FilePath& trace_file_path,
- const base::Closure& callback)
- : file_path_(trace_file_path),
- completion_callback_(callback),
- file_(NULL) {}
-
- void AddTraceChunk(const std::string& chunk) override {
- std::string tmp = chunk;
- scoped_refptr<base::RefCountedString> chunk_ptr =
- base::RefCountedString::TakeString(&tmp);
- BrowserThread::PostTask(
- BrowserThread::FILE,
- FROM_HERE,
- base::Bind(
- &FileTraceDataSink::AddTraceChunkOnFileThread, this, chunk_ptr));
- }
- void SetSystemTrace(const std::string& data) override {
- system_trace_ = data;
- }
- void Close() override {
- BrowserThread::PostTask(
- BrowserThread::FILE,
- FROM_HERE,
- base::Bind(&FileTraceDataSink::CloseOnFileThread, this));
- }
-
- private:
- ~FileTraceDataSink() override { DCHECK(file_ == NULL); }
-
- void AddTraceChunkOnFileThread(
- const scoped_refptr<base::RefCountedString> chunk) {
- if (file_ != NULL)
- fputc(',', file_);
- else if (!OpenFileIfNeededOnFileThread())
- return;
- ignore_result(fwrite(chunk->data().c_str(), strlen(chunk->data().c_str()),
- 1, file_));
- }
-
- bool OpenFileIfNeededOnFileThread() {
- if (file_ != NULL)
- return true;
- file_ = base::OpenFile(file_path_, "w");
- if (file_ == NULL) {
- LOG(ERROR) << "Failed to open " << file_path_.value();
- return false;
- }
- const char preamble[] = "{\"traceEvents\": [";
- ignore_result(fwrite(preamble, strlen(preamble), 1, file_));
- return true;
- }
-
- void CloseOnFileThread() {
- if (OpenFileIfNeededOnFileThread()) {
- fputc(']', file_);
- if (!system_trace_.empty()) {
- const char systemTraceEvents[] = ",\"systemTraceEvents\": ";
- ignore_result(fwrite(systemTraceEvents, strlen(systemTraceEvents),
- 1, file_));
- ignore_result(fwrite(system_trace_.c_str(),
- strlen(system_trace_.c_str()), 1, file_));
- }
- fputc('}', file_);
- base::CloseFile(file_);
- file_ = NULL;
- }
- BrowserThread::PostTask(
- BrowserThread::UI,
- FROM_HERE,
- base::Bind(&FileTraceDataSink::FinalizeOnUIThread, this));
- }
-
- void FinalizeOnUIThread() { completion_callback_.Run(); }
-
- base::FilePath file_path_;
- base::Closure completion_callback_;
- FILE* file_;
- std::string system_trace_;
-
- DISALLOW_COPY_AND_ASSIGN(FileTraceDataSink);
-};
-
-class StringTraceDataSink : public TracingController::TraceDataSink {
- public:
- typedef base::Callback<void(base::RefCountedString*)> CompletionCallback;
-
- explicit StringTraceDataSink(CompletionCallback callback)
- : completion_callback_(callback) {}
-
- // TracingController::TraceDataSink implementation
- void AddTraceChunk(const std::string& chunk) override {
- if (!trace_.empty())
- trace_ += ",";
- trace_ += chunk;
- }
- void SetSystemTrace(const std::string& data) override {
- system_trace_ = data;
- }
- void Close() override {
- std::string result = "{\"traceEvents\":[" + trace_ + "]";
- if (!system_trace_.empty())
- result += ",\"systemTraceEvents\": " + system_trace_;
- result += "}";
-
- scoped_refptr<base::RefCountedString> str =
- base::RefCountedString::TakeString(&result);
- completion_callback_.Run(str.get());
- }
-
- private:
- ~StringTraceDataSink() override {}
-
- std::string trace_;
- std::string system_trace_;
- CompletionCallback completion_callback_;
-
- DISALLOW_COPY_AND_ASSIGN(StringTraceDataSink);
-};
-
} // namespace
TracingController* TracingController::GetInstance() {
@@ -427,18 +306,6 @@ bool TracingControllerImpl::DisableMonitoring(
return true;
}
-scoped_refptr<TracingController::TraceDataSink>
-TracingController::CreateStringSink(
- const base::Callback<void(base::RefCountedString*)>& callback) {
- return new StringTraceDataSink(callback);
-}
-
-scoped_refptr<TracingController::TraceDataSink>
-TracingController::CreateFileSink(const base::FilePath& file_path,
- const base::Closure& callback) {
- return new FileTraceDataSink(file_path, callback);
-}
-
void TracingControllerImpl::OnDisableMonitoringDone(
const DisableMonitoringDoneCallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);

Powered by Google App Engine
This is Rietveld 408576698