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 @@
#include "base/threading/thread_task_runner_handle.h"
#include "base/time/time.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/content_browser_client.h"
#include "content/public/browser/tracing_delegate.h"
......@@ -506,8 +507,8 @@ void BackgroundTracingManagerImpl::BeginFinalizing(
scoped_refptr<TracingControllerImpl::TraceDataSink> trace_data_sink;
if (is_allowed_finalization) {
trace_data_sink = content::TracingController::CreateCompressedStringSink(
content::TracingController::CreateCallbackEndpoint(
trace_data_sink = TracingControllerImpl::CreateCompressedStringSink(
TracingControllerImpl::CreateCallbackEndpoint(
base::Bind(&BackgroundTracingManagerImpl::OnFinalizeStarted,
base::Unretained(this))));
RecordBackgroundTracingMetric(FINALIZATION_ALLOWED);
......
......@@ -12,6 +12,7 @@
#include "base/run_loop.h"
#include "base/strings/pattern.h"
#include "build/build_config.h"
#include "content/browser/tracing/tracing_controller_impl.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/content_browser_test.h"
......@@ -55,8 +56,7 @@ bool IsTraceEventArgsWhitelisted(
} // namespace
class TracingControllerTestEndpoint
: public TracingController::TraceDataEndpoint {
class TracingControllerTestEndpoint : public TraceDataEndpoint {
public:
TracingControllerTestEndpoint(
base::Callback<void(std::unique_ptr<const base::DictionaryValue>,
......@@ -271,7 +271,7 @@ class TracingControllerTest : public ContentBrowserTest {
&TracingControllerTest::StopTracingStringDoneCallbackTest,
base::Unretained(this), run_loop.QuitClosure());
bool result = controller->StopTracing(
TracingController::CreateCompressedStringSink(
TracingControllerImpl::CreateCompressedStringSink(
new TracingControllerTestEndpoint(callback)));
ASSERT_TRUE(result);
run_loop.Run();
......@@ -302,9 +302,9 @@ class TracingControllerTest : public ContentBrowserTest {
&TracingControllerTest::StopTracingFileDoneCallbackTest,
base::Unretained(this), run_loop.QuitClosure(), result_file_path);
bool result = controller->StopTracing(
TracingController::CreateCompressedStringSink(
TracingController::CreateFileEndpoint(result_file_path,
callback)));
TracingControllerImpl::CreateCompressedStringSink(
TracingControllerImpl::CreateFileEndpoint(result_file_path,
callback)));
ASSERT_TRUE(result);
run_loop.Run();
EXPECT_EQ(disable_recording_done_callback_count(), 1);
......
......@@ -30,11 +30,42 @@ namespace content {
class TraceMessageFilter;
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
: public TracingController,
public base::trace_event::MemoryDumpManagerDelegate,
public base::trace_event::TracingAgent {
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();
// TracingController implementation.
......
......@@ -19,7 +19,7 @@ namespace {
const char kChromeTraceLabel[] = "traceEvents";
const char kMetadataTraceLabel[] = "metadata";
class StringTraceDataEndpoint : public TracingController::TraceDataEndpoint {
class StringTraceDataEndpoint : public TraceDataEndpoint {
public:
typedef base::Callback<void(std::unique_ptr<const base::DictionaryValue>,
base::RefCountedString*)>
......@@ -49,7 +49,7 @@ class StringTraceDataEndpoint : public TracingController::TraceDataEndpoint {
DISALLOW_COPY_AND_ASSIGN(StringTraceDataEndpoint);
};
class FileTraceDataEndpoint : public TracingController::TraceDataEndpoint {
class FileTraceDataEndpoint : public TraceDataEndpoint {
public:
explicit FileTraceDataEndpoint(const base::FilePath& trace_file_path,
const base::Closure& callback)
......@@ -117,8 +117,7 @@ class FileTraceDataEndpoint : public TracingController::TraceDataEndpoint {
class StringTraceDataSink : public TracingController::TraceDataSink {
public:
explicit StringTraceDataSink(
scoped_refptr<TracingController::TraceDataEndpoint> endpoint)
explicit StringTraceDataSink(scoped_refptr<TraceDataEndpoint> endpoint)
: endpoint_(endpoint) {}
void AddTraceChunk(const std::string& chunk) override {
......@@ -159,7 +158,7 @@ class StringTraceDataSink : public TracingController::TraceDataSink {
private:
~StringTraceDataSink() override {}
scoped_refptr<TracingController::TraceDataEndpoint> endpoint_;
scoped_refptr<TraceDataEndpoint> endpoint_;
std::string trace_;
DISALLOW_COPY_AND_ASSIGN(StringTraceDataSink);
......@@ -168,7 +167,7 @@ class StringTraceDataSink : public TracingController::TraceDataSink {
class CompressedStringTraceDataSink : public TracingController::TraceDataSink {
public:
explicit CompressedStringTraceDataSink(
scoped_refptr<TracingController::TraceDataEndpoint> endpoint)
scoped_refptr<TraceDataEndpoint> endpoint)
: endpoint_(endpoint), already_tried_open_(false) {}
void AddTraceChunk(const std::string& chunk) override {
......@@ -287,7 +286,7 @@ class CompressedStringTraceDataSink : public TracingController::TraceDataSink {
compressed_trace_data_);
}
scoped_refptr<TracingController::TraceDataEndpoint> endpoint_;
scoped_refptr<TraceDataEndpoint> endpoint_;
std::unique_ptr<z_stream> stream_;
bool already_tried_open_;
std::string compressed_trace_data_;
......@@ -349,8 +348,8 @@ TracingController::CreateStringSink(
}
scoped_refptr<TracingController::TraceDataSink>
TracingController::CreateCompressedStringSink(
scoped_refptr<TracingController::TraceDataEndpoint> endpoint) {
TracingControllerImpl::CreateCompressedStringSink(
scoped_refptr<TraceDataEndpoint> endpoint) {
return new CompressedStringTraceDataSink(endpoint);
}
......@@ -358,19 +357,18 @@ scoped_refptr<TracingController::TraceDataSink>
TracingController::CreateFileSink(const base::FilePath& file_path,
const base::Closure& callback) {
return new StringTraceDataSink(
CreateFileEndpoint(file_path, callback));
TracingControllerImpl::CreateFileEndpoint(file_path, callback));
}
scoped_refptr<TracingController::TraceDataEndpoint>
TracingController::CreateCallbackEndpoint(
scoped_refptr<TraceDataEndpoint> TracingControllerImpl::CreateCallbackEndpoint(
const base::Callback<void(std::unique_ptr<const base::DictionaryValue>,
base::RefCountedString*)>& callback) {
return new StringTraceDataEndpoint(callback);
}
scoped_refptr<TracingController::TraceDataEndpoint>
TracingController::CreateFileEndpoint(const base::FilePath& file_path,
const base::Closure& callback) {
scoped_refptr<TraceDataEndpoint> TracingControllerImpl::CreateFileEndpoint(
const base::FilePath& file_path,
const base::Closure& callback) {
return new FileTraceDataEndpoint(file_path, callback);
}
......
......@@ -186,8 +186,8 @@ bool OnBeginJSONRequest(const std::string& path,
}
if (path == "json/end_recording_compressed") {
scoped_refptr<TracingControllerImpl::TraceDataSink> data_sink =
TracingController::CreateCompressedStringSink(
TracingController::CreateCallbackEndpoint(
TracingControllerImpl::CreateCompressedStringSink(
TracingControllerImpl::CreateCallbackEndpoint(
base::Bind(TracingCallbackWrapperBase64, callback)));
AddCustomMetadata(data_sink.get());
return TracingController::GetInstance()->StopTracing(data_sink);
......
......@@ -74,50 +74,18 @@ class TracingController {
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
// to capture the trace data as a string.
CONTENT_EXPORT static scoped_refptr<TraceDataSink> CreateStringSink(
const base::Callback<void(std::unique_ptr<const base::DictionaryValue>,
base::RefCountedString*)>& callback);
CONTENT_EXPORT static scoped_refptr<TraceDataSink> CreateCompressedStringSink(
scoped_refptr<TraceDataEndpoint> endpoint);
// Create a trace sink that may be supplied to StopTracing
// to dump the trace data to a file.
CONTENT_EXPORT static scoped_refptr<TraceDataSink> CreateFileSink(
const base::FilePath& file_path,
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
// 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