0
Commit Graph

19 Commits

Author SHA1 Message Date
Arthur Sonzogni
e5fff99cbb Rename {absl => std}::optional in base + everywhere. [Final]
Automated patch. This is a no-op. Please avoid, as much as possible,
assigning unrelated bugs to this.

Context:
https://groups.google.com/a/chromium.org/g/cxx/c/nBD_1LaanTc/m/ghh-ZZhWAwAJ?utm_medium=email

As of https://crrev.com/1204351, absl::optional is now a type alias
for std::optional. We should migrate toward it.

Script:
```
function replace {
  echo "Replacing $1 by $2"
  git grep -l "$1" \
    | cut -f1 -d: \
    | grep -v \
      -e "components/cast_streaming/browser/public/receiver_config.*" \
      -e "components/power_metrics/*" \
      -e "components/zucchini/patch_reader.*" \
      -e "third_party/abseil-cpp/*" \
      -e "third_party/googletest/*" \
      -e "third_party/leveldatabase/*" \
      -e "third_party/libaddressinput/" \
      -e "third_party/liburlpattern/*" \
      -e "third_party/lzma_sdk/*" \
      -e "third_party/maldoca/*" \
      -e "third_party/mediapipe/*" \
      -e "third_party/shell-encryption/*"\
      -e "third_party/tflite_support/*" \
      -e "third_party/webrtc_overrides/*" \
      -e "third_party/zxcvbn-cpp/*" \
    | grep \
      -e "\.h" \
      -e "\.cc" \
      -e "\.mm" \
      -e "\.pidl" \
    | sort \
    | uniq \
    | xargs sed -i "s/$1/$2/g"
}
replace "absl::make_optional" "std::make_optional"
replace "absl::optional" "std::optional"
replace "absl::nullopt" "std::nullopt"
replace "absl::in_place," "std::in_place,"
replace "absl::in_place_t," "std::in_place_t,"
replace "absl::in_place)" "std::in_place)"
replace "absl::in_place_t)" "std::in_place_t)"
replace "\"third_party\/abseil-cpp\/absl\/types\/optional.h\"" "<optional>"

git status
echo "Formatting"

echo "IncludeBlocks: Regroup" >> ".clang-format"
echo "IncludeIsMainRegex: \"(_(android|apple|chromeos|freebsd|fuchsia|fuzzer|ios|linux|mac|nacl|openbsd|posix|stubs?|win))?(_(unit|browser|perf)?tests?)?$\"" >> ".clang-format"
git cl format
git restore ".clang-format"
```

Bug: chromium:1500249
Change-Id: Ic2994b982bbc64d62f030d3d158979dc5d266121
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5296147
Reviewed-by: danakj <danakj@chromium.org>
Commit-Queue: danakj <danakj@chromium.org>
Owners-Override: danakj <danakj@chromium.org>
Auto-Submit: Arthur Sonzogni <arthursonzogni@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1263362}
2024-02-21 15:58:24 +00:00
Daniel Cheng
66af2fe6e1 Disallow calling SetUserData() when destroying SupportsUserData.
Doing this isn't immediately problematic: `~SupportsUserData()` attempts
to work around reentrant calls into itself by swapping out the backing
map during destruction.

However, if code calls `SetUserData()` on the `SupportsUserData` being
destroyed, this means the backing map is no longer empty—and when the
body of the destructor is complete, if the same problematic code calls
`SetUserData()` while `SupportsUserData`'s fields are being destroyed,
bad things will happen, since containers:
- require iterating over the elements during destruction
- are not robust against mutation of the container itself during
  iteration

There are no new checks added to `GetUserData()`. While not ideal, it
is not dangerous in the same way that calling `SetUserData()` would be.
`GetUserData()` will always return `nullptr` in this case.

Checks *will* be added to `RemoveUserData()` and `TakeUserData()` in
followups. While they are not actively dangerous in the same way
`SetUserData()` is, it is conceptually incorrect to attempt to mutate
the `SupportsUserData` during destruction. It is also entirely possible
that landing this CL will reveal interesting bugs in the wild, so
landing these checks in separate CLs means that reverts can be limited
in scope.

Bug: 1483288
Change-Id: Ib21626a5ce59480baf231c93630642484b9c3148
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4906190
Reviewed-by: danakj <danakj@chromium.org>
Commit-Queue: Daniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1204380}
2023-10-03 00:38:29 +00:00
Daniel Cheng
a47b8f13ed Remove experiment code for SupportsUserDataFlatHashMap.
Note that this simply deletes the base::flat_map arm; the experiment was
considered successful, and the default container guidelines are being
updated to recommend absl::flat_hash_map as a default. As such, it does
not seem to make sense to fall back to base::flat_map temporarily, only
to convert it again later.

Bug: 1121345
Change-Id: I627cab7a6ef313308811beb6e680e7a037a5eaa2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4906604
Reviewed-by: Scott Violet <sky@chromium.org>
Commit-Queue: Daniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1204305}
2023-10-02 22:21:59 +00:00
Daniel Cheng
ae276208ab Guard against reentrancy in SupportsUserData::RemoveUserData().
Bug: 1414218
Change-Id: I8a0e97539433c1d86557d2bfa899ea7cfd374412
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4416617
Commit-Queue: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: Scott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1129075}
2023-04-12 04:03:34 +00:00
William Liu
055a3549f4 [navigation-transitions]: Cache screenshots for navigation entries
Introduce NavigationEntryScreenshot, which preserves a screenshot on the
current NavigationEntry when the user is navigating away from it. The
stored screenshot will later be used to present the user with a preview,
when the user navigates back to this page.

The caching mechanism is composed of the screenshot, the cache and a
global manager. The global manager lives on the BrowserContext and is
responsible for memory budgeting. The cache lives on the primary
NavigationController which owns the NavigationEntry where the
screenshot is stashed.

This CL contains the impl of caching, retrieving and eviction of the
screenshots with unittests. The cache is not integrated with the navigation thus no browsertest.

The code resides in `//content/browser/renderer_host/` because no need
to access WebContents.

[Updated] DD/Explainer (chromium access): https://docs.google.com/document/d/1-7TatVjSL4n-RNyvN_MWdFoOiR6YJ1BjvJKgvym_ArU

Feature EngDoc: https://docs.google.com/document/d/1H99XZHdAWNfbfboHbGdMB97k81AzAxVtPSizAjO2Poc/

PRD (google access): https://docs.google.com/document/d/1JMWzArv0VR-G4xx3a5ku8N5np8mDeGSuvR95kZc8ynY/

Bug: 1415332, 1413521
Change-Id: Icc3b2aa7b5b36ed460ad2ddd1ff5f645a38d2835
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4245857
Reviewed-by: Kyle Charbonneau <kylechar@chromium.org>
Commit-Queue: William Liu <liuwilliam@chromium.org>
Reviewed-by: Avi Drissman <avi@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1125127}
2023-04-02 17:21:19 +00:00
Daniel Cheng
3d173eedf8 Enable A/B experimentation for SupportUserData's underlying map type.
For a pointer-sized key to a pointer-sized value, absl::flat_hash_map
should have strictly better memory scaling than both std::map and
std::unordered_map. In addition, the map data is stored inline rather
than in nodes, so CPU scaling should be strictly better as well. An
actual A/B experiment should help confirm this hypothesis (or even
confirm that the impact is negligible—which would still be fine).

Bug: 1121345
Change-Id: I757b0c057d376e0733ab996de287ce5611d91ca3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4136838
Reviewed-by: Scott Violet <sky@chromium.org>
Commit-Queue: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: Mirko Bonadei <mbonadei@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1089555}
2023-01-06 01:31:15 +00:00
Tom Sepez
9c19887ff9 Re-order locals in SupportsUserDataTest.ClearWorksRecursively.
Otherwise, dangling pointer detection may trigger a use-after-scope
when the locals are destroyed in inverse order.

Change-Id: I6c3ccd75ebbb5602626d777fed6fb8bf73e2fc77
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4137585
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1089455}
2023-01-05 22:10:36 +00:00
Avi Drissman
e4622aaecc Update copyright headers in base/
The methodology used to generate this CL is documented in
https://crbug.com/1098010#c34.

An earlier version of this CL, https://crrev.com/c/3879904,
was reverted due to an issue that was resolved with
https://crrev.com/c/3881211.

No-Try: true
Bug: 1098010
Change-Id: Ibd6ffb97e66835bc299fe7b85876c3e2927b2345
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3883841
Auto-Submit: Avi Drissman <avi@chromium.org>
Owners-Override: Avi Drissman <avi@chromium.org>
Reviewed-by: Mark Mentovai <mark@chromium.org>
Commit-Queue: Mark Mentovai <mark@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1044747}
2022-09-08 20:36:06 +00:00
Daniel Cheng
3d1108defc Revert "Update copyright headers in base/"
This reverts commit eccb7e8107.

Reason for revert: https://crbug.com/1361092

Original change's description:
> Update copyright headers in base/
>
> The methodology used to generate this CL is documented in
> https://crbug.com/1098010#c21.
>
> No-Try: true
> Bug: 1098010
> Change-Id: Icd01cc1648eab4b0550afcff2bee17076359a132
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3879904
> Owners-Override: Avi Drissman <avi@chromium.org>
> Commit-Queue: Avi Drissman <avi@chromium.org>
> Auto-Submit: Avi Drissman <avi@chromium.org>
> Reviewed-by: Mark Mentovai <mark@chromium.org>
> Cr-Commit-Position: refs/heads/main@{#1044191}

Bug: 1098010
Change-Id: Iefdde85d3d44fabe09906cd725b39a4e0b359491
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3880811
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Owners-Override: Daniel Cheng <dcheng@chromium.org>
Commit-Queue: Daniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1044252}
2022-09-07 23:42:04 +00:00
Avi Drissman
eccb7e8107 Update copyright headers in base/
The methodology used to generate this CL is documented in
https://crbug.com/1098010#c21.

No-Try: true
Bug: 1098010
Change-Id: Icd01cc1648eab4b0550afcff2bee17076359a132
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3879904
Owners-Override: Avi Drissman <avi@chromium.org>
Commit-Queue: Avi Drissman <avi@chromium.org>
Auto-Submit: Avi Drissman <avi@chromium.org>
Reviewed-by: Mark Mentovai <mark@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1044191}
2022-09-07 21:26:21 +00:00
Keishi Hattori
0e45c020c4 Rewrite most Foo* field_ pointer fields to raw_ptr<Foo> field_.
DO NOT REVERT (unless absolutely necessary)! Report build breaks to keishi@(APAC)/glazunov@(EMEA)/sebmarchand@(NA) as soon as you see them. Fixes are expected to be trivial.

This commit was generated automatically, by running the following script: tools/clang/rewrite_raw_ptr_fields/rewrite-multiple-platforms.sh on commit fe74bc434e

For more information, see MiraclePtr One Pager [1], the PSA at chromium-dev@ [2], and the raw_ptr documentation in //base/memory/raw_ptr.md.

FYI This CL does not enable MiraclePtr protection and we expect no behavior change from this.

[1] https://docs.google.com/document/d/1pnnOAIz_DMWDI4oIOFoMAqLnf_MZ2GsrJNb_dbQ3ZBg/edit?usp=sharing
[2] https://groups.google.com/a/chromium.org/g/chromium-dev/c/vAEeVifyf78/m/SkBUc6PhBAAJ

Binary-Size: Increase of around 500kb was approved for MiraclePtr
Include-Ci-Only-Tests: true
No-Tree-Checks: true
No-Presubmit: true
Bug: 1272324, 1073933
Change-Id: I05c86a83bbb4b3f4b017f361dd7f4e7437697f69
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3305132
Commit-Queue: Keishi Hattori <keishi@chromium.org>
Reviewed-by: Bartek Nowierski <bartekn@chromium.org>
Owners-Override: Bartek Nowierski <bartekn@chromium.org>
Cr-Commit-Position: refs/heads/main@{#945735}
2021-11-27 09:25:52 +00:00
Victor Hugo Vianna Silva
05f1454e1c Remove leftover <vector> includes in base/
This is among the most costful includes for the Chromium build.
https://commondatastorage.googleapis.com/chromium-browser-clang/include-analysis.html

Bug: 1233968
Change-Id: I9a4bcd8fe454daacaa0e022be9ea6643eeead250
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3059651
Auto-Submit: Victor Vianna <victorvianna@google.com>
Reviewed-by: Gabriel Charette <gab@chromium.org>
Commit-Queue: Victor Vianna <victorvianna@google.com>
Cr-Commit-Position: refs/heads/master@{#908903}
2021-08-05 16:08:48 +00:00
Matt Mueller
e74f61779c [base] Allow SupportsUserData subclasses to clear all data.
Allow SupportsUserData to be used by subclasses which can be "reset", by letting
the subclass clear all associated user-data if required.

(e.g. CertVerifyResult has a Reset method, so if it subclass SupportsUserData,
 it also needs a way to clear any attached user data when Reset is called.)

Bug: 991247
Change-Id: I3b3edaa58b2e70daac453edd28e4aa37eee17bf2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1738628
Commit-Queue: Matt Mueller <mattm@chromium.org>
Reviewed-by: Wez <wez@chromium.org>
Reviewed-by: Avi Drissman <avi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#686528}
2019-08-13 20:00:59 +00:00
Matt Mueller
39fc01f9cf [base] Allow movable types to derive from SupportsUserData.
Making SupportsUserData movable allows it to be used to allow additional
data to be attached to movable data objects, e.g. we'll use this to allow
CertVerifyResult instances to have debug information attached by
different verifier implementations

Bug: 991247
Change-Id: Iba8c9000750559e7edbafac8e5ebefddf8a38e10
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1739147
Reviewed-by: Wez <wez@chromium.org>
Commit-Queue: Matt Mueller <mattm@chromium.org>
Cr-Commit-Position: refs/heads/master@{#685843}
2019-08-10 02:24:08 +00:00
Ivan Kotenkov
a16212a56d Convert NULL and 0 to nullptr in base using clang-tidy.
Steps to replicate:
1. Build clang-tidy and clang-apply-replacements as described here: https://chromium.googlesource.com/chromium/src/+/lkcr/docs/clang_tidy.md
2. Build targets necessary for the change in out/gn.
3. Generate the compilation database:
  tools/clang/scripts/generate_compdb.py -p out/gn > compile_commands.json
4. Run clang-tidy and apply replacements:
  cd out/gn && PATH_TO_RUN_CLANG_TIDY/run-clang-tidy.py -p ../../ -clang-tidy-binary PATH_TO_CLANG_TIDY_BINARY -clang-apply-replacements-binary PATH_TO_CLANG_APPLY_REPLACEMENTS_BINARY -checks=-*,modernize-use-nullptr -fix -j 8 DIR_TO_CONVERT

Bug: 403854, 776257
Change-Id: I920f43d09b9fab758a3b8663fcf0c405d8519ad4
Reviewed-on: https://chromium-review.googlesource.com/732105
Commit-Queue: Ivan Kotenkov <kotenkov@yandex-team.ru>
Reviewed-by: danakj <danakj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#514808}
2017-11-08 12:37:33 +00:00
Jeremy Roman
9532f25fad Replace base::MakeUnique with std::make_unique in base/.
Bug: 755727
Change-Id: Ia785171c1c9fd5396def9e381bbc1387e0eee0a1
Reviewed-on: https://chromium-review.googlesource.com/616842
Commit-Queue: Jeremy Roman <jbroman@chromium.org>
Reviewed-by: Nico Weber <thakis@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#494995}
2017-08-16 23:27:24 +00:00
sdefresne
ae5e2d28e5 Update SupportsUserData API to accept std::unique_ptr<>.
SupportsUserData takes ownership of the SupportsUserData::Data
passed to SetUserData. Add an overload taking a std::unique_ptr
so that client code can be converted incrementally.

BUG=690937

Review-Url: https://codereview.chromium.org/2680403004
Cr-Commit-Position: refs/heads/master@{#449933}
2017-02-13 11:49:26 +00:00
dcheng
5648818ef9 Standardize usage of virtual/override/final in base/
BUG=417463
TBR=danakj@chromium.org

Review URL: https://codereview.chromium.org/668783004

Cr-Commit-Position: refs/heads/master@{#300447}
2014-10-21 10:55:12 +00:00
jyasskin@chromium.org
1f7d92afe7 Make sure that when a SupportsUserData is destroyed, objects destroyed transitively see it as empty.
BUG=358707

Review URL: https://codereview.chromium.org/298023008

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@273568 0039d316-1c4b-4281-b951-d872f2087c98
2014-05-29 20:10:36 +00:00