Commit 2fe929b1 authored by caseq's avatar caseq Committed by Commit bot

Clean up public TracingController interface

This removes trace endpoints from the content interface and moves them
to TracingControllerImpl. We don't want to expose both TraceDataSinks
and TraceEndpoints currently to avoid confusion.

Review-Url: https://codereview.chromium.org/2052773002
Cr-Commit-Position: refs/heads/master@{#405272}
parent 63bf1fba
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "content/browser/tracing/background_tracing_rule.h" #include "content/browser/tracing/background_tracing_rule.h"
#include "content/browser/tracing/tracing_controller_impl.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/browser/content_browser_client.h" #include "content/public/browser/content_browser_client.h"
#include "content/public/browser/tracing_delegate.h" #include "content/public/browser/tracing_delegate.h"
...@@ -506,8 +507,8 @@ void BackgroundTracingManagerImpl::BeginFinalizing( ...@@ -506,8 +507,8 @@ void BackgroundTracingManagerImpl::BeginFinalizing(
scoped_refptr<TracingControllerImpl::TraceDataSink> trace_data_sink; scoped_refptr<TracingControllerImpl::TraceDataSink> trace_data_sink;
if (is_allowed_finalization) { if (is_allowed_finalization) {
trace_data_sink = content::TracingController::CreateCompressedStringSink( trace_data_sink = TracingControllerImpl::CreateCompressedStringSink(
content::TracingController::CreateCallbackEndpoint( TracingControllerImpl::CreateCallbackEndpoint(
base::Bind(&BackgroundTracingManagerImpl::OnFinalizeStarted, base::Bind(&BackgroundTracingManagerImpl::OnFinalizeStarted,
base::Unretained(this)))); base::Unretained(this))));
RecordBackgroundTracingMetric(FINALIZATION_ALLOWED); RecordBackgroundTracingMetric(FINALIZATION_ALLOWED);
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/strings/pattern.h" #include "base/strings/pattern.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "content/browser/tracing/tracing_controller_impl.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/test/browser_test_utils.h" #include "content/public/test/browser_test_utils.h"
#include "content/public/test/content_browser_test.h" #include "content/public/test/content_browser_test.h"
...@@ -55,8 +56,7 @@ bool IsTraceEventArgsWhitelisted( ...@@ -55,8 +56,7 @@ bool IsTraceEventArgsWhitelisted(
} // namespace } // namespace
class TracingControllerTestEndpoint class TracingControllerTestEndpoint : public TraceDataEndpoint {
: public TracingController::TraceDataEndpoint {
public: public:
TracingControllerTestEndpoint( TracingControllerTestEndpoint(
base::Callback<void(std::unique_ptr<const base::DictionaryValue>, base::Callback<void(std::unique_ptr<const base::DictionaryValue>,
...@@ -271,7 +271,7 @@ class TracingControllerTest : public ContentBrowserTest { ...@@ -271,7 +271,7 @@ class TracingControllerTest : public ContentBrowserTest {
&TracingControllerTest::StopTracingStringDoneCallbackTest, &TracingControllerTest::StopTracingStringDoneCallbackTest,
base::Unretained(this), run_loop.QuitClosure()); base::Unretained(this), run_loop.QuitClosure());
bool result = controller->StopTracing( bool result = controller->StopTracing(
TracingController::CreateCompressedStringSink( TracingControllerImpl::CreateCompressedStringSink(
new TracingControllerTestEndpoint(callback))); new TracingControllerTestEndpoint(callback)));
ASSERT_TRUE(result); ASSERT_TRUE(result);
run_loop.Run(); run_loop.Run();
...@@ -302,9 +302,9 @@ class TracingControllerTest : public ContentBrowserTest { ...@@ -302,9 +302,9 @@ class TracingControllerTest : public ContentBrowserTest {
&TracingControllerTest::StopTracingFileDoneCallbackTest, &TracingControllerTest::StopTracingFileDoneCallbackTest,
base::Unretained(this), run_loop.QuitClosure(), result_file_path); base::Unretained(this), run_loop.QuitClosure(), result_file_path);
bool result = controller->StopTracing( bool result = controller->StopTracing(
TracingController::CreateCompressedStringSink( TracingControllerImpl::CreateCompressedStringSink(
TracingController::CreateFileEndpoint(result_file_path, TracingControllerImpl::CreateFileEndpoint(result_file_path,
callback))); callback)));
ASSERT_TRUE(result); ASSERT_TRUE(result);
run_loop.Run(); run_loop.Run();
EXPECT_EQ(disable_recording_done_callback_count(), 1); EXPECT_EQ(disable_recording_done_callback_count(), 1);
......
...@@ -30,11 +30,42 @@ namespace content { ...@@ -30,11 +30,42 @@ namespace content {
class TraceMessageFilter; class TraceMessageFilter;
class TracingUI; class TracingUI;
// An implementation of this interface is passed when constructing a
// TraceDataSink, and receives chunks of the final trace data as it's being
// constructed.
// Methods may be called from any thread.
class TraceDataEndpoint : public base::RefCountedThreadSafe<TraceDataEndpoint> {
public:
virtual void ReceiveTraceChunk(const std::string& chunk) {}
virtual void ReceiveTraceFinalContents(
std::unique_ptr<const base::DictionaryValue> metadata,
const std::string& contents) {}
protected:
friend class base::RefCountedThreadSafe<TraceDataEndpoint>;
virtual ~TraceDataEndpoint() {}
};
class TracingControllerImpl class TracingControllerImpl
: public TracingController, : public TracingController,
public base::trace_event::MemoryDumpManagerDelegate, public base::trace_event::MemoryDumpManagerDelegate,
public base::trace_event::TracingAgent { public base::trace_event::TracingAgent {
public: public:
// Create an endpoint that may be supplied to any TraceDataSink to
// dump the trace data to a callback.
CONTENT_EXPORT static scoped_refptr<TraceDataEndpoint> CreateCallbackEndpoint(
const base::Callback<void(std::unique_ptr<const base::DictionaryValue>,
base::RefCountedString*)>& callback);
// Create an endpoint that may be supplied to any TraceDataSink to
// dump the trace data to a file.
CONTENT_EXPORT static scoped_refptr<TraceDataEndpoint> CreateFileEndpoint(
const base::FilePath& file_path,
const base::Closure& callback);
CONTENT_EXPORT static scoped_refptr<TraceDataSink> CreateCompressedStringSink(
scoped_refptr<TraceDataEndpoint> endpoint);
static TracingControllerImpl* GetInstance(); static TracingControllerImpl* GetInstance();
// TracingController implementation. // TracingController implementation.
......
...@@ -19,7 +19,7 @@ namespace { ...@@ -19,7 +19,7 @@ namespace {
const char kChromeTraceLabel[] = "traceEvents"; const char kChromeTraceLabel[] = "traceEvents";
const char kMetadataTraceLabel[] = "metadata"; const char kMetadataTraceLabel[] = "metadata";
class StringTraceDataEndpoint : public TracingController::TraceDataEndpoint { class StringTraceDataEndpoint : public TraceDataEndpoint {
public: public:
typedef base::Callback<void(std::unique_ptr<const base::DictionaryValue>, typedef base::Callback<void(std::unique_ptr<const base::DictionaryValue>,
base::RefCountedString*)> base::RefCountedString*)>
...@@ -49,7 +49,7 @@ class StringTraceDataEndpoint : public TracingController::TraceDataEndpoint { ...@@ -49,7 +49,7 @@ class StringTraceDataEndpoint : public TracingController::TraceDataEndpoint {
DISALLOW_COPY_AND_ASSIGN(StringTraceDataEndpoint); DISALLOW_COPY_AND_ASSIGN(StringTraceDataEndpoint);
}; };
class FileTraceDataEndpoint : public TracingController::TraceDataEndpoint { class FileTraceDataEndpoint : public TraceDataEndpoint {
public: public:
explicit FileTraceDataEndpoint(const base::FilePath& trace_file_path, explicit FileTraceDataEndpoint(const base::FilePath& trace_file_path,
const base::Closure& callback) const base::Closure& callback)
...@@ -117,8 +117,7 @@ class FileTraceDataEndpoint : public TracingController::TraceDataEndpoint { ...@@ -117,8 +117,7 @@ class FileTraceDataEndpoint : public TracingController::TraceDataEndpoint {
class StringTraceDataSink : public TracingController::TraceDataSink { class StringTraceDataSink : public TracingController::TraceDataSink {
public: public:
explicit StringTraceDataSink( explicit StringTraceDataSink(scoped_refptr<TraceDataEndpoint> endpoint)
scoped_refptr<TracingController::TraceDataEndpoint> endpoint)
: endpoint_(endpoint) {} : endpoint_(endpoint) {}
void AddTraceChunk(const std::string& chunk) override { void AddTraceChunk(const std::string& chunk) override {
...@@ -159,7 +158,7 @@ class StringTraceDataSink : public TracingController::TraceDataSink { ...@@ -159,7 +158,7 @@ class StringTraceDataSink : public TracingController::TraceDataSink {
private: private:
~StringTraceDataSink() override {} ~StringTraceDataSink() override {}
scoped_refptr<TracingController::TraceDataEndpoint> endpoint_; scoped_refptr<TraceDataEndpoint> endpoint_;
std::string trace_; std::string trace_;
DISALLOW_COPY_AND_ASSIGN(StringTraceDataSink); DISALLOW_COPY_AND_ASSIGN(StringTraceDataSink);
...@@ -168,7 +167,7 @@ class StringTraceDataSink : public TracingController::TraceDataSink { ...@@ -168,7 +167,7 @@ class StringTraceDataSink : public TracingController::TraceDataSink {
class CompressedStringTraceDataSink : public TracingController::TraceDataSink { class CompressedStringTraceDataSink : public TracingController::TraceDataSink {
public: public:
explicit CompressedStringTraceDataSink( explicit CompressedStringTraceDataSink(
scoped_refptr<TracingController::TraceDataEndpoint> endpoint) scoped_refptr<TraceDataEndpoint> endpoint)
: endpoint_(endpoint), already_tried_open_(false) {} : endpoint_(endpoint), already_tried_open_(false) {}
void AddTraceChunk(const std::string& chunk) override { void AddTraceChunk(const std::string& chunk) override {
...@@ -287,7 +286,7 @@ class CompressedStringTraceDataSink : public TracingController::TraceDataSink { ...@@ -287,7 +286,7 @@ class CompressedStringTraceDataSink : public TracingController::TraceDataSink {
compressed_trace_data_); compressed_trace_data_);
} }
scoped_refptr<TracingController::TraceDataEndpoint> endpoint_; scoped_refptr<TraceDataEndpoint> endpoint_;
std::unique_ptr<z_stream> stream_; std::unique_ptr<z_stream> stream_;
bool already_tried_open_; bool already_tried_open_;
std::string compressed_trace_data_; std::string compressed_trace_data_;
...@@ -349,8 +348,8 @@ TracingController::CreateStringSink( ...@@ -349,8 +348,8 @@ TracingController::CreateStringSink(
} }
scoped_refptr<TracingController::TraceDataSink> scoped_refptr<TracingController::TraceDataSink>
TracingController::CreateCompressedStringSink( TracingControllerImpl::CreateCompressedStringSink(
scoped_refptr<TracingController::TraceDataEndpoint> endpoint) { scoped_refptr<TraceDataEndpoint> endpoint) {
return new CompressedStringTraceDataSink(endpoint); return new CompressedStringTraceDataSink(endpoint);
} }
...@@ -358,19 +357,18 @@ scoped_refptr<TracingController::TraceDataSink> ...@@ -358,19 +357,18 @@ scoped_refptr<TracingController::TraceDataSink>
TracingController::CreateFileSink(const base::FilePath& file_path, TracingController::CreateFileSink(const base::FilePath& file_path,
const base::Closure& callback) { const base::Closure& callback) {
return new StringTraceDataSink( return new StringTraceDataSink(
CreateFileEndpoint(file_path, callback)); TracingControllerImpl::CreateFileEndpoint(file_path, callback));
} }
scoped_refptr<TracingController::TraceDataEndpoint> scoped_refptr<TraceDataEndpoint> TracingControllerImpl::CreateCallbackEndpoint(
TracingController::CreateCallbackEndpoint(
const base::Callback<void(std::unique_ptr<const base::DictionaryValue>, const base::Callback<void(std::unique_ptr<const base::DictionaryValue>,
base::RefCountedString*)>& callback) { base::RefCountedString*)>& callback) {
return new StringTraceDataEndpoint(callback); return new StringTraceDataEndpoint(callback);
} }
scoped_refptr<TracingController::TraceDataEndpoint> scoped_refptr<TraceDataEndpoint> TracingControllerImpl::CreateFileEndpoint(
TracingController::CreateFileEndpoint(const base::FilePath& file_path, const base::FilePath& file_path,
const base::Closure& callback) { const base::Closure& callback) {
return new FileTraceDataEndpoint(file_path, callback); return new FileTraceDataEndpoint(file_path, callback);
} }
......
...@@ -186,8 +186,8 @@ bool OnBeginJSONRequest(const std::string& path, ...@@ -186,8 +186,8 @@ bool OnBeginJSONRequest(const std::string& path,
} }
if (path == "json/end_recording_compressed") { if (path == "json/end_recording_compressed") {
scoped_refptr<TracingControllerImpl::TraceDataSink> data_sink = scoped_refptr<TracingControllerImpl::TraceDataSink> data_sink =
TracingController::CreateCompressedStringSink( TracingControllerImpl::CreateCompressedStringSink(
TracingController::CreateCallbackEndpoint( TracingControllerImpl::CreateCallbackEndpoint(
base::Bind(TracingCallbackWrapperBase64, callback))); base::Bind(TracingCallbackWrapperBase64, callback)));
AddCustomMetadata(data_sink.get()); AddCustomMetadata(data_sink.get());
return TracingController::GetInstance()->StopTracing(data_sink); return TracingController::GetInstance()->StopTracing(data_sink);
......
...@@ -74,50 +74,18 @@ class TracingController { ...@@ -74,50 +74,18 @@ class TracingController {
base::DictionaryValue metadata_; base::DictionaryValue metadata_;
}; };
// An implementation of this interface is passed when constructing a
// TraceDataSink, and receives chunks of the final trace data as it's being
// constructed.
// Methods may be called from any thread.
class CONTENT_EXPORT TraceDataEndpoint
: public base::RefCountedThreadSafe<TraceDataEndpoint> {
public:
virtual void ReceiveTraceChunk(const std::string& chunk) {}
virtual void ReceiveTraceFinalContents(
std::unique_ptr<const base::DictionaryValue> metadata,
const std::string& contents) {}
protected:
friend class base::RefCountedThreadSafe<TraceDataEndpoint>;
virtual ~TraceDataEndpoint() {}
};
// Create a trace sink that may be supplied to StopTracing // Create a trace sink that may be supplied to StopTracing
// to capture the trace data as a string. // to capture the trace data as a string.
CONTENT_EXPORT static scoped_refptr<TraceDataSink> CreateStringSink( CONTENT_EXPORT static scoped_refptr<TraceDataSink> CreateStringSink(
const base::Callback<void(std::unique_ptr<const base::DictionaryValue>, const base::Callback<void(std::unique_ptr<const base::DictionaryValue>,
base::RefCountedString*)>& callback); base::RefCountedString*)>& callback);
CONTENT_EXPORT static scoped_refptr<TraceDataSink> CreateCompressedStringSink(
scoped_refptr<TraceDataEndpoint> endpoint);
// Create a trace sink that may be supplied to StopTracing // Create a trace sink that may be supplied to StopTracing
// to dump the trace data to a file. // to dump the trace data to a file.
CONTENT_EXPORT static scoped_refptr<TraceDataSink> CreateFileSink( CONTENT_EXPORT static scoped_refptr<TraceDataSink> CreateFileSink(
const base::FilePath& file_path, const base::FilePath& file_path,
const base::Closure& callback); const base::Closure& callback);
// Create an endpoint that may be supplied to any TraceDataSink to
// dump the trace data to a callback.
CONTENT_EXPORT static scoped_refptr<TraceDataEndpoint> CreateCallbackEndpoint(
const base::Callback<void(std::unique_ptr<const base::DictionaryValue>,
base::RefCountedString*)>& callback);
// Create an endpoint that may be supplied to any TraceDataSink to
// dump the trace data to a file.
CONTENT_EXPORT static scoped_refptr<TraceDataEndpoint> CreateFileEndpoint(
const base::FilePath& file_path,
const base::Closure& callback);
// Get a set of category groups. The category groups can change as // Get a set of category groups. The category groups can change as
// new code paths are reached. // new code paths are reached.
// //
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment