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

Side by Side Diff: content/browser/tracing/tracing_controller_impl_data_sinks.cc

Issue 1874893002: Convert //content/browser from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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 unified diff | Download patch
OLDNEW
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 <utility> 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/browser/tracing/tracing_controller_impl.h"
12 #include "content/public/browser/browser_thread.h" 12 #include "content/public/browser/browser_thread.h"
13 #include "third_party/zlib/zlib.h" 13 #include "third_party/zlib/zlib.h"
14 14
15 namespace content { 15 namespace content {
16 16
17 namespace { 17 namespace {
18 18
19 const char kChromeTraceLabel[] = "traceEvents"; 19 const char kChromeTraceLabel[] = "traceEvents";
20 const char kMetadataTraceLabel[] = "metadata"; 20 const char kMetadataTraceLabel[] = "metadata";
21 21
22 class StringTraceDataEndpoint : public TracingController::TraceDataEndpoint { 22 class StringTraceDataEndpoint : public TracingController::TraceDataEndpoint {
23 public: 23 public:
24 typedef base::Callback<void(scoped_ptr<const base::DictionaryValue>, 24 typedef base::Callback<void(std::unique_ptr<const base::DictionaryValue>,
25 base::RefCountedString*)> CompletionCallback; 25 base::RefCountedString*)>
26 CompletionCallback;
26 27
27 explicit StringTraceDataEndpoint(CompletionCallback callback) 28 explicit StringTraceDataEndpoint(CompletionCallback callback)
28 : completion_callback_(callback) {} 29 : completion_callback_(callback) {}
29 30
30 void ReceiveTraceFinalContents( 31 void ReceiveTraceFinalContents(
31 scoped_ptr<const base::DictionaryValue> metadata, 32 std::unique_ptr<const base::DictionaryValue> metadata,
32 const std::string& contents) override { 33 const std::string& contents) override {
33 std::string tmp = contents; 34 std::string tmp = contents;
34 scoped_refptr<base::RefCountedString> str = 35 scoped_refptr<base::RefCountedString> str =
35 base::RefCountedString::TakeString(&tmp); 36 base::RefCountedString::TakeString(&tmp);
36 37
37 BrowserThread::PostTask( 38 BrowserThread::PostTask(
38 BrowserThread::UI, FROM_HERE, 39 BrowserThread::UI, FROM_HERE,
39 base::Bind(completion_callback_, base::Passed(std::move(metadata)), 40 base::Bind(completion_callback_, base::Passed(std::move(metadata)),
40 base::RetainedRef(str))); 41 base::RetainedRef(str)));
41 } 42 }
(...skipping 17 matching lines...) Expand all
59 void ReceiveTraceChunk(const std::string& chunk) override { 60 void ReceiveTraceChunk(const std::string& chunk) override {
60 std::string tmp = chunk; 61 std::string tmp = chunk;
61 scoped_refptr<base::RefCountedString> chunk_ptr = 62 scoped_refptr<base::RefCountedString> chunk_ptr =
62 base::RefCountedString::TakeString(&tmp); 63 base::RefCountedString::TakeString(&tmp);
63 BrowserThread::PostTask( 64 BrowserThread::PostTask(
64 BrowserThread::FILE, FROM_HERE, 65 BrowserThread::FILE, FROM_HERE,
65 base::Bind(&FileTraceDataEndpoint::ReceiveTraceChunkOnFileThread, this, 66 base::Bind(&FileTraceDataEndpoint::ReceiveTraceChunkOnFileThread, this,
66 chunk_ptr)); 67 chunk_ptr));
67 } 68 }
68 69
69 void ReceiveTraceFinalContents( 70 void ReceiveTraceFinalContents(std::unique_ptr<const base::DictionaryValue>,
70 scoped_ptr<const base::DictionaryValue> , 71 const std::string& contents) override {
71 const std::string& contents) override {
72 BrowserThread::PostTask( 72 BrowserThread::PostTask(
73 BrowserThread::FILE, FROM_HERE, 73 BrowserThread::FILE, FROM_HERE,
74 base::Bind(&FileTraceDataEndpoint::CloseOnFileThread, this)); 74 base::Bind(&FileTraceDataEndpoint::CloseOnFileThread, this));
75 } 75 }
76 76
77 private: 77 private:
78 ~FileTraceDataEndpoint() override { DCHECK(file_ == NULL); } 78 ~FileTraceDataEndpoint() override { DCHECK(file_ == NULL); }
79 79
80 void ReceiveTraceChunkOnFileThread( 80 void ReceiveTraceChunkOnFileThread(
81 const scoped_refptr<base::RefCountedString> chunk) { 81 const scoped_refptr<base::RefCountedString> chunk) {
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 AddTraceChunkAndCompressOnFileThread("}", true); 281 AddTraceChunkAndCompressOnFileThread("}", true);
282 282
283 deflateEnd(stream_.get()); 283 deflateEnd(stream_.get());
284 stream_.reset(); 284 stream_.reset();
285 285
286 endpoint_->ReceiveTraceFinalContents(GetMetadataCopy(), 286 endpoint_->ReceiveTraceFinalContents(GetMetadataCopy(),
287 compressed_trace_data_); 287 compressed_trace_data_);
288 } 288 }
289 289
290 scoped_refptr<TracingController::TraceDataEndpoint> endpoint_; 290 scoped_refptr<TracingController::TraceDataEndpoint> endpoint_;
291 scoped_ptr<z_stream> stream_; 291 std::unique_ptr<z_stream> stream_;
292 bool already_tried_open_; 292 bool already_tried_open_;
293 std::string compressed_trace_data_; 293 std::string compressed_trace_data_;
294 294
295 DISALLOW_COPY_AND_ASSIGN(CompressedStringTraceDataSink); 295 DISALLOW_COPY_AND_ASSIGN(CompressedStringTraceDataSink);
296 }; 296 };
297 297
298 } // namespace 298 } // namespace
299 299
300 TracingController::TraceDataSink::TraceDataSink() {} 300 TracingController::TraceDataSink::TraceDataSink() {}
301 301
(...skipping 15 matching lines...) Expand all
317 void TracingController::TraceDataSink::AddMetadata( 317 void TracingController::TraceDataSink::AddMetadata(
318 const base::DictionaryValue& data) { 318 const base::DictionaryValue& data) {
319 metadata_.MergeDictionary(&data); 319 metadata_.MergeDictionary(&data);
320 } 320 }
321 321
322 void TracingController::TraceDataSink::SetMetadataFilterPredicate( 322 void TracingController::TraceDataSink::SetMetadataFilterPredicate(
323 const MetadataFilterPredicate& metadata_filter_predicate) { 323 const MetadataFilterPredicate& metadata_filter_predicate) {
324 metadata_filter_predicate_ = metadata_filter_predicate; 324 metadata_filter_predicate_ = metadata_filter_predicate;
325 } 325 }
326 326
327 scoped_ptr<const base::DictionaryValue> 327 std::unique_ptr<const base::DictionaryValue>
328 TracingController::TraceDataSink::GetMetadataCopy() const { 328 TracingController::TraceDataSink::GetMetadataCopy() const {
329 if (metadata_filter_predicate_.is_null()) 329 if (metadata_filter_predicate_.is_null())
330 return scoped_ptr<const base::DictionaryValue>(metadata_.DeepCopy()); 330 return std::unique_ptr<const base::DictionaryValue>(metadata_.DeepCopy());
331 331
332 scoped_ptr<base::DictionaryValue> metadata_copy(new base::DictionaryValue); 332 std::unique_ptr<base::DictionaryValue> metadata_copy(
333 new base::DictionaryValue);
333 for (base::DictionaryValue::Iterator it(metadata_); !it.IsAtEnd(); 334 for (base::DictionaryValue::Iterator it(metadata_); !it.IsAtEnd();
334 it.Advance()) { 335 it.Advance()) {
335 if (metadata_filter_predicate_.Run(it.key())) 336 if (metadata_filter_predicate_.Run(it.key()))
336 metadata_copy->Set(it.key(), it.value().DeepCopy()); 337 metadata_copy->Set(it.key(), it.value().DeepCopy());
337 else 338 else
338 metadata_copy->SetString(it.key(), "__stripped__"); 339 metadata_copy->SetString(it.key(), "__stripped__");
339 } 340 }
340 return std::move(metadata_copy); 341 return std::move(metadata_copy);
341 } 342 }
342 343
343 scoped_refptr<TracingController::TraceDataSink> 344 scoped_refptr<TracingController::TraceDataSink>
344 TracingController::CreateStringSink( 345 TracingController::CreateStringSink(
345 const base::Callback<void(scoped_ptr<const base::DictionaryValue>, 346 const base::Callback<void(std::unique_ptr<const base::DictionaryValue>,
346 base::RefCountedString*)>& callback) { 347 base::RefCountedString*)>& callback) {
347 return new StringTraceDataSink(new StringTraceDataEndpoint(callback)); 348 return new StringTraceDataSink(new StringTraceDataEndpoint(callback));
348 } 349 }
349 350
350 scoped_refptr<TracingController::TraceDataSink> 351 scoped_refptr<TracingController::TraceDataSink>
351 TracingController::CreateCompressedStringSink( 352 TracingController::CreateCompressedStringSink(
352 scoped_refptr<TracingController::TraceDataEndpoint> endpoint) { 353 scoped_refptr<TracingController::TraceDataEndpoint> endpoint) {
353 return new CompressedStringTraceDataSink(endpoint); 354 return new CompressedStringTraceDataSink(endpoint);
354 } 355 }
355 356
356 scoped_refptr<TracingController::TraceDataSink> 357 scoped_refptr<TracingController::TraceDataSink>
357 TracingController::CreateFileSink(const base::FilePath& file_path, 358 TracingController::CreateFileSink(const base::FilePath& file_path,
358 const base::Closure& callback) { 359 const base::Closure& callback) {
359 return new StringTraceDataSink( 360 return new StringTraceDataSink(
360 CreateFileEndpoint(file_path, callback)); 361 CreateFileEndpoint(file_path, callback));
361 } 362 }
362 363
363 scoped_refptr<TracingController::TraceDataEndpoint> 364 scoped_refptr<TracingController::TraceDataEndpoint>
364 TracingController::CreateCallbackEndpoint(const base::Callback< 365 TracingController::CreateCallbackEndpoint(
365 void(scoped_ptr<const base::DictionaryValue>, 366 const base::Callback<void(std::unique_ptr<const base::DictionaryValue>,
366 base::RefCountedString*)>& callback) { 367 base::RefCountedString*)>& callback) {
367 return new StringTraceDataEndpoint(callback); 368 return new StringTraceDataEndpoint(callback);
368 } 369 }
369 370
370 scoped_refptr<TracingController::TraceDataEndpoint> 371 scoped_refptr<TracingController::TraceDataEndpoint>
371 TracingController::CreateFileEndpoint(const base::FilePath& file_path, 372 TracingController::CreateFileEndpoint(const base::FilePath& file_path,
372 const base::Closure& callback) { 373 const base::Closure& callback) {
373 return new FileTraceDataEndpoint(file_path, callback); 374 return new FileTraceDataEndpoint(file_path, callback);
374 } 375 }
375 376
376 } // namespace content 377 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/tracing/tracing_controller_impl.cc ('k') | content/browser/tracing/tracing_ui.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698