Chromium Code Reviews| 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 0f67ac357bd057f29787a08de0355df40d8493f0..84236bdee30485d66198b3ca9dddc8d8778442ed 100644 |
| --- a/content/browser/tracing/tracing_controller_impl_data_sinks.cc |
| +++ b/content/browser/tracing/tracing_controller_impl_data_sinks.cc |
| @@ -6,6 +6,7 @@ |
| #include "base/bind.h" |
| #include "base/files/file_util.h" |
| #include "base/json/json_writer.h" |
| +#include "base/strings/pattern.h" |
| #include "content/public/browser/browser_thread.h" |
| #include "third_party/zlib/zlib.h" |
| @@ -143,7 +144,7 @@ class StringTraceDataSink : public TracingController::TraceDataSink { |
| AddTraceChunkAndPassToEndpoint(",\"systemTraceEvents\": " + |
| system_trace_); |
| std::string metadataJSON; |
| - if (base::JSONWriter::Write(GetMetadata(), &metadataJSON) && |
| + if (base::JSONWriter::Write(*GetMetadataCopy(), &metadataJSON) && |
| !metadataJSON.empty()) |
| AddTraceChunkAndPassToEndpoint(",\"metadata\": " + metadataJSON); |
| if (!power_trace_.empty()) { |
| @@ -153,8 +154,7 @@ class StringTraceDataSink : public TracingController::TraceDataSink { |
| AddTraceChunkAndPassToEndpoint("}"); |
| - scoped_ptr<const base::DictionaryValue> metadata(GetMetadata().DeepCopy()); |
| - endpoint_->ReceiveTraceFinalContents(metadata.Pass(), trace_); |
| + endpoint_->ReceiveTraceFinalContents(GetMetadataCopy(), trace_); |
| } |
| private: |
| @@ -278,7 +278,7 @@ class CompressedStringTraceDataSink : public TracingController::TraceDataSink { |
| ",\"systemTraceEvents\": " + system_trace_, false); |
| } |
| std::string metadataJSON; |
| - if (base::JSONWriter::Write(GetMetadata(), &metadataJSON) && |
| + if (base::JSONWriter::Write(*GetMetadataCopy(), &metadataJSON) && |
| !metadataJSON.empty()) { |
| AddTraceChunkAndCompressOnFileThread(",\"metadata\": " + metadataJSON, |
| false); |
| @@ -292,8 +292,7 @@ class CompressedStringTraceDataSink : public TracingController::TraceDataSink { |
| deflateEnd(stream_.get()); |
| stream_.reset(); |
| - scoped_ptr<const base::DictionaryValue> metadata(GetMetadata().DeepCopy()); |
| - endpoint_->ReceiveTraceFinalContents(metadata.Pass(), |
| + endpoint_->ReceiveTraceFinalContents(GetMetadataCopy(), |
| compressed_trace_data_); |
| } |
| @@ -307,16 +306,56 @@ class CompressedStringTraceDataSink : public TracingController::TraceDataSink { |
| DISALLOW_COPY_AND_ASSIGN(CompressedStringTraceDataSink); |
| }; |
| +const char* kMetadataWhitelist[] = { |
|
oystein (OOO til 10th of July)
2015/12/07 22:43:51
Hmm, it'd be nice if the whitelists were all livin
Zhen Wang
2015/12/07 23:23:27
Discussed offline, will try the following way:
- T
|
| + "command_line", |
| + "cpu-*", |
| + "field-trials", |
| + "gpu-*", |
| + "highres-ticks", |
| + "network-type", |
| + "num-cpus", |
| + "os-*", |
| + "physical-memory", |
| + "product-version", |
| + "user-agent" |
| +}; |
| + |
| } // namespace |
| +TracingController::TraceDataSink::TraceDataSink() |
| + : requires_anonymized_metadata_(false) { |
| +} |
| + |
| void TracingController::TraceDataSink::AddMetadata( |
| const base::DictionaryValue& data) { |
| metadata_.MergeDictionary(&data); |
| } |
| -const base::DictionaryValue& |
| - TracingController::TraceDataSink::GetMetadata() const { |
| - return metadata_; |
| +void TracingController::TraceDataSink::EnableMetadataFilter() { |
| + requires_anonymized_metadata_ = true; |
| +} |
| + |
| +scoped_ptr<const base::DictionaryValue> |
| + TracingController::TraceDataSink::GetMetadataCopy() const { |
| + if (!requires_anonymized_metadata_) |
| + return scoped_ptr<const base::DictionaryValue>(metadata_.DeepCopy()).Pass(); |
| + |
| + scoped_ptr<base::DictionaryValue> metadata_copy(new base::DictionaryValue); |
| + for (base::DictionaryValue::Iterator it(metadata_); !it.IsAtEnd(); |
| + it.Advance()) { |
| + bool whitelisted = false; |
| + for (auto key : kMetadataWhitelist) { |
| + if (base::MatchPattern(it.key(), key)) { |
| + whitelisted = true; |
| + break; |
| + } |
| + } |
| + if (whitelisted) |
| + metadata_copy->Set(it.key(), it.value().DeepCopy()); |
| + else |
| + metadata_copy->SetString(it.key(), "__stripped__"); |
| + } |
| + return metadata_copy.Pass(); |
| } |
| scoped_refptr<TracingController::TraceDataSink> |