Commit 4ac95514 authored by Dmitry Gozman's avatar Dmitry Gozman Committed by Commit Bot

[DevTools] Use BigString for protocol responses

We can get rid of our custom chunking.

Bug: 776009
Change-Id: Ib5ffe7ce1e4e1b6758a5963c68fc0eedb9af8e41
Reviewed-on: https://chromium-review.googlesource.com/869191
Commit-Queue: Dmitry Gozman <dgozman@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#533333}
parent f1f55967
......@@ -196,33 +196,14 @@ void DevToolsSession::flushProtocolNotifications() {
}
void DevToolsSession::DispatchProtocolMessage(
blink::mojom::DevToolsMessageChunkPtr chunk) {
if (chunk->is_first && !response_message_buffer_.empty()) {
ReceivedBadMessage();
return;
}
response_message_buffer_ += std::move(chunk->data);
if (!chunk->is_last)
return;
if (!chunk->post_state.empty())
state_cookie_ = std::move(chunk->post_state);
waiting_for_response_messages_.erase(chunk->call_id);
std::string message;
message.swap(response_message_buffer_);
const std::string& message,
int call_id,
const base::Optional<std::string>& state) {
if (state.has_value())
state_cookie_ = state.value();
waiting_for_response_messages_.erase(call_id);
client_->DispatchProtocolMessage(agent_host_, message);
// |this| may be deleted at this point.
}
void DevToolsSession::ReceivedBadMessage() {
MojoConnectionDestroyed();
RenderProcessHost* process = RenderProcessHost::FromID(process_host_id_);
if (process) {
bad_message::ReceivedBadMessage(
process, bad_message::RFH_INCONSISTENT_DEVTOOLS_MESSAGE);
}
}
} // namespace content
......@@ -59,7 +59,6 @@ class DevToolsSession : public protocol::FrontendChannel,
private:
void SendResponse(std::unique_ptr<base::DictionaryValue> response);
void MojoConnectionDestroyed();
void ReceivedBadMessage();
void DispatchProtocolMessageToAgent(int call_id,
const std::string& method,
const std::string& message);
......@@ -74,7 +73,9 @@ class DevToolsSession : public protocol::FrontendChannel,
// blink::mojom::DevToolsSessionHost implementation.
void DispatchProtocolMessage(
blink::mojom::DevToolsMessageChunkPtr chunk) override;
const std::string& message,
int call_id,
const base::Optional<std::string>& state) override;
mojo::AssociatedBinding<blink::mojom::DevToolsSessionHost> binding_;
blink::mojom::DevToolsSessionAssociatedPtr session_ptr_;
......@@ -109,7 +110,6 @@ class DevToolsSession : public protocol::FrontendChannel,
// any of the waiting for response messages have been handled.
// Note that |state_cookie_| is not present only before first attach.
base::Optional<std::string> state_cookie_;
std::string response_message_buffer_;
base::WeakPtrFactory<DevToolsSession> weak_factory_;
};
......
......@@ -104,10 +104,6 @@ bool IsMainFrame(WebLocalFrameImpl* frame) {
return frame->ViewImpl() && !frame->Parent();
}
// TODO(dgozman): somehow get this from a mojo config.
// See kMaximumMojoMessageSize in services/service_manager/embedder/main.cc.
const size_t kMaxDevToolsMessageChunkSize = 128 * 1024 * 1024 / 8;
bool ShouldInterruptForMethod(const String& method) {
// Keep in sync with DevToolsSession::ShouldSendOnIO.
// TODO(dgozman): find a way to share this.
......@@ -365,22 +361,7 @@ void WebDevToolsAgentImpl::Session::SendProtocolMessage(int session_id,
// protocol response in any of them.
if (LayoutTestSupport::IsRunningLayoutTest() && call_id)
agent_->FlushProtocolNotifications();
bool single_chunk = response.length() < kMaxDevToolsMessageChunkSize;
for (size_t pos = 0; pos < response.length();
pos += kMaxDevToolsMessageChunkSize) {
mojom::blink::DevToolsMessageChunkPtr chunk =
mojom::blink::DevToolsMessageChunk::New();
chunk->is_first = pos == 0;
chunk->is_last = pos + kMaxDevToolsMessageChunkSize >= response.length();
chunk->call_id = chunk->is_last ? call_id : 0;
chunk->post_state =
chunk->is_last && !state.IsNull() ? state : g_empty_string;
chunk->data = single_chunk
? response
: response.Substring(pos, kMaxDevToolsMessageChunkSize);
host_ptr_->DispatchProtocolMessage(std::move(chunk));
}
host_ptr_->DispatchProtocolMessage(response, call_id, state);
}
void WebDevToolsAgentImpl::Session::DispatchProtocolMessageInternal(
......
......@@ -4,25 +4,16 @@
module blink.mojom;
import "mojo/public/mojom/base/big_string.mojom";
import "ui/gfx/geometry/mojo/geometry.mojom";
// Used to send large messages in chunks from session to a host.
struct DevToolsMessageChunk {
// Whether this is a first chunk in a message.
bool is_first;
// Whether this is a last chunk in a message.
bool is_last;
// Chunk data.
string data;
// Call id as defined in DevTools protocol, only comes for responses.
int32 call_id;
// State for future reattach, only comes for responses in a last chunk.
string post_state;
};
// Debugging interactions are defined in Remote Debugging Protocol.
// See https://chromedevtools.github.io/devtools-protocol/ for more
// information on the protocol itself.
//
// All interfaces defined here serve as a transport level for the
// remote debugging protocol, passing messages opaquely between debugging
// client (like DevTools frontend) and debugging agent (like core/inspector).
// Implemented by debugging targets which expose remote debugging protocol.
// Examples are local frame roots and service workers.
......@@ -48,7 +39,7 @@ interface DevToolsAgent {
// regular |session|.
//
// If |reattach_state| is present, restores the state of the session to
// previously saved one (see DevToolsMessageChunk). This is useful when
// previously saved one (see DevToolsSessionHost). This is useful when
// transferring a session from one agent to another while preserving the
// state. For example, cross-process navigation in a frame creates a new
// DevToolsAgent (in a different process), but we can preserve the state of
......@@ -89,7 +80,7 @@ interface DevToolsSession {
// Dispatches protocol message from a client to a debugging target.
// |method| is a method name as defined in protocol (e.g. "Runtime.evaluate").
// |call_id| is a command id as defined in protocol, and is going to be
// reported back to host in a response message (see DevToolsMessageChunk).
// reported back to host in a response message (see DevToolsSessionHost).
DispatchProtocolMessage(int32 call_id, string method, string message);
};
......@@ -97,6 +88,12 @@ interface DevToolsSession {
// which receives notifications and responses from a session.
// This interface is implemented in browser.
interface DevToolsSessionHost {
// Dispatches protocol message (in chunks) to a remote debugging client.
DispatchProtocolMessage(DevToolsMessageChunk chunk);
// Dispatches protocol message to a remote debugging client.
// |call_id| is a command id as defined in protocol, only used
// for command responses (as opposite to protocol events).
// |state| is a state for future reattach (see DevToolsAgent),
// only comes in response to a command.
DispatchProtocolMessage(mojo_base.mojom.BigString message,
int32 call_id,
string? state);
};
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