Upstream PR:
Introduce a crdtp/dispatch.{h,cc} library.
https://chromium-review.googlesource.com/c/deps/inspector_protocol/+/1974680
New Rev: 8c2064ea99cffdb5647760ad3953c43e612e07fc
Notable downstream changes:
- ChromeDevToolsManagerDelegate::HandleCommand no longer carries
a method. Reason being, the shallow parser (crdtp::Dispatchable)
should be efficient enough to parse an incoming message a couple
of times, e.g. once for the content layer and once for the
embedder, and if we felt differently then we'd quite possibly
want to carry more than just the method - e.g., we'd want to also
pass the params. Anyway, for now simplifying this interface.
- crdtp::FrontendChannel::FallThrough; here, it's advantagueous
to keep the method around, but now it's a crdtp::span. This is
much better than const std::string& because the generated code
knows exactly which method is going to fall through and we
can pass a C++ string literal via this span.
- The crdtp/dispatch library presents a somewhat different surface
between the UberDispatcher and the session implementations.
The session implementations are responsible for creating a
crdtp::Dispatchable instance (the shallow parser) which
it then hands to the dispatcher for dispatching. Rather than
querying for whether it can dispatch and then doing it,
the result of the Dispatch indicates whether a method was
found and can be executed. There's no more need to instantiate
protocol::Value in a devtools session class.
- Since the dispatch library uses crdtp::span to represent
method names, we no longer need to reference platform specific
routines for finding strings and making substrings. As a result,
v8_inspector_string.h is losing a few more methods
(and same for base_string_adapter_h.template).
- crdtp::DispatchResponse (also known as protocol::Response) has
some renames for consistency (
Response::Error -> Response::SeverError,
Response::OK -> Response::Success). Touches all domain handlers
but is mechanical.
- All protocol error messages, such as the parameters passed
to DispatchResponse::ServerError are required to be UTF8 strings,
even for Blink, so when code generates them as WTF::String,
we convert them to std::string using WTF::String::Utf8()
before passing them to DispatchResponse::ServerError.
- We're better about checking messages and sending errors when we
can't parse them - esp. we no longer drop messages on the floor
if we can't make sense of them; the LOG statements are gone,
because we can either send an error or assume that we've
previously parsed the message elsewhere and put a DCHECK (e.g.,
a message received by blink has always been shallow-parsed by the
browser before).
- DevToolsAgentHost::DispatchProtocolMessage no longer has a boolean
return value. Reason being, it's not well defined what the
boolean should indicate. If we reject the message and send
an error, arguably we've also handled it. And of course, we
always do that (now). So it's not useful to generate or check
this return value, and there is only one DCHECK on it currently,
which is also not covered by tests.
- content::DevToolsSession uses binary searches to match method names
(e.g. in ShouldSendOnIO).
This is because I've switched the method names to span, and
implemented similar searches for the dispatching library, so
it's best to be consistent. It will also scale better if we add
more methods.
- The additional unittests added to the CRDTP library upstream cover
shallow parsing, dispatching, etc. and are now also part of
the content_unittests.
- Improves Android binary size by about 36k, by reducing code
duplication. There's now just one UberDispatcher, for example,
as opposed to one for blink, one for content, one for headless,
one for chromium, ...
- Speeds up execution by 1-2% (based on internal measurements),
because message serialization no longer takes a detour via
protocol::Value.
Change-Id: I422fe527d6f8a6ffb098b3992728ecba408b571f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2047966
Reviewed-by: Dmitry Gozman <dgozman@chromium.org>
Reviewed-by: Ganggui Tang <gogerald@chromium.org>
Reviewed-by: Andrey Kosyakov <caseq@chromium.org>
Reviewed-by: Leonard Grey <lgrey@chromium.org>
Commit-Queue: Johannes Henkel <johannes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#750284}