[DevTools] Use base::span<const uint8_t> for devtools messages in content/public
The interfaces in content/public currently use const std::string& for
devtools messages. This requires client code as well as implementation
code to use an std::string for representing the messages (depending on the
code that's providing the const std::string&).
Moving to base::span allows code to use any container that gives
access to a sequence of bytes without having to make a copy, including:
- std::string (just like now)
- std::vector<uint8_t> (base::span<const uint8_t>'s implicit
constructor takes it).
- the BigBuffer from Mojo (provides a base::span<const uint8_t> already).
- base::span<const uint8_t>
- crdtp::span<uint8_t> (base::span<const uint8_t>'s implicit
constructor takes it).
- base::StringPiece (going to / from this one requires a reinterpret_cast,
but at least it's efficient).
The switch removes a few copies of byte sequences (e.g. from BigBuffer
to std::string). It introduces a few conversions between
the non-owning representations, but these are cheap.
This PR includes a roll of third_party/inspector_protocol.
New revision is: 3b0551d3904f7fc067e78905ce697002187fa7a5
Change-Id: I4bea62307378f72ae95fa631db42c3bc95694d2e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1965407
Reviewed-by: Charlie Harrison <[email protected]>
Reviewed-by: Stephane Zermatten <[email protected]>
Reviewed-by: Josh Karlin <[email protected]>
Reviewed-by: Yusuf Ozuysal <[email protected]>
Reviewed-by: Istiaque Ahmed <[email protected]>
Reviewed-by: Ken Rockot <[email protected]>
Reviewed-by: Andrey Kosyakov <[email protected]>
Reviewed-by: Dmitry Gozman <[email protected]>
Commit-Queue: Johannes Henkel <[email protected]>
Cr-Commit-Position: refs/heads/master@{#726674}
diff --git a/chrome/browser/extensions/api/debugger/debugger_api.cc b/chrome/browser/extensions/api/debugger/debugger_api.cc
index e0b5e36..b2dead2 100644
--- a/chrome/browser/extensions/api/debugger/debugger_api.cc
+++ b/chrome/browser/extensions/api/debugger/debugger_api.cc
@@ -145,7 +145,7 @@
// DevToolsAgentHostClient interface.
void AgentHostClosed(DevToolsAgentHost* agent_host) override;
void DispatchProtocolMessage(DevToolsAgentHost* agent_host,
- const std::string& message) override;
+ base::span<const uint8_t> message) override;
bool MayAttachToURL(const GURL& url, bool is_webui) override;
bool MayAttachToBrowser() override;
bool MayReadLocalFiles() override;
@@ -266,9 +266,11 @@
"params", command_params->additional_properties.CreateDeepCopy());
}
- std::string json_args;
- base::JSONWriter::Write(protocol_request, &json_args);
- agent_host_->DispatchProtocolMessage(this, json_args);
+ std::string json;
+ base::JSONWriter::Write(protocol_request, &json);
+
+ agent_host_->DispatchProtocolMessage(this,
+ base::as_bytes(base::make_span(json)));
}
void ExtensionDevToolsClientHost::InfoBarDismissed() {
@@ -314,15 +316,18 @@
}
void ExtensionDevToolsClientHost::DispatchProtocolMessage(
- DevToolsAgentHost* agent_host, const std::string& message) {
+ DevToolsAgentHost* agent_host,
+ base::span<const uint8_t> message) {
DCHECK(agent_host == agent_host_.get());
if (!EventRouter::Get(profile_))
return;
+ base::StringPiece message_str(reinterpret_cast<const char*>(message.data()),
+ message.size());
std::unique_ptr<base::Value> result = base::JSONReader::ReadDeprecated(
- message, base::JSON_REPLACE_INVALID_CHARACTERS);
+ message_str, base::JSON_REPLACE_INVALID_CHARACTERS);
if (!result || !result->is_dict()) {
- LOG(ERROR) << "Tried to send invalid message to extension: " << message;
+ LOG(ERROR) << "Tried to send invalid message to extension: " << message_str;
return;
}
base::DictionaryValue* dictionary =