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

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

Issue 2143033004: Change TraceDataEndPoint::ReceiveTraceChunk() to accept unique_ptr<string> (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: now use unique_ptr Created 4 years, 5 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
« no previous file with comments | « content/browser/tracing/tracing_controller_impl.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/tracing/tracing_controller_impl_data_sinks.cc
diff --git a/content/browser/tracing/tracing_controller_impl_data_sinks.cc b/content/browser/tracing/tracing_controller_impl_data_sinks.cc
index c4561462e72052cdedc459fd5fa0fdbde6f48e57..86f0df224ba888da6fb8b8e8458301ddfc6316ae 100644
--- a/content/browser/tracing/tracing_controller_impl_data_sinks.cc
+++ b/content/browser/tracing/tracing_controller_impl_data_sinks.cc
@@ -43,7 +43,9 @@ class StringTraceDataEndpoint : public TraceDataEndpoint {
base::RetainedRef(str)));
}
- void ReceiveTraceChunk(const std::string& chunk) override { trace_ << chunk; }
+ void ReceiveTraceChunk(std::unique_ptr<std::string> chunk) override {
+ trace_ << *chunk;
+ }
private:
~StringTraceDataEndpoint() override {}
@@ -62,14 +64,11 @@ class FileTraceDataEndpoint : public TraceDataEndpoint {
completion_callback_(callback),
file_(NULL) {}
- void ReceiveTraceChunk(const std::string& chunk) override {
- std::string tmp = chunk;
- scoped_refptr<base::RefCountedString> chunk_ptr =
- base::RefCountedString::TakeString(&tmp);
+ void ReceiveTraceChunk(std::unique_ptr<std::string> chunk) override {
BrowserThread::PostTask(
BrowserThread::FILE, FROM_HERE,
base::Bind(&FileTraceDataEndpoint::ReceiveTraceChunkOnFileThread, this,
- chunk_ptr));
+ base::Passed(std::move(chunk))));
}
void ReceiveTraceFinalContents(
@@ -82,12 +81,10 @@ class FileTraceDataEndpoint : public TraceDataEndpoint {
private:
~FileTraceDataEndpoint() override { DCHECK(file_ == NULL); }
- void ReceiveTraceChunkOnFileThread(
- const scoped_refptr<base::RefCountedString> chunk) {
+ void ReceiveTraceChunkOnFileThread(std::unique_ptr<std::string> chunk) {
if (!OpenFileIfNeededOnFileThread())
return;
- ignore_result(
- fwrite(chunk->data().c_str(), chunk->data().size(), 1, file_));
+ ignore_result(fwrite(chunk->c_str(), chunk->size(), 1, file_));
}
bool OpenFileIfNeededOnFileThread() {
@@ -157,25 +154,26 @@ class JSONTraceDataSink : public TraceDataSinkImplBase {
trace_string += chunk;
had_received_first_chunk_ = true;
- endpoint_->ReceiveTraceChunk(trace_string);
+ endpoint_->ReceiveTraceChunk(base::MakeUnique<std::string>(trace_string));
}
void Close() override {
- endpoint_->ReceiveTraceChunk("]");
+ endpoint_->ReceiveTraceChunk(base::MakeUnique<std::string>("]"));
for (auto const &it : GetAgentTrace())
- endpoint_->ReceiveTraceChunk(",\"" + it.first + "\": " + it.second);
+ endpoint_->ReceiveTraceChunk(
+ base::MakeUnique<std::string>(",\"" + it.first + "\": " + it.second));
std::unique_ptr<base::DictionaryValue> metadata(TakeMetadata());
std::string metadataJSON;
if (base::JSONWriter::Write(*metadata, &metadataJSON) &&
!metadataJSON.empty()) {
- endpoint_->ReceiveTraceChunk(",\"" + std::string(kMetadataTraceLabel) +
- "\": " + metadataJSON);
+ endpoint_->ReceiveTraceChunk(base::MakeUnique<std::string>(
+ ",\"" + std::string(kMetadataTraceLabel) + "\": " + metadataJSON));
}
- endpoint_->ReceiveTraceChunk("}");
+ endpoint_->ReceiveTraceChunk(base::MakeUnique<std::string>("}"));
endpoint_->ReceiveTraceFinalContents(std::move(metadata));
}
@@ -193,11 +191,11 @@ class CompressedTraceDataEndpoint : public TraceDataEndpoint {
scoped_refptr<TraceDataEndpoint> endpoint)
: endpoint_(endpoint), already_tried_open_(false) {}
- void ReceiveTraceChunk(const std::string& chunk) override {
+ void ReceiveTraceChunk(std::unique_ptr<std::string> chunk) override {
BrowserThread::PostTask(
BrowserThread::FILE, FROM_HERE,
base::Bind(&CompressedTraceDataEndpoint::CompressOnFileThread, this,
- base::Passed(base::MakeUnique<std::string>(chunk))));
+ base::Passed(std::move(chunk))));
}
void ReceiveTraceFinalContents(
@@ -240,7 +238,7 @@ class CompressedTraceDataEndpoint : public TraceDataEndpoint {
return;
stream_->avail_in = chunk->size();
- stream_->next_in = (unsigned char*)chunk->data();
+ stream_->next_in = reinterpret_cast<unsigned char*>(&*chunk->begin());
oystein (OOO til 10th of July) 2016/07/15 16:56:26 Just curious: What's the reason for &*chunk->begin
DrainStreamOnFileThread(false);
}
@@ -261,8 +259,8 @@ class CompressedTraceDataEndpoint : public TraceDataEndpoint {
int bytes = kChunkSize - stream_->avail_out;
if (bytes) {
- std::string compressed_chunk = std::string(buffer, bytes);
- endpoint_->ReceiveTraceChunk(compressed_chunk);
+ std::string compressed(buffer, bytes);
+ endpoint_->ReceiveTraceChunk(base::MakeUnique<std::string>(compressed));
}
} while (stream_->avail_out == 0);
}
« no previous file with comments | « content/browser/tracing/tracing_controller_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698