forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make network::DataElement a union with absl::variant
network.mojom.DataElement represents part of a request body. It is a union of several types, and that applies to its typemapped class, network::DataElement. Up until now we had flat members (e.g., offset(), length(), bytes()) with various DCHECKs on network::DataElement. This led to several issues: 1) The code author can be confused. Some members (e.g., length(), bytes()) seems to have a meaning in a wrong context, and that can lead to security issues. See https://crbug.com/1151865 for example. 2) It is hard to maintain the DCHECKs in a consistent way. For example, at this moment we have a DCHECK at chunked_data_pipe_getter(), but we don't have a DCHECK at length(). We have a similar difficulty on mojo deserialization. This CL makes network::DataElement a simple wrapper of absl::variant. network::DataElement has only one member: absl::variant<absl::monostate, DataElementBytes, DataElementDataPipe, DataElementChunkedDataPipe, DataElementFile> variant_; A user needs to check the type and explicitly cast the element to the correct class, to access any information (other than `type`). We rely on checks implemented in absl::variant, so we don't need to have many DCHECKs. This CL also contains the following changes: A) DataElementType.kReadOnceStream is gone, as having two members sharing the same type makes the use of absl::variant difficult. This merges the type to DataElementType.kChunkedDataPipe, and introduced a boolean `read_only_once` in DataElement to distinguish them. B) Removed FetchAPIDataElement, as it seems identical to network.mojom.DataElement. C) Deserialization logic gets more strict. Invalid mojo::pending_remote for kDataPipe and kChunkedDataPipe are now treated as errors. D) Made network.mojom.DataElement a union. E) Added some deserialization tests for network::DataElement. Change-Id: I2c646ead57bc19bee661b711c9c863ce1a5e9c94 Bug: 1156550, 1151865, 1152664 Tbr: [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected] Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2599731 Reviewed-by: Alex Ilin <[email protected]> Reviewed-by: Matt Menke <[email protected]> Reviewed-by: Daniel Cheng <[email protected]> Reviewed-by: Matt Falkenhagen <[email protected]> Reviewed-by: Nathan Parker <[email protected]> Commit-Queue: Yutaka Hirano <[email protected]> Cr-Commit-Position: refs/heads/master@{#842964}
- Loading branch information
1 parent
6f1ad3e
commit 69d394f
Showing
46 changed files
with
887 additions
and
758 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.