0

Fix (most of?) the remaining absl::optional references

There were a lot of references in comments and documentation that
weren't previously picked up. Also a few references in code, which I
assume were a race condition with the bulk of the migration.

Bug: 40242125
Change-Id: Ia9f9332df8c389a55da7bc0b43732a2c1730d664
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5688859
Commit-Queue: David Benjamin <davidben@chromium.org>
Owners-Override: danakj <danakj@chromium.org>
Reviewed-by: danakj <danakj@chromium.org>
Commit-Queue: danakj <danakj@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1325069}
This commit is contained in:
David Benjamin
2024-07-09 19:54:35 +00:00
committed by Chromium LUCI CQ
parent c637ad8221
commit 1d737482da
35 changed files with 56 additions and 58 deletions
ash/test/pixel
base
chrome
browser
web_applications
isolated_web_apps
update_manifest
services
chromeos
ash
components
feature_usage
services
multidevice_setup
components
sensors
codelabs/cpp101
components
permissions
segmentation_platform
internal
services
app_service
content
device/bluetooth/floss
docs/ui
extensions/docs
media/learning/mojo/public/mojom
services
storage/browser/file_system
third_party/blink
tools/clang/blink_gc_plugin

@ -24,7 +24,7 @@ with Chrome testing, read this [doc][3] first.
class DemoAshPixelDiffTest : public AshTestBase {
public:
// AshTestBase:
absl::optional<pixel_test::InitParams> CreatePixelTestInitParams()
std::optional<pixel_test::InitParams> CreatePixelTestInitParams()
const override {
return pixel_test::InitParams();
}
@ -190,7 +190,7 @@ create a pixel test to verify the right-to-left UI layout in the code below:
class DemoRTLTest : public AshTestBase {
public:
// AshTestBase:
absl::optional<pixel_test::InitParams> CreatePixelTestInitParams()
std::optional<pixel_test::InitParams> CreatePixelTestInitParams()
const override {
pixel_test::InitParams init_params;
init_params.under_rtl = true;

@ -110,14 +110,14 @@ class BASE_EXPORT JSONReader {
JSONReader& operator=(const JSONReader&) = delete;
// Reads and parses |json|, returning a Value.
// If |json| is not a properly formed JSON string, returns absl::nullopt.
// If |json| is not a properly formed JSON string, returns std::nullopt.
static std::optional<Value> Read(
std::string_view json,
int options = JSON_PARSE_CHROMIUM_EXTENSIONS,
size_t max_depth = internal::kAbsoluteMaxDepth);
// Reads and parses |json|, returning a Value::Dict.
// If |json| is not a properly formed JSON dict string, returns absl::nullopt.
// If |json| is not a properly formed JSON dict string, returns std::nullopt.
static std::optional<Value::Dict> ReadDict(
std::string_view json,
int options = JSON_PARSE_CHROMIUM_EXTENSIONS,

@ -6,7 +6,7 @@ This is a brief overview of what they are and how they should be used. Refer to
individual header files for details. C++ is not memory safe, so use these types
to help guard against potential memory bugs.
There are other pointer-like object types implemented elsewhere that may be
right for a given use case, such as `absl::optional<T>` and
right for a given use case, such as `std::optional<T>` and
`std::unique_ptr<T>`. More on all types in video form
[here](https://youtu.be/MpwbWSEDfjM?t=582s) and in a doc
[here](https://docs.google.com/document/d/1VRevv8JhlP4I8fIlvf87IrW2IRjE0PbkSfIcI6-UbJo/edit?usp=sharing).

@ -137,7 +137,7 @@ class UpdateManifest {
// Parses the `channels` field value of a version entry and either returns a
// set of channels on success or an error on failure. If `channels` is not
// set (i.e., `channels_value` is `absl::nullopt`), then a set containing
// set (i.e., `channels_value` is `std::nullopt`), then a set containing
// just the "default" channel is returned.
static base::expected<base::flat_set<UpdateChannelId>, absl::monostate>
ParseAndValidateChannels(
@ -167,7 +167,7 @@ class UpdateManifest {
const std::vector<VersionEntry>& versions() const { return version_entries_; }
// Returns the most up to date version contained in the `UpdateManifest` for a
// given `channel_id`. May return `absl::nullopt` if no applicable version is
// given `channel_id`. May return `std::nullopt` if no applicable version is
// found.
std::optional<VersionEntry> GetLatestVersion(
const UpdateChannelId& channel_id) const;

@ -84,7 +84,7 @@ bool WifiDirectMedium::DisconnectWifiDirect() {
}
std::unique_ptr<api::WifiDirectSocket> WifiDirectMedium::ConnectToService(
absl::string_view ip_address,
std::string_view ip_address,
int port,
CancellationFlag* cancellation_flag) {
// Ensure that there is a valid WiFi Direct connection.
@ -224,10 +224,10 @@ std::unique_ptr<api::WifiDirectServerSocket> WifiDirectMedium::ListenForService(
std::move(socket));
}
absl::optional<std::pair<std::int32_t, std::int32_t>>
std::optional<std::pair<std::int32_t, std::int32_t>>
WifiDirectMedium::GetDynamicPortRange() {
NOTIMPLEMENTED();
return absl::nullopt;
return std::nullopt;
}
void WifiDirectMedium::GetCapabilities(

@ -34,12 +34,12 @@ class WifiDirectMedium : public api::WifiDirectMedium {
bool ConnectWifiDirect(WifiDirectCredentials* credentials) override;
bool DisconnectWifiDirect() override;
std::unique_ptr<api::WifiDirectSocket> ConnectToService(
absl::string_view ip_address,
std::string_view ip_address,
int port,
CancellationFlag* cancellation_flag) override;
std::unique_ptr<api::WifiDirectServerSocket> ListenForService(
int port) override;
absl::optional<std::pair<std::int32_t, std::int32_t>> GetDynamicPortRange()
std::optional<std::pair<std::int32_t, std::int32_t>> GetDynamicPortRange()
override;
private:

@ -71,9 +71,9 @@ class MyDelegate : public FeatureUsageMetrics::Delegate {
bool IsEligible() const final {
...
}
// Optional. Default implementation returns `absl::nullopt` which do not emit
// Optional. Default implementation returns `std::nullopt` which do not emit
// any UMA events.
absl::optional<bool> IsAccessible() const final {
std::optional<bool> IsAccessible() const final {
...
}
// If `IsEnabled` returns true `IsEligible` must return true too.

@ -284,7 +284,7 @@ interface MultiDeviceSetup {
// Informs whether the user already connected their phone using OOBE Quick
// Start. If so, it returns the string of the phone instance ID. If not, it
// returns absl::nullopt. MultideviceSetup in OOBE uses this value to prefer
// returns std::nullopt. MultideviceSetup in OOBE uses this value to prefer
// the device and update UI strings if the matching phone is present.
GetQuickStartPhoneInstanceID() =>
(string? qs_phone_instance_id);

@ -193,7 +193,7 @@ interface SensorDevice {
// Gets the |attr_name| attribute of channels as a group into |values| in
// string.
// Returns absl::nullopt if the attribute in the channel cannot be read.
// Returns std::nullopt if the attribute in the channel cannot be read.
GetChannelsAttributes@8(array<int32> iio_chn_indices, string attr_name)
=> (array<string?> values);
};

@ -269,14 +269,14 @@ exiting prematurely.
Take the given (slow) function to find a non-trivial factor of a given integer:
```cpp
absl::optional<int> FindNonTrivialFactor(int n) {
std::optional<int> FindNonTrivialFactor(int n) {
// Really naive algorithm.
for (int i = 2; i < n; ++i) {
if (n % i == 0) {
return i;
}
}
return absl::nullopt;
return std::nullopt;
}
```
Write a command-line utility `factor` that takes a number, posts a task to the

@ -83,7 +83,7 @@ update
* [PermissionDescriptorInfoToPermissionType()](https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/common/permissions/permission_utils.cc;l=126;drc=caa1747121ee9f14ba7d4e346ea2dc5e7a2e05c0)
6. In [permission_controller_impl.cc](https://source.chromium.org/chromium/chromium/src/+/main:content/browser/permissions/permission_controller_impl.cc)
update [PermissionToSchedulingFeature()](https://source.chromium.org/chromium/chromium/src/+/main:content/browser/permissions/permission_controller_impl.cc;l=31;drc=a989b8968ead0d1a80b285eef0a2acf9feb71c82)
. By default the new feature should return `absl::nullopt`. That means it will
. By default the new feature should return `std::nullopt`. That means it will
not block back-forward cache. If your feature needs to block it, make sure it is
explicitly mentioned in a design doc as that needs to be reviewed.
7. In [aw_permission_manager.cc](https://source.chromium.org/chromium/chromium/src/+/main:android_webview/browser/aw_permission_manager.cc)

@ -247,7 +247,7 @@ void {clas}::ExecuteModelWithInput(
// Invalid inputs.
if (inputs.size() != kUMAFeatures.size()) {{
base::SequencedTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE, base::BindOnce(std::move(callback), absl::nullopt));
FROM_HERE, base::BindOnce(std::move(callback), std::nullopt));
return;
}}

@ -119,9 +119,9 @@ The `App`, `Readiness` and `OptionalBool` types are:
// The fields above are mandatory. Everything else below is optional.
Readiness readiness;
absl::optional<std::string> name;
absl::optional<IconKey> icon_key;
absl::optional<bool> show_in_launcher;
std::optional<std::string> name;
std::optional<IconKey> icon_key;
std::optional<bool> show_in_launcher;
// etc.
};
@ -141,8 +141,8 @@ which have the same type: `App`). Specifically, last known value wins. Any
known field in the delta overwrites the corresponding field in the old state,
any unknown field in the delta is ignored. For example, if an app's name
changed but its icon didn't, the delta's `App.name` field (a
`absl::optional<std::string>`) would be known (not `absl::nullopt`) and copied
over but its `App.icon` field would be unknown (`absl::nullopt`) and not copied
`std::optional<std::string>`) would be known (not `std::nullopt`) and copied
over but its `App.icon` field would be unknown (`std::nullopt`) and not copied
over.
The current state is thus the merger or sum of all previous deltas, including

@ -1435,7 +1435,7 @@ TEST_F(FetchLaterKeepAliveURLLoaderServiceTest,
GetLastPendingRequest()->client->OnReceiveResponse(
CreateResponseHead(
{{kAttributionReportingRegisterSourceHeader, kRegisterSourceJson}}),
/*body=*/{}, /*cached_metadata=*/absl::nullopt);
/*body=*/{}, /*cached_metadata=*/std::nullopt);
base::RunLoop().RunUntilIdle();
}

@ -98,7 +98,7 @@ struct CreateViewParams {
// The session storage namespace ID this view should use.
string session_storage_namespace_id;
// The frame token of the opener frame if one exists, or absl::nullopt
// The frame token of the opener frame if one exists, or std::nullopt
// otherwise.
blink.mojom.FrameToken? opener_frame_token;
@ -274,7 +274,7 @@ struct CreateFrameParams {
blink.mojom.FrameToken? previous_frame_token;
// Specifies the new frame's opener. The opener will be null if this is
// absl::nullopt.
// std::nullopt.
blink.mojom.FrameToken? opener_frame_token;
// The new frame should be created as a child of the object identified by

@ -548,7 +548,7 @@ class DEVICE_BLUETOOTH_EXPORT FlossDBusClient {
// Error: Invalid return.
static const char kErrorInvalidReturn[];
// Property key for absl::Optional dbus serialization.
// Property key for std::optional dbus serialization.
static const char kOptionalValueKey[];
// Error: does not exist.

@ -476,7 +476,7 @@ SkColor GetAuraColor(
NativeTheme::kColorId_ButtonColor,
color_scheme);
return color_utils::BlendForMinContrast(
bg, bg, absl::nullopt, 1.2f).color;
bg, bg, std::nullopt, 1.2f).color;
}
...
}

@ -279,7 +279,7 @@ TabGroupEditorBubbleView::TabGroupEditorBubbleView(
const Browser* browser,
const tab_groups::TabGroupId& group,
TabGroupHeader* anchor_view,
absl::optional<gfx::Rect> anchor_rect,
std::optional<gfx::Rect> anchor_rect,
bool stop_context_menu_propagation)
: ... {
@ -374,7 +374,7 @@ TabGroupEditorBubbleView::TabGroupEditorBubbleView(
const Browser* browser,
const tab_groups::TabGroupId& group,
views::View* anchor_view,
absl::optional<gfx::Rect> anchor_rect,
std::optional<gfx::Rect> anchor_rect,
TabGroupHeader* header_view,
bool stop_context_menu_propagation)
: ... {
@ -1348,4 +1348,3 @@ void TimeView::UpdateClockLayout(
```
|||---|||

@ -180,7 +180,7 @@ at run-time, getting or setting the value directly via the getter and setter is
perfectly valid.
The type converter for a non-serializable type may return something from the
ToString() method, but it will typically return absl::nullopt from the
ToString() method, but it will typically return std::nullopt from the
FromString() method. For a non-serializable type, the ui-devtools front-end
wont call the setter since whatever “value” it has is presumed to be
unconvertable to a valid value.
@ -195,4 +195,3 @@ converter specialization. This is done the same as other type converter
specializations, except for the ancestor specialization. The ancestor
`BaseTypeConverter` template takes a few `bool` parameters. The first of which
indicates whether a property type is serializable.

@ -117,7 +117,7 @@ GizmoFrobulateFunction::~ GizmoFrobulateFunction() = default;
ExtensionFunction::ResponseAction GizmoFrobulateFunction::Run() {
// We can create a typed struct of the arguments from the generated code.
absl::optional<api::gizmo::Frobulate::Params> params(
std::optional<api::gizmo::Frobulate::Params> params(
api::gizmo::Frobulate::Params::Create(args()));
// EXTENSION_FUNCTION_VALIDATE() is used to assert things that should only
@ -156,7 +156,7 @@ implement.
```
ExtensionFunction::ResponseAction GizmoFrobulateFunction::Run() {
absl::optional<api::gizmo::Frobulate::Params> params(
std::optional<api::gizmo::Frobulate::Params> params(
api::gizmo::Frobulate::Params::Create(args()));
EXTENSION_FUNCTION_VALIDATE(params);

@ -332,7 +332,7 @@ TEST_F(FrobulationApiUnitTest, CallingFrobulateKicksOffFrobulation) {
Browser* browser = CreateTestBrowser();
auto frobulate_function =
base::MakeRefCounted<FrobulationFrobulateFunction>();
absl::optional<base::Value> result(
std::optional<base::Value> result(
api_test_utils::RunFunctionAndReturnSingleResult(
frobulate_function.get(), R"([{"speed": 10, "target": "foo"}])",
browser));

@ -43,7 +43,7 @@ interface LearningTaskController {
TargetValue? default_target);
// Asynchronously predicts distribution for given |features|. |callback| will
// receive a absl::nullopt prediction when model is not available.
// receive a std::nullopt prediction when model is not available.
PredictDistribution(array<FeatureValue> features)
=> (TargetHistogram? predicted);
};

@ -233,7 +233,7 @@ auto* ukm_background_service = ukm::UkmBackgroundRecorderFactory::GetForProfile(
ukm_background_service->GetBackgroundSourceIdIfAllowed(origin, base::BindOnce(&DidGetBackgroundSourceId));
// A callback will run with an optional source ID.
void DidGetBackgroundSourceId(absl::optional<ukm::SourceId> source_id) {
void DidGetBackgroundSourceId(std::optional<ukm::SourceId> source_id) {
if (!source_id) return; // Can't record as it wasn't found in the history.
// Use the newly generated source ID.

@ -30,10 +30,10 @@ struct FirstPartySetEntry {
// This struct must match the class fields defined in
// //net/first_party_sets/first_party_set_metadata.h.
struct FirstPartySetMetadata {
// absl::nullopt indicates that the frame's site is not associated with any
// std::nullopt indicates that the frame's site is not associated with any
// First-Party Set.
FirstPartySetEntry? frame_entry;
// absl::nullopt indicates that the top frame's site is not associated with
// std::nullopt indicates that the top frame's site is not associated with
// any First-Party Set.
FirstPartySetEntry? top_frame_entry;
};
@ -90,4 +90,3 @@ struct GlobalFirstPartySets {
// The aliases contained in the manually-supplied set.
map<SchemefulSite, SchemefulSite> manual_aliases;
};

@ -176,7 +176,7 @@ struct URLRequest {
//
// [1]: https://fetch.spec.whatwg.org/#concept-request-origin
//
// |request_initiator| should be omitted (i.e. set to absl::nullopt) for
// |request_initiator| should be omitted (i.e. set to std::nullopt) for
// browser-initiated requests (e.g. navigations initiated via omnibox or
// bookmarks, internal subresource requests like fetching the SafeBrowsing
// data, etc.). Various security features may treat browser-initiated
@ -190,7 +190,7 @@ struct URLRequest {
// provided. Failure to provide a correct, verified |request_initiator| may
// lead to bypasses of CORS, ORB, SameSite cookies and other HTTP security
// features. An untrustworthy process (e.g. a renderer or a utility process)
// should not be able to trigger or influence requests with a absl::nullopt
// should not be able to trigger or influence requests with a std::nullopt
// |request_initiator|).
//
// See also:

@ -4872,7 +4872,7 @@ TEST_F(URLLoaderTest, BlockAllCookies) {
GURL cookie_url = test_server()->GetURL("/");
auto cc = net::CanonicalCookie::CreateForTesting(
cookie_url, "a=b", base::Time::Now(), absl::nullopt /* server_time */,
cookie_url, "a=b", base::Time::Now(), std::nullopt /* server_time */,
net::CookiePartitionKey::FromURLForTesting(
GURL("https://toplevelsite.com")));
@ -4901,7 +4901,7 @@ TEST_F(URLLoaderTest, BlockOnlyThirdPartyCookies) {
GURL cookie_url = test_server()->GetURL("/");
auto cc = net::CanonicalCookie::CreateForTesting(
cookie_url, "a=b", base::Time::Now(), absl::nullopt /* server_time */,
cookie_url, "a=b", base::Time::Now(), std::nullopt /* server_time */,
net::CookiePartitionKey::FromURLForTesting(
GURL("https://toplevelsite.com")));
@ -4928,7 +4928,7 @@ TEST_F(URLLoaderTest, AllowAllCookies) {
GURL cookie_url = test_server()->GetURL("/");
auto cc = net::CanonicalCookie::CreateForTesting(
cookie_url, "a=b", base::Time::Now(), absl::nullopt /* server_time */,
cookie_url, "a=b", base::Time::Now(), std::nullopt /* server_time */,
net::CookiePartitionKey::FromURLForTesting(
GURL("https://toplevelsite.com")));

@ -41,7 +41,7 @@ struct CompositorFrameMetadata {
BeginFrameAck begin_frame_ack;
uint32 frame_token;
bool send_frame_token_to_embedder;
// TODO(crbug.com/40489779): This should be a absl::optional<float>.
// TODO(crbug.com/40489779): This should be a `float?`.
bool top_controls_visible_height_set;
float top_controls_visible_height;

@ -79,7 +79,7 @@ TEST(FileSystemURLTest, CreateSibling) {
// Another CreateSibling precondition is that the sibling_name is non-empty.
// We don't test for that here because a base::SafeBaseName is designed to be
// non-empty by construction: the base::SafeBaseName::Create factory function
// returns absl::Optional<base::SafeBaseName> not base::SafeBaseName.
// returns std::optional<base::SafeBaseName> not base::SafeBaseName.
//
// See also TODO(crbug.com/40205226)
const base::SafeBaseName sibling_name =

@ -43,7 +43,7 @@ struct BackForwardCacheNotRestoredReasons {
string? name;
// List of reasons that blocked back/forward cache if any.
array<BFCacheBlockingDetailedReason> reasons;
// This will be absl::nullopt when this document is cross-origin from the main
// This will be std::nullopt when this document is cross-origin from the main
// document.
SameOriginBfcacheNotRestoredDetails? same_origin_details;
};

@ -95,7 +95,7 @@ struct UntrustworthyContextMenuParams {
// Will be empty if |link_url| is empty.
mojo_base.mojom.String16 link_text;
// The impression declared by the link. May be absl::nullopt even if
// The impression declared by the link. May be std::nullopt even if
// |link_url| is non-empty.
Impression? impression;

@ -433,7 +433,7 @@ interface RemoteFrame {
// `token`: The frame token. Used to map between RemoteFrame and
// RenderFrameProxyHost.
// `opener_frame_token`: Frame token that identifies the opener frame if one
// exists, or absl::nullopt otherwise.
// exists, or std::nullopt otherwise.
// `tree_scope_type`: Whether the owner element (e.g. <iframe>, <object>, et
// cetera) for this frame is in the document tree or the shadow tree.
// `owner_properties`: This frame's FrameOwner properties, such as scrolling,

@ -136,7 +136,7 @@ interface PageBroadcast {
// `token`: The frame token. Used to map between RemoteFrame and
// RenderFrameProxyHost.
// `opener_frame_token`: Frame token that identifies the opener frame if one
// exists, or absl::nullopt otherwise.
// exists, or std::nullopt otherwise.
// `is_loading`: Whether to call DidStartLoading() on the new main frame.
// `devtools_frame_token`: Used for devtools instrumentation and
// trace-ability. The token is shared across all frames (local or remotes)

@ -261,7 +261,7 @@ class MediaRecorderHandlerFixture : public ScopedMockOverlayScrollbars {
std::string encoded_data,
base::TimeTicks timestamp) {
media_recorder_handler_->OnEncodedAudio(params, std::move(encoded_data),
absl::nullopt, timestamp);
std::nullopt, timestamp);
}
void OnAudioBusForTesting(const media::AudioBus& audio_bus) {

@ -19,7 +19,7 @@ class XRSession;
// type T (for example XRPlane, XRAnchor). The type T has to have a
// NativeOrigin() method, returning a
// device::mojom::blink::XRNativeOriginInformationPtr, a MojoFromObject()
// method, returning a absl::Optional<gfx::Transform>, and IsStationary()
// method, returning a std::optional<gfx::Transform>, and IsStationary()
// method returning true if the object is supposed to be treated as stationary
// for the purposes of anchor creation.
//

@ -106,8 +106,9 @@ class OptionalOrRawPtrToGCedMatcher : public MatchFinder::MatchCallback {
: diagnostics_(diagnostics), record_cache_(record_cache) {}
void Register(MatchFinder& match_finder) {
// Matches fields and new-expressions of type absl::optional where the
// template argument is known to refer to a garbage-collected type.
// Matches fields and new-expressions of type std::optional or
// absl::optional where the template argument is known to refer to a
// garbage-collected type.
auto optional_gced_type = hasType(
classTemplateSpecializationDecl(
hasAnyName("::absl::optional", "::std::optional", "::base::raw_ptr",