summaryrefslogtreecommitdiff
path: root/chromium/styleguide
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2021-05-20 09:47:09 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2021-06-07 11:15:42 +0000
commit189d4fd8fad9e3c776873be51938cd31a42b6177 (patch)
tree6497caeff5e383937996768766ab3bb2081a40b2 /chromium/styleguide
parent8bc75099d364490b22f43a7ce366b366c08f4164 (diff)
downloadqtwebengine-chromium-189d4fd8fad9e3c776873be51938cd31a42b6177.tar.gz
BASELINE: Update Chromium to 90.0.4430.221
Change-Id: Iff4d9d18d2fcf1a576f3b1f453010f744a232920 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/styleguide')
-rw-r--r--chromium/styleguide/c++/OWNERS1
-rw-r--r--chromium/styleguide/c++/blink-c++.md10
-rw-r--r--chromium/styleguide/c++/c++.md13
-rw-r--r--chromium/styleguide/c++/c++11.html33
-rw-r--r--chromium/styleguide/java/java.md6
-rw-r--r--chromium/styleguide/objective-c/objective-c.md4
-rw-r--r--chromium/styleguide/python/blink-python.md8
-rw-r--r--chromium/styleguide/styleguide.md1
-rw-r--r--chromium/styleguide/swift/OWNERS2
-rw-r--r--chromium/styleguide/swift/swift.md10
-rw-r--r--chromium/styleguide/web/web.md2
11 files changed, 59 insertions, 31 deletions
diff --git a/chromium/styleguide/c++/OWNERS b/chromium/styleguide/c++/OWNERS
index 5549853f073..5fe90a1ec09 100644
--- a/chromium/styleguide/c++/OWNERS
+++ b/chromium/styleguide/c++/OWNERS
@@ -1,4 +1,5 @@
danakj@chromium.org
jbroman@chromium.org
+jdoerrie@chromium.org
pkasting@chromium.org
thakis@chromium.org
diff --git a/chromium/styleguide/c++/blink-c++.md b/chromium/styleguide/c++/blink-c++.md
index 31980d8569d..41f4a35f320 100644
--- a/chromium/styleguide/c++/blink-c++.md
+++ b/chromium/styleguide/c++/blink-c++.md
@@ -65,7 +65,7 @@ void DocumentLoader::SetHistoryItemStateForCommit() {
```c++
class BodyStreamBuffer {
public:
- using PassKey = util::PassKey<BodyStreamBuffer>;
+ using PassKey = base::PassKey<BodyStreamBuffer>;
static BodyStreamBuffer* Create();
BodyStreamBuffer(PassKey);
@@ -236,9 +236,9 @@ class Node {
## Prefer enums or StrongAliases to bare bools for function parameters
Prefer enums to bools for function parameters if callers are likely to be
passing constants, since named constants are easier to read at the call site.
-Alternatively, you can use base::util::StrongAlias<Tag, bool>. An exception to
-this rule is a setter function, where the name of the function already makes
-clear what the boolean is.
+Alternatively, you can use `base::StrongAlias<Tag, bool>`. An exception to this
+rule is a setter function, where the name of the function already makes clear
+what the boolean is.
**Good:**
```c++
@@ -271,7 +271,7 @@ if (frame_->Loader().ShouldClose(FrameLoader::CloseType::kNotForReload)) {
```c++
class FrameLoader {
public:
- using ForReload = base::util::StrongAlias<class ForReloadTag, bool>;
+ using ForReload = base::StrongAlias<class ForReloadTag, bool>;
bool ShouldClose(ForReload) {
// A StrongAlias<_, bool> can be tested like a bool.
diff --git a/chromium/styleguide/c++/c++.md b/chromium/styleguide/c++/c++.md
index f13553e8957..11a3d68f874 100644
--- a/chromium/styleguide/c++/c++.md
+++ b/chromium/styleguide/c++/c++.md
@@ -47,7 +47,7 @@ status of Chromium's C++ support is covered in more detail in
## Code formatting
* Put `*` and `&` by the type rather than the variable name.
- * In class declarations, group function overrides together within each access
+ * In class declarations, group function overrides together within each access
control section, with one labeled group per parent class.
* Prefer `(foo == 0)` to `(0 == foo)`.
@@ -287,6 +287,17 @@ these:
bots in a bad state. Use the `ASSERT_xx()` and `EXPECT_xx()` family of
macros, which report failures gracefully and can continue running other
tests.
+ * Dereferencing a null pointer in C++ is generally UB (undefined behavior) as
+ the compiler is free to assume a dereference means the pointer is not null
+ and may apply optimizations based on that. As such, there is sometimes a
+ strong opinion to `CHECK()` pointers before dereference. Chromium builds
+ with the `no-delete-null-pointer-checks` Clang/GCC flag which prevents such
+ optimizations, meaning the side effect of a null dereference would just be
+ the use of 0x0 which will lead to a crash on all the platforms Chromium
+ supports. As such we do not use `CHECK()` to guard pointer deferences. A
+ `DCHECK()` can be used to document that a pointer is never null, and doing
+ so as early as possible can help with debugging, though our styleguide now
+ recommends using a reference instead of a pointer when it cannot be null.
## Miscellany
diff --git a/chromium/styleguide/c++/c++11.html b/chromium/styleguide/c++/c++11.html
index 1e4c7329bbd..f9bfc4f27b6 100644
--- a/chromium/styleguide/c++/c++11.html
+++ b/chromium/styleguide/c++/c++11.html
@@ -20,8 +20,9 @@ table tbody tr td:first-child {
<div id="content">
<h1>Modern C++ use in Chromium</h1>
-<p><i>This document lives at src/styleguide/c++/c++11.html in a Chromium
-checkout and is part of the more general
+<p><i>This document lives at
+<a href="https://source.chromium.org/chromium/chromium/src/+/master:styleguide/c++/c++11.html">
+src/styleguide/c++/c++11.html</a> in a Chromium checkout and is part of the more general
<a href="https://chromium.googlesource.com/chromium/src/+/master/styleguide/c++/c++.md">
Chromium C++ style guide</a>. It summarizes the supported state of new and
updated language and library features in recent C++ standards and the
@@ -54,6 +55,7 @@ The current status of existing standards and Abseil features is:
<li><b>Abseil:</b> Initially supported July 31, 2020; see allowed/banned/TBD features below
<ul>
<li>absl::StatusOr: Initially supported September 3, 2020</li>
+<li>absl::Cleanup: Initially supported February 4, 2021</li>
</ul></li>
</ul></p>
@@ -184,7 +186,7 @@ The current status of existing standards and Abseil features is:
<td><code>std::function</code></td>
<td>Wraps a standard polymorphic function</td>
<td><a href="http://en.cppreference.com/w/cpp/utility/functional/function">std::function</a></td>
-<td>Use <code>base::Callback</code> instead. Compared to <code>std::function</code>, <code>base::Callback</code> directly supports Chromium's refcounting classes and weak pointers and deals with additional thread safety concerns. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/cxx/SoEj7oIDNuA">Discussion thread</a></td>
+<td>Use <code>base::&lcub;Once,Repeating&rcub;Callback</code> instead. Compared to <code>std::function</code>, <code>base::&lcub;Once,Repeating&rcub;Callback</code> directly supports Chromium's refcounting classes and weak pointers and deals with additional thread safety concerns. <a href="https://groups.google.com/a/chromium.org/forum/#!topic/cxx/SoEj7oIDNuA">Discussion thread</a></td>
</tr>
<tr>
@@ -293,6 +295,15 @@ The current status of existing standards and Abseil features is:
</tr>
<tr>
+<td>Status</td>
+<td><code>absl::Status</code></td>
+<td>Type for returning detailed errors.</td>
+<td><a href="https://source.chromium.org/chromium/chromium/src/+/master:third_party/abseil-cpp/absl/status/status.h">status.h</a></td>
+<td>Approved for use inside a wrapper type. Use <a href="https://source.chromium.org/chromium/chromium/src/+/master:base/strings/abseil_string_conversions.h">abseil_string_conversions.h</a> to convert to and from <a href="https://source.chromium.org/chromium/chromium/src/+/master:third_party/abseil-cpp/absl/strings/string_view.h">absl::string_view</a> so the wrapper can expose <a href="https://source.chromium.org/chromium/chromium/src/+/master:base/strings/string_piece.h">base::StringPiece</a>. Use <a href="https://source.chromium.org/chromium/chromium/src/+/master:third_party/abseil-cpp/absl/strings/cord.h">absl::Cord</a> directly as minimally necessary to interface; do not expose in the wrapper type API.<br>
+<a href="https://groups.google.com/a/chromium.org/g/cxx/c/ImdFCSZ-NMA">Discussion thread</a></td>
+</tr>
+
+<tr>
<td>Variant</td>
<td><code>absl::variant</code></td>
<td>Early adaptation of C++17 std::variant.</td>
@@ -393,6 +404,14 @@ the allowed or banned sections.</p>
</tr>
<tr>
+<td>Cleanup</td>
+<td><code>FILE* sink_file = fopen(sink_path, "w");<br>auto sink_closer = absl::MakeCleanup([sink_file] { fclose(sink_file); });</code></td>
+<td>Implements the scope guard idiom, invoking the contained callback's `operator()() &&` on scope exit.</td>
+<td><a href="https://source.chromium.org/chromium/chromium/src/+/master:third_party/abseil-cpp/absl/cleanup/cleanup.h">cleanup.h</a></td>
+<td>Similar to `defer` in Golang.</td>
+</tr>
+
+<tr>
<td>Containers</td>
<td><code>absl::flat_hash_map, absl::flat_hash_set,<br>absl::node_hash_map, absl::node_hash_set,<br>
absl::btree_map, absl::btree_set,<br>absl::btree_multimap, absl::btree_multiset,<br>
@@ -437,14 +456,6 @@ size_t index = absl::Uniform(bitgen, 0u, elems.size());</code></td>
</tr>
<tr>
-<td>Status</td>
-<td><code>absl::Status</code></td>
-<td>Type for returning detailed errors.</td>
-<td><a href="https://source.chromium.org/chromium/chromium/src/+/master:third_party/abseil-cpp/absl/status/status.h">status.h</a></td>
-<td></td>
-</tr>
-
-<tr>
<td>StatusOr</td>
<td><code>absl::StatusOr&lt;T&gt;</td>
<td>An object that is either a usable value, or an error Status explaining why such a value is not present.</td>
diff --git a/chromium/styleguide/java/java.md b/chromium/styleguide/java/java.md
index f5bc1b0d895..6067a258b66 100644
--- a/chromium/styleguide/java/java.md
+++ b/chromium/styleguide/java/java.md
@@ -124,12 +124,12 @@ Classes that need destructor logic should provide an explicit `destroy()`
method. Use [LifetimeAssert](https://chromium.googlesource.com/chromium/src/+/master/base/android/java/src/org/chromium/base/LifetimeAssert.java)
to ensure in debug builds and tests that `destroy()` is called.
-### Other Android Support Library Annotations
+### AndroidX Annotations
* Use them! They are [documented here](https://developer.android.com/studio/write/annotations).
* They generally improve readability.
* Some make lint more useful.
-* `javax.annotation.Nullable` vs `android.support.annotation.Nullable`
- * Always prefer `android.support.annotation.Nullable`.
+* `javax.annotation.Nullable` vs `androidx.annotation.Nullable`
+ * Always prefer `androidx.annotation.Nullable`.
* It uses `@Retention(SOURCE)` rather than `@Retention(RUNTIME)`.
## Tools
diff --git a/chromium/styleguide/objective-c/objective-c.md b/chromium/styleguide/objective-c/objective-c.md
index cd74cdc74c4..38524d1d0f2 100644
--- a/chromium/styleguide/objective-c/objective-c.md
+++ b/chromium/styleguide/objective-c/objective-c.md
@@ -3,7 +3,7 @@
_For other languages, please see the [Chromium style guides](https://chromium.googlesource.com/chromium/src/+/master/styleguide/styleguide.md)._
Chromium follows the
-[Google Objective-C style guide](https://github.com/google/styleguide/blob/gh-pages/objcguide.md)
+[Google Objective-C style guide](https://google.github.io/styleguide/objcguide.html)
unless an exception is listed below.
A checkout should give you
@@ -48,5 +48,5 @@ C++ style.
## #import and #include in the `ios/` directory
#import directive can be used to import C++ and Objective-C headers for all
-source code in the `ios/` directory. This differs from Google Objective-C Style
+source code in the `ios/` directory. This differs from the Google Objective-C Style
Guide, which requires using #include directive for C++ headers.
diff --git a/chromium/styleguide/python/blink-python.md b/chromium/styleguide/python/blink-python.md
index 931c4bc2caf..6632526fe4c 100644
--- a/chromium/styleguide/python/blink-python.md
+++ b/chromium/styleguide/python/blink-python.md
@@ -6,11 +6,3 @@ exception is listed below. See
_Note: We likely want to converge with [Chromium style](python.md), so this
style recommendation is likely to change._
-
-## Differences from PEP-8
-
-* Line length limit is 132
-
-## Differences from Chromium style
-
-* Line length limit is 132
diff --git a/chromium/styleguide/styleguide.md b/chromium/styleguide/styleguide.md
index 5120b7c3d61..318107c1ad7 100644
--- a/chromium/styleguide/styleguide.md
+++ b/chromium/styleguide/styleguide.md
@@ -5,6 +5,7 @@
* [Chromium C++ style guide](c++/c++.md)
* See also: [C++ Dos and Don'ts](c++/c++-dos-and-donts.md) for Chromium best-practices.
* [Chromium Objective-C style guide](objective-c/objective-c.md)
+ * [Chromium Swift style guide](swift/swift.md)
* [Java style guide for Android](java/java.md)
* [Chromium Python style guide](python/python.md)
* [GN style guide](https://gn.googlesource.com/gn/+/master/docs/style_guide.md) for build files.
diff --git a/chromium/styleguide/swift/OWNERS b/chromium/styleguide/swift/OWNERS
new file mode 100644
index 00000000000..50b9bfbf544
--- /dev/null
+++ b/chromium/styleguide/swift/OWNERS
@@ -0,0 +1,2 @@
+javierrobles@chromium.org
+pinkerton@chromium.org
diff --git a/chromium/styleguide/swift/swift.md b/chromium/styleguide/swift/swift.md
new file mode 100644
index 00000000000..4f800386903
--- /dev/null
+++ b/chromium/styleguide/swift/swift.md
@@ -0,0 +1,10 @@
+# Chromium Swift style guide
+
+_For other languages, please see the [Chromium style guides](https://chromium.googlesource.com/chromium/src/+/master/styleguide/styleguide.md)._
+
+Chromium follows the
+[Google Swift style guide](https://google.github.io/swift/)
+no exceptions at this point.
+
+[swift-format](https://github.com/apple/swift-format)
+can be used to automatically format Swift code.
diff --git a/chromium/styleguide/web/web.md b/chromium/styleguide/web/web.md
index bbf61f3ce65..13cb37dadfb 100644
--- a/chromium/styleguide/web/web.md
+++ b/chromium/styleguide/web/web.md
@@ -415,7 +415,7 @@ https://www.polymer-project.org/2.0/docs/devguide/templates#dom-if):
* Alternatives:
* Include the SVG in a WebUI page-specific icon file. e.g. `chrome/browser/resources/settings/icons.html`.
* If reused across multiple WebUI pages, include the SVG in `ui/webui/resources/cr_elements/icons.html` .
- * You may copy the SVG code from [iron-icons files](https://github.com/PolymerElements/iron-icons/blob/master/iron-icons.html).
+ * You may copy the SVG code from [iron-icons files](https://github.com/PolymerElements/iron-icons/blob/master/iron-icons.js).
## Grit processing