| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 #include "content/browser/tracing/tracing_controller_impl.h" | 4 #include <utility> |
| 5 | 5 |
| 6 #include "base/bind.h" | 6 #include "base/bind.h" |
| 7 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
| 8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/strings/pattern.h" | 10 #include "base/strings/pattern.h" |
| 11 #include "content/browser/tracing/tracing_controller_impl.h" |
| 11 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
| 12 #include "third_party/zlib/zlib.h" | 13 #include "third_party/zlib/zlib.h" |
| 13 | 14 |
| 14 namespace content { | 15 namespace content { |
| 15 | 16 |
| 16 namespace { | 17 namespace { |
| 17 | 18 |
| 18 const char kChromeTraceLabel[] = "traceEvents"; | 19 const char kChromeTraceLabel[] = "traceEvents"; |
| 19 const char kMetadataTraceLabel[] = "metadata"; | 20 const char kMetadataTraceLabel[] = "metadata"; |
| 20 | 21 |
| 21 class StringTraceDataEndpoint : public TracingController::TraceDataEndpoint { | 22 class StringTraceDataEndpoint : public TracingController::TraceDataEndpoint { |
| 22 public: | 23 public: |
| 23 typedef base::Callback<void(scoped_ptr<const base::DictionaryValue>, | 24 typedef base::Callback<void(scoped_ptr<const base::DictionaryValue>, |
| 24 base::RefCountedString*)> CompletionCallback; | 25 base::RefCountedString*)> CompletionCallback; |
| 25 | 26 |
| 26 explicit StringTraceDataEndpoint(CompletionCallback callback) | 27 explicit StringTraceDataEndpoint(CompletionCallback callback) |
| 27 : completion_callback_(callback) {} | 28 : completion_callback_(callback) {} |
| 28 | 29 |
| 29 void ReceiveTraceFinalContents( | 30 void ReceiveTraceFinalContents( |
| 30 scoped_ptr<const base::DictionaryValue> metadata, | 31 scoped_ptr<const base::DictionaryValue> metadata, |
| 31 const std::string& contents) override { | 32 const std::string& contents) override { |
| 32 std::string tmp = contents; | 33 std::string tmp = contents; |
| 33 scoped_refptr<base::RefCountedString> str = | 34 scoped_refptr<base::RefCountedString> str = |
| 34 base::RefCountedString::TakeString(&tmp); | 35 base::RefCountedString::TakeString(&tmp); |
| 35 | 36 |
| 36 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 37 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 37 base::Bind(completion_callback_, | 38 base::Bind(completion_callback_, |
| 38 base::Passed(metadata.Pass()), str)); | 39 base::Passed(std::move(metadata)), str)); |
| 39 } | 40 } |
| 40 | 41 |
| 41 private: | 42 private: |
| 42 ~StringTraceDataEndpoint() override {} | 43 ~StringTraceDataEndpoint() override {} |
| 43 | 44 |
| 44 CompletionCallback completion_callback_; | 45 CompletionCallback completion_callback_; |
| 45 | 46 |
| 46 DISALLOW_COPY_AND_ASSIGN(StringTraceDataEndpoint); | 47 DISALLOW_COPY_AND_ASSIGN(StringTraceDataEndpoint); |
| 47 }; | 48 }; |
| 48 | 49 |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 } | 319 } |
| 319 | 320 |
| 320 void TracingController::TraceDataSink::SetMetadataFilterPredicate( | 321 void TracingController::TraceDataSink::SetMetadataFilterPredicate( |
| 321 const MetadataFilterPredicate& metadata_filter_predicate) { | 322 const MetadataFilterPredicate& metadata_filter_predicate) { |
| 322 metadata_filter_predicate_ = metadata_filter_predicate; | 323 metadata_filter_predicate_ = metadata_filter_predicate; |
| 323 } | 324 } |
| 324 | 325 |
| 325 scoped_ptr<const base::DictionaryValue> | 326 scoped_ptr<const base::DictionaryValue> |
| 326 TracingController::TraceDataSink::GetMetadataCopy() const { | 327 TracingController::TraceDataSink::GetMetadataCopy() const { |
| 327 if (metadata_filter_predicate_.is_null()) | 328 if (metadata_filter_predicate_.is_null()) |
| 328 return scoped_ptr<const base::DictionaryValue>(metadata_.DeepCopy()).Pass(); | 329 return scoped_ptr<const base::DictionaryValue>(metadata_.DeepCopy()); |
| 329 | 330 |
| 330 scoped_ptr<base::DictionaryValue> metadata_copy(new base::DictionaryValue); | 331 scoped_ptr<base::DictionaryValue> metadata_copy(new base::DictionaryValue); |
| 331 for (base::DictionaryValue::Iterator it(metadata_); !it.IsAtEnd(); | 332 for (base::DictionaryValue::Iterator it(metadata_); !it.IsAtEnd(); |
| 332 it.Advance()) { | 333 it.Advance()) { |
| 333 if (metadata_filter_predicate_.Run(it.key())) | 334 if (metadata_filter_predicate_.Run(it.key())) |
| 334 metadata_copy->Set(it.key(), it.value().DeepCopy()); | 335 metadata_copy->Set(it.key(), it.value().DeepCopy()); |
| 335 else | 336 else |
| 336 metadata_copy->SetString(it.key(), "__stripped__"); | 337 metadata_copy->SetString(it.key(), "__stripped__"); |
| 337 } | 338 } |
| 338 return metadata_copy.Pass(); | 339 return std::move(metadata_copy); |
| 339 } | 340 } |
| 340 | 341 |
| 341 scoped_refptr<TracingController::TraceDataSink> | 342 scoped_refptr<TracingController::TraceDataSink> |
| 342 TracingController::CreateStringSink( | 343 TracingController::CreateStringSink( |
| 343 const base::Callback<void(scoped_ptr<const base::DictionaryValue>, | 344 const base::Callback<void(scoped_ptr<const base::DictionaryValue>, |
| 344 base::RefCountedString*)>& callback) { | 345 base::RefCountedString*)>& callback) { |
| 345 return new StringTraceDataSink(new StringTraceDataEndpoint(callback)); | 346 return new StringTraceDataSink(new StringTraceDataEndpoint(callback)); |
| 346 } | 347 } |
| 347 | 348 |
| 348 scoped_refptr<TracingController::TraceDataSink> | 349 scoped_refptr<TracingController::TraceDataSink> |
| (...skipping 16 matching lines...) Expand all Loading... |
| 365 return new StringTraceDataEndpoint(callback); | 366 return new StringTraceDataEndpoint(callback); |
| 366 } | 367 } |
| 367 | 368 |
| 368 scoped_refptr<TracingController::TraceDataEndpoint> | 369 scoped_refptr<TracingController::TraceDataEndpoint> |
| 369 TracingController::CreateFileEndpoint(const base::FilePath& file_path, | 370 TracingController::CreateFileEndpoint(const base::FilePath& file_path, |
| 370 const base::Closure& callback) { | 371 const base::Closure& callback) { |
| 371 return new FileTraceDataEndpoint(file_path, callback); | 372 return new FileTraceDataEndpoint(file_path, callback); |
| 372 } | 373 } |
| 373 | 374 |
| 374 } // namespace content | 375 } // namespace content |
| OLD | NEW |