Commit 16f8dbce authored by yurys's avatar yurys Committed by Commit bot

DevTools: use explicit IPC messages for enabling/disabling tracing instead of...

DevTools: use explicit IPC messages for enabling/disabling tracing instead of intercepting protocol events

Added IPC plumbing that allows InspectorTracingAgent to enable/disable  browser-wide tracing. It was implemented by intercepting Tracing.started/Tracing.stopped events in the browser. Tracing.stopped event in the DevTools protocol was used by the renderer to notify the browser that it should stop trace event recording and it didn't make much sense for the client as there is already Tracing.tracingComplete event in the protocol.

BUG=398787

Committed: https://chromium.googlesource.com/chromium/src/+/a449adae35631e4791547bd0b14403d1766f9ddf

Review URL: https://codereview.chromium.org/511873002

Cr-Commit-Position: refs/heads/master@{#292578}
parent f4dc9d14
...@@ -178,15 +178,6 @@ DevToolsProtocol::Handler::HandleCommand( ...@@ -178,15 +178,6 @@ DevToolsProtocol::Handler::HandleCommand(
return (it->second).Run(command); return (it->second).Run(command);
} }
void DevToolsProtocol::Handler::HandleNotification(
scoped_refptr<DevToolsProtocol::Notification> notification) {
NotificationHandlers::iterator it =
notification_handlers_.find(notification->method());
if (it == notification_handlers_.end())
return;
(it->second).Run(notification);
}
void DevToolsProtocol::Handler::SetNotifier(const Notifier& notifier) { void DevToolsProtocol::Handler::SetNotifier(const Notifier& notifier) {
notifier_ = notifier; notifier_ = notifier;
} }
...@@ -200,12 +191,6 @@ void DevToolsProtocol::Handler::RegisterCommandHandler( ...@@ -200,12 +191,6 @@ void DevToolsProtocol::Handler::RegisterCommandHandler(
command_handlers_[command] = handler; command_handlers_[command] = handler;
} }
void DevToolsProtocol::Handler::RegisterNotificationHandler(
const std::string& notification,
const NotificationHandler& handler) {
notification_handlers_[notification] = handler;
}
void DevToolsProtocol::Handler::SendNotification( void DevToolsProtocol::Handler::SendNotification(
const std::string& method, const std::string& method,
base::DictionaryValue* params) { base::DictionaryValue* params) {
......
...@@ -127,18 +127,12 @@ class DevToolsProtocol { ...@@ -127,18 +127,12 @@ class DevToolsProtocol {
public: public:
typedef base::Callback<scoped_refptr<DevToolsProtocol::Response>( typedef base::Callback<scoped_refptr<DevToolsProtocol::Response>(
scoped_refptr<DevToolsProtocol::Command> command)> CommandHandler; scoped_refptr<DevToolsProtocol::Command> command)> CommandHandler;
typedef base::Callback<void(
scoped_refptr<DevToolsProtocol::Notification> notification)>
NotificationHandler;
virtual ~Handler(); virtual ~Handler();
virtual scoped_refptr<DevToolsProtocol::Response> HandleCommand( virtual scoped_refptr<DevToolsProtocol::Response> HandleCommand(
scoped_refptr<DevToolsProtocol::Command> command); scoped_refptr<DevToolsProtocol::Command> command);
virtual void HandleNotification(
scoped_refptr<DevToolsProtocol::Notification> notification);
void SetNotifier(const Notifier& notifier); void SetNotifier(const Notifier& notifier);
protected: protected:
...@@ -147,9 +141,6 @@ class DevToolsProtocol { ...@@ -147,9 +141,6 @@ class DevToolsProtocol {
void RegisterCommandHandler(const std::string& command, void RegisterCommandHandler(const std::string& command,
const CommandHandler& handler); const CommandHandler& handler);
void RegisterNotificationHandler(const std::string& notification,
const NotificationHandler& handler);
// Sends notification to the client. Takes ownership of |params|. // Sends notification to the client. Takes ownership of |params|.
void SendNotification(const std::string& method, void SendNotification(const std::string& method,
base::DictionaryValue* params); base::DictionaryValue* params);
...@@ -162,11 +153,9 @@ class DevToolsProtocol { ...@@ -162,11 +153,9 @@ class DevToolsProtocol {
private: private:
typedef std::map<std::string, CommandHandler> CommandHandlers; typedef std::map<std::string, CommandHandler> CommandHandlers;
typedef std::map<std::string, NotificationHandler> NotificationHandlers;
Notifier notifier_; Notifier notifier_;
CommandHandlers command_handlers_; CommandHandlers command_handlers_;
NotificationHandlers notification_handlers_;
DISALLOW_COPY_AND_ASSIGN(Handler); DISALLOW_COPY_AND_ASSIGN(Handler);
}; };
......
...@@ -65,12 +65,6 @@ DevToolsTracingHandler::DevToolsTracingHandler( ...@@ -65,12 +65,6 @@ DevToolsTracingHandler::DevToolsTracingHandler(
RegisterCommandHandler(devtools::Tracing::getCategories::kName, RegisterCommandHandler(devtools::Tracing::getCategories::kName,
base::Bind(&DevToolsTracingHandler::OnGetCategories, base::Bind(&DevToolsTracingHandler::OnGetCategories,
base::Unretained(this))); base::Unretained(this)));
RegisterNotificationHandler(devtools::Tracing::started::kName,
base::Bind(&DevToolsTracingHandler::OnTracingStarted,
base::Unretained(this)));
RegisterNotificationHandler(devtools::Tracing::stopped::kName,
base::Bind(&DevToolsTracingHandler::OnTracingStopped,
base::Unretained(this)));
} }
DevToolsTracingHandler::~DevToolsTracingHandler() { DevToolsTracingHandler::~DevToolsTracingHandler() {
...@@ -154,6 +148,11 @@ base::debug::TraceOptions DevToolsTracingHandler::TraceOptionsFromString( ...@@ -154,6 +148,11 @@ base::debug::TraceOptions DevToolsTracingHandler::TraceOptionsFromString(
scoped_refptr<DevToolsProtocol::Response> scoped_refptr<DevToolsProtocol::Response>
DevToolsTracingHandler::OnStart( DevToolsTracingHandler::OnStart(
scoped_refptr<DevToolsProtocol::Command> command) { scoped_refptr<DevToolsProtocol::Command> command) {
// If inspected target is a render process Tracing.start will be handled by
// tracing agent in the renderer.
if (target_ == Renderer)
return NULL;
is_recording_ = true; is_recording_ = true;
std::string categories; std::string categories;
...@@ -175,16 +174,6 @@ DevToolsTracingHandler::OnStart( ...@@ -175,16 +174,6 @@ DevToolsTracingHandler::OnStart(
SetupTimer(usage_reporting_interval); SetupTimer(usage_reporting_interval);
// If inspected target is a render process Tracing.start will be handled by
// tracing agent in the renderer.
if (target_ == Renderer) {
TracingController::GetInstance()->EnableRecording(
base::debug::CategoryFilter(categories),
options,
TracingController::EnableRecordingDoneCallback());
return NULL;
}
TracingController::GetInstance()->EnableRecording( TracingController::GetInstance()->EnableRecording(
base::debug::CategoryFilter(categories), base::debug::CategoryFilter(categories),
options, options,
...@@ -228,6 +217,10 @@ void DevToolsTracingHandler::OnBufferUsage(float usage) { ...@@ -228,6 +217,10 @@ void DevToolsTracingHandler::OnBufferUsage(float usage) {
scoped_refptr<DevToolsProtocol::Response> scoped_refptr<DevToolsProtocol::Response>
DevToolsTracingHandler::OnEnd( DevToolsTracingHandler::OnEnd(
scoped_refptr<DevToolsProtocol::Command> command) { scoped_refptr<DevToolsProtocol::Command> command) {
// If inspected target is a render process Tracing.end will be handled by
// tracing agent in the renderer.
if (target_ == Renderer)
return NULL;
DisableRecording( DisableRecording(
base::Bind(&DevToolsTracingHandler::BeginReadingRecordingResult, base::Bind(&DevToolsTracingHandler::BeginReadingRecordingResult,
weak_factory_.GetWeakPtr())); weak_factory_.GetWeakPtr()));
...@@ -272,8 +265,7 @@ void DevToolsTracingHandler::OnCategoriesReceived( ...@@ -272,8 +265,7 @@ void DevToolsTracingHandler::OnCategoriesReceived(
SendAsyncResponse(command->SuccessResponse(response)); SendAsyncResponse(command->SuccessResponse(response));
} }
void DevToolsTracingHandler::OnTracingStarted( void DevToolsTracingHandler::EnableTracing(const std::string& category_filter) {
scoped_refptr<DevToolsProtocol::Notification> notification) {
if (is_recording_) if (is_recording_)
return; return;
is_recording_ = true; is_recording_ = true;
...@@ -281,13 +273,13 @@ void DevToolsTracingHandler::OnTracingStarted( ...@@ -281,13 +273,13 @@ void DevToolsTracingHandler::OnTracingStarted(
SetupTimer(kDefaultReportingInterval); SetupTimer(kDefaultReportingInterval);
TracingController::GetInstance()->EnableRecording( TracingController::GetInstance()->EnableRecording(
base::debug::CategoryFilter(kDefaultCategories), base::debug::CategoryFilter(category_filter),
base::debug::TraceOptions(), base::debug::TraceOptions(),
TracingController::EnableRecordingDoneCallback()); TracingController::EnableRecordingDoneCallback());
SendNotification(devtools::Tracing::started::kName, NULL);
} }
void DevToolsTracingHandler::OnTracingStopped( void DevToolsTracingHandler::DisableTracing() {
scoped_refptr<DevToolsProtocol::Notification> notification) {
if (!is_recording_) if (!is_recording_)
return; return;
is_recording_ = false; is_recording_ = false;
......
...@@ -30,6 +30,9 @@ class DevToolsTracingHandler : public DevToolsProtocol::Handler { ...@@ -30,6 +30,9 @@ class DevToolsTracingHandler : public DevToolsProtocol::Handler {
void OnClientDetached(); void OnClientDetached();
void EnableTracing(const std::string& category_filter);
void DisableTracing();
private: private:
void BeginReadingRecordingResult(const base::FilePath& path); void BeginReadingRecordingResult(const base::FilePath& path);
void ReadRecordingResult(const scoped_refptr<base::RefCountedString>& result); void ReadRecordingResult(const scoped_refptr<base::RefCountedString>& result);
...@@ -45,12 +48,6 @@ class DevToolsTracingHandler : public DevToolsProtocol::Handler { ...@@ -45,12 +48,6 @@ class DevToolsTracingHandler : public DevToolsProtocol::Handler {
scoped_refptr<DevToolsProtocol::Response> OnGetCategories( scoped_refptr<DevToolsProtocol::Response> OnGetCategories(
scoped_refptr<DevToolsProtocol::Command> command); scoped_refptr<DevToolsProtocol::Command> command);
void OnTracingStarted(
scoped_refptr<DevToolsProtocol::Notification> notification);
void OnTracingStopped(
scoped_refptr<DevToolsProtocol::Notification> notification);
void OnCategoriesReceived(scoped_refptr<DevToolsProtocol::Command> command, void OnCategoriesReceived(scoped_refptr<DevToolsProtocol::Command> command,
const std::set<std::string>& category_set); const std::set<std::string>& category_set);
......
...@@ -441,6 +441,8 @@ bool RenderViewDevToolsAgentHost::DispatchIPCMessage( ...@@ -441,6 +441,8 @@ bool RenderViewDevToolsAgentHost::DispatchIPCMessage(
OnDispatchOnInspectorFrontend) OnDispatchOnInspectorFrontend)
IPC_MESSAGE_HANDLER(DevToolsHostMsg_SaveAgentRuntimeState, IPC_MESSAGE_HANDLER(DevToolsHostMsg_SaveAgentRuntimeState,
OnSaveAgentRuntimeState) OnSaveAgentRuntimeState)
IPC_MESSAGE_HANDLER(DevToolsHostMsg_EnableTracing, OnEnableTracing)
IPC_MESSAGE_HANDLER(DevToolsHostMsg_DisableTracing, OnDisableTracing)
IPC_MESSAGE_HANDLER_GENERIC(ViewHostMsg_SwapCompositorFrame, IPC_MESSAGE_HANDLER_GENERIC(ViewHostMsg_SwapCompositorFrame,
handled = false; OnSwapCompositorFrame(msg)) handled = false; OnSwapCompositorFrame(msg))
IPC_MESSAGE_UNHANDLED(handled = false) IPC_MESSAGE_UNHANDLED(handled = false)
...@@ -474,14 +476,16 @@ void RenderViewDevToolsAgentHost::OnDispatchOnInspectorFrontend( ...@@ -474,14 +476,16 @@ void RenderViewDevToolsAgentHost::OnDispatchOnInspectorFrontend(
const std::string& message) { const std::string& message) {
if (!render_view_host_) if (!render_view_host_)
return; return;
SendMessageToClient(message);
}
scoped_refptr<DevToolsProtocol::Notification> notification = void RenderViewDevToolsAgentHost::OnEnableTracing(
DevToolsProtocol::ParseNotification(message); const std::string& category_filter) {
tracing_handler_->EnableTracing(category_filter);
}
if (notification.get()) { void RenderViewDevToolsAgentHost::OnDisableTracing() {
tracing_handler_->HandleNotification(notification); tracing_handler_->DisableTracing();
}
SendMessageToClient(message);
} }
} // namespace content } // namespace content
...@@ -97,6 +97,8 @@ class CONTENT_EXPORT RenderViewDevToolsAgentHost ...@@ -97,6 +97,8 @@ class CONTENT_EXPORT RenderViewDevToolsAgentHost
void OnDispatchOnInspectorFrontend(const std::string& message); void OnDispatchOnInspectorFrontend(const std::string& message);
void OnSaveAgentRuntimeState(const std::string& state); void OnSaveAgentRuntimeState(const std::string& state);
void OnEnableTracing(const std::string& category_filter);
void OnDisableTracing();
void ClientDetachedFromRenderer(); void ClientDetachedFromRenderer();
......
...@@ -114,6 +114,13 @@ IPC_MESSAGE_ROUTED1(DevToolsHostMsg_DispatchOnEmbedder, ...@@ -114,6 +114,13 @@ IPC_MESSAGE_ROUTED1(DevToolsHostMsg_DispatchOnEmbedder,
IPC_MESSAGE_ROUTED1(DevToolsHostMsg_SaveAgentRuntimeState, IPC_MESSAGE_ROUTED1(DevToolsHostMsg_SaveAgentRuntimeState,
std::string /* state */) std::string /* state */)
// Tells the host to enable trace event recording.
IPC_MESSAGE_ROUTED1(DevToolsHostMsg_EnableTracing,
std::string /* category_filter */)
// Tells the host to disable trace event recording.
IPC_MESSAGE_ROUTED0(DevToolsHostMsg_DisableTracing)
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// These are messages sent from the GPU process to the inspected renderer. // These are messages sent from the GPU process to the inspected renderer.
......
...@@ -171,6 +171,7 @@ void DevToolsAgent::setTraceEventCallback(const WebString& category_filter, ...@@ -171,6 +171,7 @@ void DevToolsAgent::setTraceEventCallback(const WebString& category_filter,
} }
void DevToolsAgent::enableTracing(const WebString& category_filter) { void DevToolsAgent::enableTracing(const WebString& category_filter) {
Send(new DevToolsHostMsg_EnableTracing(routing_id(), category_filter.utf8()));
TraceLog* trace_log = TraceLog::GetInstance(); TraceLog* trace_log = TraceLog::GetInstance();
trace_log->SetEnabled(base::debug::CategoryFilter(category_filter.utf8()), trace_log->SetEnabled(base::debug::CategoryFilter(category_filter.utf8()),
TraceLog::RECORDING_MODE, TraceLog::RECORDING_MODE,
...@@ -179,6 +180,7 @@ void DevToolsAgent::enableTracing(const WebString& category_filter) { ...@@ -179,6 +180,7 @@ void DevToolsAgent::enableTracing(const WebString& category_filter) {
void DevToolsAgent::disableTracing() { void DevToolsAgent::disableTracing() {
TraceLog::GetInstance()->SetDisabled(); TraceLog::GetInstance()->SetDisabled();
Send(new DevToolsHostMsg_DisableTracing(routing_id()));
} }
// static // static
......
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