Commit ca984d75 authored by Dmitry Gozman's avatar Dmitry Gozman Committed by Commit Bot

Update guidelines for using STL and base in Blink

This follows the discussion which happened on platform-architecture-dev:
https://groups.google.com/a/chromium.org/forum/#!topic/platform-architecture-dev/wuLAMcSvVqs/discussion

Change-Id: I1b65537eadb3ddd5dd3e1a981a3ae5b3e9432e34
Reviewed-on: https://chromium-review.googlesource.com/1094478
Commit-Queue: Dmitry Gozman <dgozman@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarJeremy Roman <jbroman@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#569383}
parent fee79728
...@@ -47,13 +47,10 @@ FrameLoader::FrameLoader(LocalFrame* frame) ...@@ -47,13 +47,10 @@ FrameLoader::FrameLoader(LocalFrame* frame)
} }
``` ```
## Prefer WTF types over STL types ## Prefer WTF types over STL and base types
Outside of `//third_party/blink/common`, Blink should use WTF types. STL string See [Blink readme](../../third_party/blink/renderer/README.md#Type-dependencies)
and container types should only be used at the boundary to interoperate with for more details on Blink directories and their type usage.
'//base', `//third_party/blink/common`, and other Chromium-side code.
Similarly, Blink should prefer `KURL` over `GURL` and `SecurityOrigin` over
`url::Origin`.
**Good:** **Good:**
```c++ ```c++
......
...@@ -127,16 +127,33 @@ See [this diagram](https://docs.google.com/document/d/1yYei-V76q3Mb-5LeJfNUMitmj ...@@ -127,16 +127,33 @@ See [this diagram](https://docs.google.com/document/d/1yYei-V76q3Mb-5LeJfNUMitmj
### Type dependencies ### Type dependencies
`core/`, `modules/`, `bindings/`, `platform/` and `controller/` can use `std::` types and Member variables of the following types are strongly discouraged in Blink:
types defined in Chromium. The philosophy is that we should - STL strings and containers. Use `WTF::String` and WTF containers instead.
share as much code between Chromium and Blink as possible. - `GURL` and `url::Origin`. Use `KURL` and `SecurityOrigin` respectively.
- Any `//base` type which has a matching type in `platform/wtf`. The number of
However, there are a couple of types that really need to be optimized duplicated types between WTF and base is continuously shrinking,
for Blink's workload (e.g., `Vector`, `HashTable`, `Bind`, `AtomicString`). but always look at WTF first.
These types are defined in `platform/wtf`. If there is an equivalent in
`platform/wtf`, Blink must use the type in `platform/wtf` instead of the type The types above could only be used at the boundary to interoperate
defined in Chromium. For example, Blink should not use `std::vector` with `//base`, `//services`, `//third_party/blink/common` and other
(except places where a conversion between `std::vector` and `WTF::Vector` is needed). Chromium-side or third-party code. It is also allowed to use local variables
of these types when convenient, as long as the result is not stored
in a member variable.
For example, calling an utility function on an `std::string` which came
from `//net` and then converting to `WTF::String` to store in a field
is allowed.
We try to share as much code between Chromium and Blink as possible,
so the number of these types should go down. However, some types
really need to be optimized for Blink's workload (e.g., `Vector`,
`HashTable`, `AtomicString`).
Exceptions to this rule:
- Code in `//third_party/blink/common` and `//third_party/blink/public/common`
also runs in the browser process, and should use STL and base instead of WTF.
- Selected types in `public/platform` and `public/web`,
whole purpose of which is conversion between WTF and STL,
for example `WebString` or `WebVector`.
To prevent use of random types, we control allowed types by whitelisting To prevent use of random types, we control allowed types by whitelisting
them in DEPS and a [presubmit script](../tools/audit_non_blink_usage.py). them in DEPS and a [presubmit script](../tools/audit_non_blink_usage.py).
......
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