0

Rename {absl => std}::optional in //components/

#cleanup

Automated patch. This is a no-op. Please avoid, to assign unrelated
bugs to this, as much as possible.

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 \
      -e "^components/" \
    | grep \
      -e "\.h" \
      -e "\.cc" \
      -e "\.mm" \
    | grep -v \
      -e "components/cast_streaming/browser/public/receiver_config.*" \
      -e "components/power_metrics/*" \
      -e "components/zucchini/patch_reader.*" \
    | 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 "\"third_party\/abseil-cpp\/absl\/types\/optional.h\"" "<optional>"

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"

git cl format
```

Bug: chromium:1500249
Change-Id: I34b45aba082a627d94fd9d3f9f994a60c64b40b1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5200092
Auto-Submit: Arthur Sonzogni <arthursonzogni@chromium.org>
Reviewed-by: danakj <danakj@chromium.org>
Commit-Queue: danakj <danakj@chromium.org>
Owners-Override: danakj <danakj@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1252820}
This commit is contained in:
Arthur Sonzogni
2024-01-26 20:26:18 +00:00
committed by Chromium LUCI CQ
parent f903b2778c
commit c571efbef3
2832 changed files with 13933 additions and 13834 deletions
components
access_code_cast
account_id
account_manager_core
aggregation_service
allocation_recorder
android_autofill
apdu
arc
attribution_reporting
autofill
background_sync
background_task_scheduler
blocked_content
blocklist
bookmarks
breadcrumbs
browser_sync
browser_ui
site_settings
browsing_data
browsing_topics
cast
cast_receiver
cast_streaming
cbor
cdm
chromeos_camera
client_hints
cloud_devices
commerce
component_updater
consent_auditor
content_capture
content_relationship_verification
content_settings
contextual_search
crash
cronet
crx_file
custom_handlers
desks_storage
device_reauth
device_signals
devtools
simple_devtools_protocol_client
discardable_memory
dom_distiller
domain_reliability
download
embedder_support
endpoint_fetcher
enterprise
error_page
exo
eye_dropper
favicon
feature_engagement
feed
feedback
fuchsia_component_support
fuchsia_legacymetrics
gcm_driver
global_media_controls
guest_view
gwp_asan
headless
heap_profiling
history
history_clusters
image_fetcher
invalidation
js_injection
language
lens
leveldb_proto
link_header_util
live_caption
local_state
lookalikes
manta
media_device_salt
media_message_center
media_router
memory_pressure
memory_system
metal_util
metrics
mirroring
ml
nacl
named_mojo_ipc_server
navigation_interception
net_log
network_hints
network_session_configurator
network_time
no_state_prefetch
ntp_tiles
offline_items_collection
offline_pages
omnibox
browser
actions
autocomplete_controller.ccautocomplete_controller.hautocomplete_controller_metrics_unittest.ccautocomplete_controller_unittest.ccautocomplete_grouper_sections.ccautocomplete_input.hautocomplete_match.ccautocomplete_match.hautocomplete_match_type_unittest.ccautocomplete_match_unittest.ccautocomplete_provider_unittest.ccautocomplete_result.ccautocomplete_result.hautocomplete_result_unittest.ccautocomplete_scoring_model_executor.ccautocomplete_scoring_model_executor.hautocomplete_scoring_model_executor_unittest.ccautocomplete_scoring_model_handler.ccautocomplete_scoring_model_handler.hautocomplete_scoring_model_handler_unittest.ccautocomplete_scoring_model_service.ccautocomplete_scoring_model_service.hbase_search_provider.ccbookmark_scoring_signals_annotator.ccclipboard_provider.ccclipboard_provider.hclipboard_provider_unittest.ccdocument_provider.ccdocument_provider_unittest.ccdocument_suggestions_service_unittest.cchistory_cluster_provider_unittest.cchistory_quick_provider.cchistory_quick_provider.hhistory_scoring_signals_annotator.cchistory_url_provider.ccomnibox_prefs.ccomnibox_triggered_feature_service_unittest.ccon_device_tail_model_service.ccon_device_tail_model_service_unittest.ccquery_tile_provider_unittest.ccscored_history_match.ccscored_history_match.hsearch_provider.ccsearch_suggestion_parser.ccsearch_suggestion_parser.hsearch_suggestion_parser_fuzzer.ccsearch_suggestion_parser_unittest.ccshortcuts_provider.ccshortcuts_provider_unittest.ccsuggestion_answer.ccsuggestion_answer.hsuggestion_answer_unittest.ccsuggestion_group_util.cctitled_url_match_utils.ccurl_scoring_signals_annotator.ccurl_scoring_signals_annotator_unittest.cczero_suggest_provider.cc
open_from_clipboard
openscreen_platform
optimization_guide
content
core
base_model_executor.hbase_model_executor_helpers.hbatch_entity_metadata_task.ccbatch_entity_metadata_task.hbatch_entity_metadata_task_unittest.ccbert_model_executor.ccbert_model_executor.hbert_model_executor_unittest.ccbert_model_handler.ccbert_model_handler.hcommand_line_top_host_provider.ccentity_annotator_native_library.ccentity_metadata_provider.hhint_cache_unittest.cchints_fetcher.cchints_fetcher.hhints_fetcher_unittest.cchints_manager.cchints_manager.hhints_manager_unittest.ccmediapipe_text_model_executor.ccmediapipe_text_model_executor.hmediapipe_text_model_executor_unittest.ccmemory_hint.ccmemory_hint.h
model_execution
model_executor.hmodel_handler.hmodel_handler_unittest.cc
model_quality
model_store_metadata_entry.ccmodel_store_metadata_entry.hmodel_util.ccmodel_util.hmodel_util_unittest.ccmodel_validator.ccmodel_validator.hmodel_validator_unittest.ccoptimization_guide_features.ccoptimization_guide_features.hoptimization_guide_features_unittest.ccoptimization_guide_model_provider.hoptimization_guide_navigation_data.ccoptimization_guide_navigation_data.hoptimization_guide_store.ccoptimization_guide_store.hoptimization_guide_store_unittest.ccoptimization_guide_switches.ccoptimization_guide_switches.hoptimization_guide_switches_unittest.ccoptimization_guide_util.hoptimization_guide_util_unittest.ccoptimization_hints_component_update_listener.ccoptimization_hints_component_update_listener.hoptimization_metadata.hoptimization_metadata_unittest.ccpage_content_annotation_job.ccpage_content_annotation_job.hpage_content_annotation_job_executor.hpage_content_annotation_job_executor_unittest.ccpage_content_annotation_job_unittest.ccpage_content_annotations_common.ccpage_content_annotations_common.hpage_entities_model_handler.ccpage_entities_model_handler.hpage_entities_model_handler_impl.ccpage_entities_model_handler_impl.hpage_entities_model_handler_impl_unittest.ccpage_visibility_model_executor.ccpage_visibility_model_executor.hpage_visibility_model_fuzzer.ccpage_visibility_model_handler.ccpage_visibility_model_handler.hpage_visibility_model_handler_unittest.ccprediction_manager.ccprediction_manager.hprediction_manager_unittest.ccprediction_model_download_manager.ccprediction_model_download_manager.hprediction_model_download_manager_unittest.ccprediction_model_fetch_timer_unittest.ccprediction_model_fetcher.hprediction_model_fetcher_impl.ccprediction_model_fetcher_impl.hprediction_model_fetcher_unittest.ccprediction_model_override.ccprediction_model_store.ccstore_update_data.ccstore_update_data.htest_model_executor.cctest_model_executor.htest_model_handler.htest_optimization_guide_model_provider.cctest_optimization_guide_model_provider.htest_tflite_model_executor.cctest_tflite_model_executor.htest_tflite_model_handler.htext_embedding_model_executor.cctext_embedding_model_executor.htext_embedding_model_executor_unittest.cctext_embedding_model_handler.cctext_embedding_model_handler.htext_embedding_model_handler_unittest.cctflite_model_executor.htflite_model_executor_unittest.cc
origin_trials
os_crypt
ownership
page_image_annotation
page_image_service
page_info
page_load_metrics
browser
common
renderer
paint_preview
password_manager
payments
pdf
performance_manager
decorators
execution_context_priority
freezing
graph
performance_manager_lifetime.cc
persistence
power
public
resource_attribution
test_support
user_tuning
v8_memory
permissions
android
bluetooth_delegate_impl.ccbluetooth_delegate_impl.h
contexts
notifications_engagement_service.ccnotifications_engagement_service.hobject_permission_context_base.ccobject_permission_context_base.horigin_keyed_permission_action_service.ccorigin_keyed_permission_action_service.hpepc_initiated_permission_request_unittest.ccpermission_actions_history.ccpermission_actions_history_unittest.ccpermission_auditing_database.ccpermission_auditing_database.hpermission_auditing_database_unittest.ccpermission_auditing_service.hpermission_auditing_service_unittest.ccpermission_context_base.ccpermission_context_base.hpermission_context_base_unittest.ccpermission_decision_auto_blocker.ccpermission_decision_auto_blocker.hpermission_decision_auto_blocker_unittest.ccpermission_manager.ccpermission_manager.hpermission_manager_unittest.ccpermission_prompt.hpermission_recovery_success_rate_tracker.hpermission_request.ccpermission_request.hpermission_request_data.hpermission_request_manager.ccpermission_request_manager.hpermission_request_manager_unittest.ccpermission_ui_selector.ccpermission_ui_selector.hpermission_uma_util.ccpermission_uma_util.hpermission_uma_util_unittest.ccpermission_util.ccpermission_util.hpermissions_client.ccpermissions_client.h
prediction_service
request_type.ccrequest_type.h
test
plugins
plus_addresses
policy
content
core
browser
common
test_support
power_bookmarks
prefs
printing
privacy_sandbox
proxy_config
qr_code_generator
query_tiles
quirks
reading_list
reduce_accept_language
remote_cocoa
renderer_context_menu
reporting
safe_browsing
android
content
core
safe_search_api
saved_tab_groups
schema_org
search
search_engines
search_provider_logos
security_interstitials
segmentation_platform
embedder
internal
config_parser.cc
data_collection
database
execution
metadata
metrics
migration
post_processor
scheduler
segment_id_convertor.ccsegment_id_convertor.hsegmentation_platform_service_impl.ccsegmentation_platform_service_impl.hsegmentation_ukm_helper.ccsegmentation_ukm_helper.hsegmentation_ukm_helper_unittest.cc
selection
service_proxy_impl.ccservice_proxy_impl.h
signals
stats.ccstats.hstats_unittest.ccukm_data_manager_impl.hukm_data_manager_impl_unittest.cc
public
send_tab_to_self
services
app_service
filesystem
font
heap_profiling
paint_preview_compositor
screen_ai
storage
dom_storage
indexed_db
partition_impl.ccpartition_impl.hpartition_impl_unittest.cc
public
service_worker
shared_storage
storage_service_impl.ccstorage_service_impl.hstorage_service_impl_unittest.cc
session_proto_db
sessions
shared_highlighting
signin
core
internal
ios
public
site_engagement
site_isolation
soda
spellcheck
sqlite_proto
startup_metric_utils
subresource_filter
supervised_user
sync
base
engine
invalidations
model
nigori
service
test
sync_bookmarks
sync_device_info
sync_preferences
sync_sessions
sync_user_events
system_cpu
system_media_controls
thin_webview
tpcd
metadata
tracing
translate
trusted_vault
ui_devtools
ukm
unexportable_keys
unified_consent
update_client
upload_list
url_pattern_index
url_rewrite
user_education
user_manager
user_notes
value_store
visitedlink
viz
client
common
demo
host
service
compositor_frame_fuzzer
debugger
display
aggregated_frame.hca_layer_overlay.hcopy_output_scaling_pixeltest.ccdc_layer_overlay.ccdelegated_ink_point_renderer_base.ccdelegated_ink_point_renderer_base.hdelegated_ink_trail_data.ccdelegated_ink_trail_data.hdirect_renderer.ccdirect_renderer.hdisplay.ccdisplay_damage_tracker.hdisplay_perftest.ccdisplay_resource_provider_skia_unittest.ccdisplay_scheduler.hdisplay_scheduler_base.hdisplay_unittest.ccexternal_use_client.ccexternal_use_client.hframe_rate_decider.ccframe_rate_decider_unittest.ccoutput_surface.houtput_surface_frame.hoverlay_ca_unittest.ccoverlay_candidate.hoverlay_candidate_factory.ccoverlay_candidate_factory.hoverlay_candidate_factory_unittest.ccoverlay_dc_unittest.ccoverlay_processor_delegated.ccoverlay_processor_delegated.hoverlay_processor_interface.hoverlay_processor_mac.ccoverlay_processor_mac.hoverlay_processor_stub.hoverlay_processor_surface_control.ccoverlay_processor_surface_control.hoverlay_processor_surface_control_unittest.ccoverlay_processor_using_strategy.ccoverlay_processor_using_strategy.hoverlay_processor_win.hoverlay_proposed_candidate_unittest.ccoverlay_unittest.ccpending_swap_params.hrenderer_perftest.ccrenderer_pixeltest.ccresolved_frame_data.ccresolved_frame_data.hresolved_frame_data_unittest.ccskia_readback_pixeltest.ccskia_renderer.ccskia_renderer.hsoftware_renderer.ccsoftware_renderer.hsoftware_renderer_unittest.ccsurface_aggregator.ccsurface_aggregator.hsurface_aggregator_perftest.ccsurface_aggregator_pixeltest.ccsurface_aggregator_unittest.ccviz_perftest.ccviz_perftest.h
display_embedder
frame_sinks
gl
hit_test
main
surfaces
transitions
test
web_cache
web_modal
web_package
webapps
webauthn
webcrypto
webrtc
webrtc_logging
wifi
winhttp
zoom
zucchini

@ -308,7 +308,7 @@ TEST(AccessCodeCastMetricsTest, CheckMetricsEnums) {
base::HistogramTester histogram_tester;
// AddSinkResult
absl::optional<base::HistogramEnumEntryMap> add_sink_results =
std::optional<base::HistogramEnumEntryMap> add_sink_results =
base::ReadEnumFromEnumsXml("AccessCodeCastAddSinkResult");
EXPECT_TRUE(add_sink_results->size() ==
static_cast<int>(AccessCodeCastAddSinkResult::kMaxValue) + 1)
@ -317,7 +317,7 @@ TEST(AccessCodeCastMetricsTest, CheckMetricsEnums) {
"enums.xml to match.";
// CastMode
absl::optional<base::HistogramEnumEntryMap> cast_modes =
std::optional<base::HistogramEnumEntryMap> cast_modes =
base::ReadEnumFromEnumsXml("AccessCodeCastCastMode");
EXPECT_TRUE(cast_modes->size() ==
static_cast<int>(AccessCodeCastCastMode::kMaxValue) + 1)
@ -326,7 +326,7 @@ TEST(AccessCodeCastMetricsTest, CheckMetricsEnums) {
"enums.xml to match.";
// DialogCloseReason
absl::optional<base::HistogramEnumEntryMap> dialog_close_reasons =
std::optional<base::HistogramEnumEntryMap> dialog_close_reasons =
base::ReadEnumFromEnumsXml("AccessCodeCastDialogCloseReason");
EXPECT_TRUE(dialog_close_reasons->size() ==
static_cast<int>(AccessCodeCastDialogCloseReason::kMaxValue) + 1)
@ -335,7 +335,7 @@ TEST(AccessCodeCastMetricsTest, CheckMetricsEnums) {
"enums.xml to match.";
// DialogOpenLocation
absl::optional<base::HistogramEnumEntryMap> dialog_open_locations =
std::optional<base::HistogramEnumEntryMap> dialog_open_locations =
base::ReadEnumFromEnumsXml("AccessCodeCastDialogOpenLocation");
EXPECT_TRUE(dialog_open_locations->size() ==
static_cast<int>(AccessCodeCastDialogOpenLocation::kMaxValue) + 1)
@ -344,7 +344,7 @@ TEST(AccessCodeCastMetricsTest, CheckMetricsEnums) {
"enums.xml to match.";
// DiscoveryTypeAndSource
absl::optional<base::HistogramEnumEntryMap> discovery_types_and_sources =
std::optional<base::HistogramEnumEntryMap> discovery_types_and_sources =
base::ReadEnumFromEnumsXml("AccessCodeCastDiscoveryTypeAndSource");
EXPECT_TRUE(
discovery_types_and_sources->size() ==

@ -241,7 +241,7 @@ std::string AccountId::Serialize() const {
// static
bool AccountId::Deserialize(const std::string& serialized,
AccountId* account_id) {
absl::optional<base::Value> value(base::JSONReader::Read(serialized));
std::optional<base::Value> value(base::JSONReader::Read(serialized));
if (!value || !value->is_dict())
return false;

@ -133,7 +133,7 @@ class COMPONENT_EXPORT(ACCOUNT_MANAGER_CORE) AccountManagerFacade {
// Launches account addition dialog and calls the `callback` with the result.
// If `result` is `kSuccess`, the added account will be passed to the
// callback. Otherwise `account` will be set to `absl::nullopt`.
// callback. Otherwise `account` will be set to `std::nullopt`.
virtual void ShowAddAccountDialog(
AccountAdditionSource source,
base::OnceCallback<void(const AccountUpsertionResult& result)>

@ -5,6 +5,7 @@
#include "components/account_manager_core/account_manager_facade_impl.h"
#include <memory>
#include <optional>
#include <string>
#include <utility>
#include <vector>
@ -27,7 +28,6 @@
#include "google_apis/gaia/oauth2_access_token_consumer.h"
#include "google_apis/gaia/oauth2_access_token_fetcher.h"
#include "google_apis/gaia/oauth2_access_token_fetcher_immediate_error.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
namespace account_manager {
@ -52,7 +52,7 @@ void UnmarshalAccounts(
std::vector<crosapi::mojom::AccountPtr> mojo_accounts) {
std::vector<Account> accounts;
for (const auto& mojo_account : mojo_accounts) {
absl::optional<Account> maybe_account = FromMojoAccount(mojo_account);
std::optional<Account> maybe_account = FromMojoAccount(mojo_account);
if (!maybe_account) {
// Skip accounts we couldn't unmarshal. No logging, as it would produce
// a lot of noise.
@ -66,7 +66,7 @@ void UnmarshalAccounts(
void UnmarshalPersistentError(
base::OnceCallback<void(const GoogleServiceAuthError&)> callback,
crosapi::mojom::GoogleServiceAuthErrorPtr mojo_error) {
absl::optional<GoogleServiceAuthError> maybe_error =
std::optional<GoogleServiceAuthError> maybe_error =
FromMojoGoogleServiceAuthError(mojo_error);
if (!maybe_error) {
// Couldn't unmarshal GoogleServiceAuthError, report the account as not
@ -237,7 +237,7 @@ class AccountManagerFacadeImpl::AccessTokenFetcher
is_request_pending_ = false;
if (result->is_error()) {
absl::optional<GoogleServiceAuthError> maybe_error =
std::optional<GoogleServiceAuthError> maybe_error =
account_manager::FromMojoGoogleServiceAuthError(result->get_error());
if (!maybe_error.has_value()) {
@ -546,7 +546,7 @@ void AccountManagerFacadeImpl::OnSigninDialogActionFinished(
base::OnceCallback<
void(const account_manager::AccountUpsertionResult& result)> callback,
crosapi::mojom::AccountUpsertionResultPtr mojo_result) {
absl::optional<account_manager::AccountUpsertionResult> result =
std::optional<account_manager::AccountUpsertionResult> result =
account_manager::FromMojoAccountUpsertionResult(mojo_result);
if (!result.has_value()) {
FinishUpsertAccount(
@ -568,7 +568,7 @@ void AccountManagerFacadeImpl::FinishUpsertAccount(
void AccountManagerFacadeImpl::OnTokenUpserted(
crosapi::mojom::AccountPtr account) {
absl::optional<Account> maybe_account = FromMojoAccount(account);
std::optional<Account> maybe_account = FromMojoAccount(account);
if (!maybe_account) {
LOG(WARNING) << "Can't unmarshal account of type: "
<< account->key->account_type;
@ -581,7 +581,7 @@ void AccountManagerFacadeImpl::OnTokenUpserted(
void AccountManagerFacadeImpl::OnAccountRemoved(
crosapi::mojom::AccountPtr account) {
absl::optional<Account> maybe_account = FromMojoAccount(account);
std::optional<Account> maybe_account = FromMojoAccount(account);
if (!maybe_account) {
LOG(WARNING) << "Can't unmarshal account of type: "
<< account->key->account_type;
@ -595,14 +595,14 @@ void AccountManagerFacadeImpl::OnAccountRemoved(
void AccountManagerFacadeImpl::OnAuthErrorChanged(
crosapi::mojom::AccountKeyPtr account,
crosapi::mojom::GoogleServiceAuthErrorPtr error) {
absl::optional<AccountKey> maybe_account_key = FromMojoAccountKey(account);
std::optional<AccountKey> maybe_account_key = FromMojoAccountKey(account);
if (!maybe_account_key) {
LOG(WARNING) << "Can't unmarshal account key of type: "
<< account->account_type;
return;
}
absl::optional<GoogleServiceAuthError> maybe_error =
std::optional<GoogleServiceAuthError> maybe_error =
FromMojoGoogleServiceAuthError(error);
if (!maybe_error) {
LOG(WARNING) << "Can't unmarshal error with state: " << error->state;

@ -159,7 +159,7 @@ class FakeAccountManager : public crosapi::mojom::AccountManager {
void GetPersistentErrorForAccount(
crosapi::mojom::AccountKeyPtr mojo_account_key,
GetPersistentErrorForAccountCallback callback) override {
absl::optional<AccountKey> account_key =
std::optional<AccountKey> account_key =
FromMojoAccountKey(mojo_account_key);
DCHECK(account_key.has_value());
auto it = persistent_errors_.find(account_key.value());
@ -256,7 +256,7 @@ class FakeAccountManager : public crosapi::mojom::AccountManager {
return show_add_account_dialog_calls_;
}
absl::optional<account_manager::AccountAdditionOptions>
std::optional<account_manager::AccountAdditionOptions>
show_add_account_dialog_options() const {
return show_add_account_dialog_options_;
}
@ -271,7 +271,7 @@ class FakeAccountManager : public crosapi::mojom::AccountManager {
private:
int show_add_account_dialog_calls_ = 0;
absl::optional<account_manager::AccountAdditionOptions>
std::optional<account_manager::AccountAdditionOptions>
show_add_account_dialog_options_;
int show_reauth_account_dialog_calls_ = 0;
int show_manage_accounts_settings_calls_ = 0;

@ -4,12 +4,13 @@
#include "components/account_manager_core/account_manager_util.h"
#include <optional>
#include "base/notreached.h"
#include "components/account_manager_core/account.h"
#include "components/account_manager_core/account_addition_options.h"
#include "components/account_manager_core/account_upsertion_result.h"
#include "google_apis/gaia/google_service_auth_error.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
namespace account_manager {
@ -98,7 +99,7 @@ crosapi::mojom::GoogleServiceAuthError::State ToMojoGoogleServiceAuthErrorState(
}
}
absl::optional<account_manager::AccountUpsertionResult::Status>
std::optional<account_manager::AccountUpsertionResult::Status>
FromMojoAccountAdditionStatus(
crosapi::mojom::AccountUpsertionResult::Status mojo_status) {
switch (mojo_status) {
@ -119,7 +120,7 @@ FromMojoAccountAdditionStatus(
default:
LOG(WARNING) << "Unknown crosapi::mojom::AccountUpsertionResult::Status: "
<< mojo_status;
return absl::nullopt;
return std::nullopt;
}
}
@ -155,16 +156,16 @@ crosapi::mojom::AccountUpsertionResult::Status ToMojoAccountAdditionStatus(
} // namespace
absl::optional<account_manager::Account> FromMojoAccount(
std::optional<account_manager::Account> FromMojoAccount(
const crosapi::mojom::AccountPtr& mojom_account) {
if (mojom_account.is_null()) {
return absl::nullopt;
return std::nullopt;
}
const absl::optional<account_manager::AccountKey> account_key =
const std::optional<account_manager::AccountKey> account_key =
FromMojoAccountKey(mojom_account->key);
if (!account_key.has_value())
return absl::nullopt;
return std::nullopt;
account_manager::Account account{account_key.value(),
mojom_account->raw_email};
@ -179,18 +180,18 @@ crosapi::mojom::AccountPtr ToMojoAccount(
return mojom_account;
}
absl::optional<account_manager::AccountKey> FromMojoAccountKey(
std::optional<account_manager::AccountKey> FromMojoAccountKey(
const crosapi::mojom::AccountKeyPtr& mojom_account_key) {
if (mojom_account_key.is_null()) {
return absl::nullopt;
return std::nullopt;
}
const absl::optional<account_manager::AccountType> account_type =
const std::optional<account_manager::AccountType> account_type =
FromMojoAccountType(mojom_account_key->account_type);
if (!account_type.has_value())
return absl::nullopt;
return std::nullopt;
if (mojom_account_key->id.empty())
return absl::nullopt;
return std::nullopt;
return account_manager::AccountKey(mojom_account_key->id,
account_type.value());
@ -206,7 +207,7 @@ crosapi::mojom::AccountKeyPtr ToMojoAccountKey(
return mojom_account_key;
}
absl::optional<account_manager::AccountType> FromMojoAccountType(
std::optional<account_manager::AccountType> FromMojoAccountType(
const crosapi::mojom::AccountType& account_type) {
switch (account_type) {
case crosapi::mojom::AccountType::kGaia:
@ -224,7 +225,7 @@ absl::optional<account_manager::AccountType> FromMojoAccountType(
// Don't consider this as as error to preserve forwards compatibility with
// lacros.
LOG(WARNING) << "Unknown account type: " << account_type;
return absl::nullopt;
return std::nullopt;
}
}
@ -238,10 +239,10 @@ crosapi::mojom::AccountType ToMojoAccountType(
}
}
absl::optional<GoogleServiceAuthError> FromMojoGoogleServiceAuthError(
std::optional<GoogleServiceAuthError> FromMojoGoogleServiceAuthError(
const crosapi::mojom::GoogleServiceAuthErrorPtr& mojo_error) {
if (mojo_error.is_null()) {
return absl::nullopt;
return std::nullopt;
}
switch (mojo_error->state) {
@ -279,7 +280,7 @@ absl::optional<GoogleServiceAuthError> FromMojoGoogleServiceAuthError(
default:
LOG(WARNING) << "Unknown crosapi::mojom::GoogleServiceAuthError::State: "
<< mojo_error->state;
return absl::nullopt;
return std::nullopt;
}
}
@ -305,32 +306,32 @@ crosapi::mojom::GoogleServiceAuthErrorPtr ToMojoGoogleServiceAuthError(
return mojo_result;
}
absl::optional<account_manager::AccountUpsertionResult>
std::optional<account_manager::AccountUpsertionResult>
FromMojoAccountUpsertionResult(
const crosapi::mojom::AccountUpsertionResultPtr& mojo_result) {
if (mojo_result.is_null()) {
return absl::nullopt;
return std::nullopt;
}
absl::optional<account_manager::AccountUpsertionResult::Status> status =
std::optional<account_manager::AccountUpsertionResult::Status> status =
FromMojoAccountAdditionStatus(mojo_result->status);
if (!status.has_value())
return absl::nullopt;
return std::nullopt;
switch (status.value()) {
case account_manager::AccountUpsertionResult::Status::kSuccess: {
absl::optional<account_manager::Account> account =
std::optional<account_manager::Account> account =
FromMojoAccount(mojo_result->account);
if (!account.has_value())
return absl::nullopt;
return std::nullopt;
return account_manager::AccountUpsertionResult::FromAccount(
account.value());
}
case account_manager::AccountUpsertionResult::Status::kNetworkError: {
absl::optional<GoogleServiceAuthError> net_error =
std::optional<GoogleServiceAuthError> net_error =
FromMojoGoogleServiceAuthError(mojo_result->error);
if (!net_error.has_value())
return absl::nullopt;
return std::nullopt;
return account_manager::AccountUpsertionResult::FromError(
net_error.value());
}
@ -364,11 +365,11 @@ crosapi::mojom::AccountUpsertionResultPtr ToMojoAccountUpsertionResult(
return mojo_result;
}
absl::optional<account_manager::AccountAdditionOptions>
std::optional<account_manager::AccountAdditionOptions>
FromMojoAccountAdditionOptions(
const crosapi::mojom::AccountAdditionOptionsPtr& mojo_options) {
if (mojo_options.is_null()) {
return absl::nullopt;
return std::nullopt;
}
account_manager::AccountAdditionOptions result;

@ -5,48 +5,49 @@
#ifndef COMPONENTS_ACCOUNT_MANAGER_CORE_ACCOUNT_MANAGER_UTIL_H_
#define COMPONENTS_ACCOUNT_MANAGER_CORE_ACCOUNT_MANAGER_UTIL_H_
#include <optional>
#include "chromeos/crosapi/mojom/account_manager.mojom.h"
#include "components/account_manager_core/account.h"
#include "components/account_manager_core/account_addition_options.h"
#include "components/account_manager_core/account_upsertion_result.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
class GoogleServiceAuthError;
namespace account_manager {
// Returns `absl::nullopt` if `mojom_account` cannot be parsed.
// Returns `std::nullopt` if `mojom_account` cannot be parsed.
COMPONENT_EXPORT(ACCOUNT_MANAGER_CORE)
absl::optional<account_manager::Account> FromMojoAccount(
std::optional<account_manager::Account> FromMojoAccount(
const crosapi::mojom::AccountPtr& mojom_account);
COMPONENT_EXPORT(ACCOUNT_MANAGER_CORE)
crosapi::mojom::AccountPtr ToMojoAccount(
const account_manager::Account& account);
// Returns `absl::nullopt` if `mojom_account_key` cannot be parsed.
// Returns `std::nullopt` if `mojom_account_key` cannot be parsed.
COMPONENT_EXPORT(ACCOUNT_MANAGER_CORE)
absl::optional<account_manager::AccountKey> FromMojoAccountKey(
std::optional<account_manager::AccountKey> FromMojoAccountKey(
const crosapi::mojom::AccountKeyPtr& mojom_account_key);
COMPONENT_EXPORT(ACCOUNT_MANAGER_CORE)
crosapi::mojom::AccountKeyPtr ToMojoAccountKey(
const account_manager::AccountKey& account_key);
// Returns `absl::nullopt` if `account_type` cannot be parsed.
// Returns `std::nullopt` if `account_type` cannot be parsed.
COMPONENT_EXPORT(ACCOUNT_MANAGER_CORE)
absl::optional<account_manager::AccountType> FromMojoAccountType(
std::optional<account_manager::AccountType> FromMojoAccountType(
const crosapi::mojom::AccountType& account_type);
COMPONENT_EXPORT(ACCOUNT_MANAGER_CORE)
crosapi::mojom::AccountType ToMojoAccountType(
const account_manager::AccountType& account_type);
// Returns `absl::nullopt` if `mojo_error` cannot be parsed. This probably means
// Returns `std::nullopt` if `mojo_error` cannot be parsed. This probably means
// that a new error type was added, so it should be considered a persistent
// error.
COMPONENT_EXPORT(ACCOUNT_MANAGER_CORE)
absl::optional<GoogleServiceAuthError> FromMojoGoogleServiceAuthError(
std::optional<GoogleServiceAuthError> FromMojoGoogleServiceAuthError(
const crosapi::mojom::GoogleServiceAuthErrorPtr& mojo_error);
COMPONENT_EXPORT(ACCOUNT_MANAGER_CORE)
@ -54,7 +55,7 @@ crosapi::mojom::GoogleServiceAuthErrorPtr ToMojoGoogleServiceAuthError(
GoogleServiceAuthError error);
COMPONENT_EXPORT(ACCOUNT_MANAGER_CORE)
absl::optional<account_manager::AccountUpsertionResult>
std::optional<account_manager::AccountUpsertionResult>
FromMojoAccountUpsertionResult(
const crosapi::mojom::AccountUpsertionResultPtr& mojo_result);
@ -63,7 +64,7 @@ crosapi::mojom::AccountUpsertionResultPtr ToMojoAccountUpsertionResult(
account_manager::AccountUpsertionResult result);
COMPONENT_EXPORT(ACCOUNT_MANAGER_CORE)
absl::optional<account_manager::AccountAdditionOptions>
std::optional<account_manager::AccountAdditionOptions>
FromMojoAccountAdditionOptions(
const crosapi::mojom::AccountAdditionOptionsPtr& mojo_options);
} // namespace account_manager

@ -13,7 +13,7 @@ namespace account_manager {
AccountUpsertionResult AccountUpsertionResult::FromStatus(Status status) {
DCHECK_NE(status, Status::kSuccess);
DCHECK_NE(status, Status::kNetworkError);
return AccountUpsertionResult(status, /*account=*/absl::nullopt,
return AccountUpsertionResult(status, /*account=*/std::nullopt,
GoogleServiceAuthError::AuthErrorNone());
}
@ -29,7 +29,7 @@ AccountUpsertionResult AccountUpsertionResult::FromError(
const GoogleServiceAuthError& error) {
DCHECK_NE(error.state(), GoogleServiceAuthError::NONE);
return AccountUpsertionResult(Status::kNetworkError,
/*account=*/absl::nullopt, error);
/*account=*/std::nullopt, error);
}
AccountUpsertionResult::AccountUpsertionResult(const AccountUpsertionResult&) =
@ -42,7 +42,7 @@ AccountUpsertionResult::~AccountUpsertionResult() = default;
AccountUpsertionResult::AccountUpsertionResult(
Status status,
const absl::optional<Account>& account,
const std::optional<Account>& account,
const GoogleServiceAuthError& error)
: status_(status), account_(account), error_(error) {
DCHECK_EQ(account.has_value(), status == Status::kSuccess);

@ -5,9 +5,10 @@
#ifndef COMPONENTS_ACCOUNT_MANAGER_CORE_ACCOUNT_UPSERTION_RESULT_H_
#define COMPONENTS_ACCOUNT_MANAGER_CORE_ACCOUNT_UPSERTION_RESULT_H_
#include <optional>
#include "components/account_manager_core/account.h"
#include "google_apis/gaia/google_service_auth_error.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
namespace account_manager {
@ -50,11 +51,11 @@ class COMPONENT_EXPORT(ACCOUNT_MANAGER_CORE) AccountUpsertionResult {
static AccountUpsertionResult FromError(const GoogleServiceAuthError& error);
// If `status` is `kSuccess`, the reauthenticated/added account will be
// returned from `account`. Otherwise `account` will be `absl::nullopt`.
// returned from `account`. Otherwise `account` will be `std::nullopt`.
Status status() const { return status_; }
// The account that was added. Set iff `status` is set to `kSuccess`.
const absl::optional<Account>& account() const { return account_; }
const std::optional<Account>& account() const { return account_; }
// The error state is NONE unless `status` is set to `kNetworkError`.
const GoogleServiceAuthError& error() const { return error_; }
@ -65,11 +66,11 @@ class COMPONENT_EXPORT(ACCOUNT_MANAGER_CORE) AccountUpsertionResult {
private:
AccountUpsertionResult(Status status,
const absl::optional<Account>& account,
const std::optional<Account>& account,
const GoogleServiceAuthError& error);
Status status_;
absl::optional<Account> account_;
std::optional<Account> account_;
GoogleServiceAuthError error_;
};

@ -30,7 +30,7 @@ AccessTokenFetcher::AccessTokenFetcher(
receiver_.set_disconnect_handler(base::BindOnce(
&AccessTokenFetcher::OnMojoPipeError, base::Unretained(this)));
absl::optional<account_manager::AccountKey> maybe_account_key =
std::optional<account_manager::AccountKey> maybe_account_key =
account_manager::FromMojoAccountKey(mojo_account_key);
if (maybe_account_key.has_value()) {
access_token_fetcher_ = account_manager->CreateAccessTokenFetcher(

@ -5,6 +5,7 @@
#include "components/account_manager_core/chromeos/account_manager.h"
#include <memory>
#include <optional>
#include <string>
#include <utility>
@ -38,7 +39,6 @@
#include "google_apis/gaia/google_service_auth_error.h"
#include "google_apis/gaia/oauth2_access_token_consumer.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "third_party/protobuf/src/google/protobuf/message_lite.h"
namespace account_manager {
@ -81,11 +81,11 @@ void RecordInitializationTime(
}
// Returns `nullopt` if `account_type` is `ACCOUNT_TYPE_UNSPECIFIED`.
absl::optional<::account_manager::AccountType> FromProtoAccountType(
std::optional<::account_manager::AccountType> FromProtoAccountType(
const internal::AccountType& account_type) {
switch (account_type) {
case internal::AccountType::ACCOUNT_TYPE_UNSPECIFIED:
return absl::nullopt;
return std::nullopt;
case internal::AccountType::ACCOUNT_TYPE_GAIA:
static_assert(
static_cast<int>(internal::AccountType::ACCOUNT_TYPE_GAIA) ==
@ -243,7 +243,7 @@ class AccountManager::AccessTokenFetcher : public OAuth2AccessTokenFetcher {
return;
}
absl::optional<std::string> maybe_token =
std::optional<std::string> maybe_token =
account_manager_->GetRefreshToken(account_key_);
if (!maybe_token.has_value()) {
FireOnGetTokenFailure(GoogleServiceAuthError(
@ -413,7 +413,7 @@ AccountManager::AccountMap AccountManager::LoadAccountsFromDisk(
bool is_any_account_corrupt = false;
for (const auto& account : accounts_proto.accounts()) {
const absl::optional<::account_manager::AccountType> account_type =
const std::optional<::account_manager::AccountType> account_type =
FromProtoAccountType(account.account_type());
if (!account_type.has_value()) {
LOG(WARNING) << "Ignoring invalid account_type load from disk";
@ -836,7 +836,7 @@ bool AccountManager::IsEphemeralMode() const {
return home_dir_.empty();
}
absl::optional<std::string> AccountManager::GetRefreshToken(
std::optional<std::string> AccountManager::GetRefreshToken(
const ::account_manager::AccountKey& account_key) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK_EQ(init_state_, InitializationState::kInitialized);
@ -844,10 +844,10 @@ absl::optional<std::string> AccountManager::GetRefreshToken(
auto it = accounts_.find(account_key);
if (it == accounts_.end() || it->second.token.empty()) {
return absl::nullopt;
return std::nullopt;
}
return absl::make_optional<std::string>(it->second.token);
return std::make_optional<std::string>(it->second.token);
}
scoped_refptr<network::SharedURLLoaderFactory>

@ -7,6 +7,7 @@
#include <map>
#include <memory>
#include <optional>
#include <ostream>
#include <string>
#include <utility>
@ -21,7 +22,6 @@
#include "base/observer_list.h"
#include "base/sequence_checker.h"
#include "components/account_manager_core/account.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
class OAuth2AccessTokenFetcher;
class OAuth2AccessTokenConsumer;
@ -340,7 +340,7 @@ class COMPONENT_EXPORT(ACCOUNT_MANAGER_CORE) AccountManager {
// Returns the refresh token for `account_key`, if present. `account_key` must
// be a Gaia account. Assumes that `AccountManager` initialization
// (`init_state_`) is complete.
absl::optional<std::string> GetRefreshToken(
std::optional<std::string> GetRefreshToken(
const ::account_manager::AccountKey& account_key);
// Returns `url_loader_factory_`. Assumes that `AccountManager` initialization

@ -6,6 +6,7 @@
#include <algorithm>
#include <memory>
#include <optional>
#include <utility>
#include "base/containers/contains.h"
@ -25,7 +26,6 @@
#include "google_apis/gaia/google_service_auth_error.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
namespace crosapi {
@ -101,7 +101,7 @@ void AccountManagerMojoService::GetAccounts(
void AccountManagerMojoService::GetPersistentErrorForAccount(
mojom::AccountKeyPtr mojo_account_key,
mojom::AccountManager::GetPersistentErrorForAccountCallback callback) {
absl::optional<account_manager::AccountKey> maybe_account_key =
std::optional<account_manager::AccountKey> maybe_account_key =
account_manager::FromMojoAccountKey(mojo_account_key);
DCHECK(maybe_account_key)
<< "Can't unmarshal account of type: " << mojo_account_key->account_type;
@ -182,7 +182,7 @@ void AccountManagerMojoService::CreateAccessTokenFetcher(
void AccountManagerMojoService::ReportAuthError(
mojom::AccountKeyPtr mojo_account_key,
mojom::GoogleServiceAuthErrorPtr mojo_error) {
absl::optional<account_manager::AccountKey> maybe_account_key =
std::optional<account_manager::AccountKey> maybe_account_key =
account_manager::FromMojoAccountKey(mojo_account_key);
base::UmaHistogramBoolean("AccountManager.ReportAuthError.IsAccountKeyEmpty",
!maybe_account_key.has_value());
@ -192,7 +192,7 @@ void AccountManagerMojoService::ReportAuthError(
return;
}
absl::optional<GoogleServiceAuthError> maybe_error =
std::optional<GoogleServiceAuthError> maybe_error =
account_manager::FromMojoGoogleServiceAuthError(mojo_error);
if (!maybe_error) {
// Newer version of Lacros may have reported an error that older version of

@ -6,6 +6,7 @@
#include <cstddef>
#include <memory>
#include <optional>
#include <string>
#include <utility>
#include <vector>
@ -31,7 +32,6 @@
#include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h"
#include "services/network/test/test_url_loader_factory.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
namespace crosapi {
@ -130,10 +130,10 @@ class TestAccountManagerObserver
int num_account_removed_calls_ = 0;
int num_auth_errors_ = 0;
int num_signin_dialog_closed_notifications_ = 0;
absl::optional<account_manager::Account> last_upserted_account_;
absl::optional<account_manager::Account> last_removed_account_;
absl::optional<account_manager::AccountKey> last_err_account_;
absl::optional<GoogleServiceAuthError> last_error_;
std::optional<account_manager::Account> last_upserted_account_;
std::optional<account_manager::Account> last_removed_account_;
std::optional<account_manager::AccountKey> last_err_account_;
std::optional<GoogleServiceAuthError> last_error_;
mojo::Receiver<mojom::AccountManagerObserver> receiver_;
};
@ -165,7 +165,7 @@ class AccountManagerSpy : public account_manager::AccountManager {
private:
// Mutated by const CreateAccessTokenFetcher.
mutable int num_access_token_fetches_ = 0;
mutable absl::optional<account_manager::AccountKey>
mutable std::optional<account_manager::AccountKey>
last_access_token_account_key_;
};
@ -462,7 +462,7 @@ TEST_F(AccountManagerMojoServiceTest,
// Check status.
EXPECT_EQ(mojom::AccountUpsertionResult::Status::kSuccess, result->status);
// Check account.
absl::optional<account_manager::Account> account =
std::optional<account_manager::Account> account =
account_manager::FromMojoAccount(result->account);
EXPECT_TRUE(account.has_value());
EXPECT_EQ(kFakeAccount.key, account.value().key);
@ -490,7 +490,7 @@ TEST_F(AccountManagerMojoServiceTest,
// Check status.
EXPECT_EQ(mojom::AccountUpsertionResult::Status::kSuccess, result->status);
// Check account.
absl::optional<account_manager::Account> account =
std::optional<account_manager::Account> account =
account_manager::FromMojoAccount(result->account);
EXPECT_TRUE(account.has_value());
EXPECT_EQ(kFakeAccount.key, account.value().key);
@ -527,7 +527,7 @@ TEST_F(AccountManagerMojoServiceTest,
EXPECT_EQ(mojom::AccountUpsertionResult::Status::kSuccess, result->status);
// Check account.
absl::optional<account_manager::Account> account =
std::optional<account_manager::Account> account =
account_manager::FromMojoAccount(result->account);
EXPECT_TRUE(account.has_value());
EXPECT_EQ(kFakeAccount.key, account.value().key);
@ -552,7 +552,7 @@ TEST_F(AccountManagerMojoServiceTest,
auto result = future.Take();
EXPECT_EQ(mojom::AccountUpsertionResult::Status::kSuccess, result->status);
// Check account.
absl::optional<account_manager::Account> account =
std::optional<account_manager::Account> account =
account_manager::FromMojoAccount(result->account);
EXPECT_TRUE(account.has_value());
EXPECT_EQ(kFakeAccount.key, account.value().key);
@ -569,7 +569,7 @@ TEST_F(AccountManagerMojoServiceTest,
auto result_2 = future_2.Take();
EXPECT_EQ(mojom::AccountUpsertionResult::Status::kSuccess, result_2->status);
// Check account.
absl::optional<account_manager::Account> account_2 =
std::optional<account_manager::Account> account_2 =
account_manager::FromMojoAccount(result_2->account);
EXPECT_TRUE(account_2.has_value());
EXPECT_EQ(kFakeAccount.key, account_2.value().key);

@ -4,6 +4,7 @@
#include "components/account_manager_core/chromeos/account_manager.h"
#include <optional>
#include <set>
#include <string>
#include <utility>
@ -29,7 +30,6 @@
#include "services/network/test/test_url_loader_factory.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
namespace account_manager {
@ -240,9 +240,9 @@ class AccountManagerObserver : public AccountManager::Observer {
void Reset() {
is_token_upserted_callback_called_ = false;
is_account_removed_callback_called_ = false;
last_upserted_account_key_ = absl::nullopt;
last_upserted_account_key_ = std::nullopt;
last_upserted_account_email_.clear();
last_removed_account_key_ = absl::nullopt;
last_removed_account_key_ = std::nullopt;
last_removed_account_email_.clear();
accounts_.clear();
}
@ -278,9 +278,9 @@ class AccountManagerObserver : public AccountManager::Observer {
private:
bool is_token_upserted_callback_called_ = false;
bool is_account_removed_callback_called_ = false;
absl::optional<::account_manager::AccountKey> last_upserted_account_key_;
std::optional<::account_manager::AccountKey> last_upserted_account_key_;
std::string last_upserted_account_email_;
absl::optional<::account_manager::AccountKey> last_removed_account_key_;
std::optional<::account_manager::AccountKey> last_removed_account_key_;
std::string last_removed_account_email_;
std::set<::account_manager::AccountKey> accounts_;
};

@ -4,22 +4,21 @@
#include "components/aggregation_service/parsing_utils.h"
#include <optional>
#include <string>
#include "components/aggregation_service/aggregation_coordinator_utils.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "url/gurl.h"
#include "url/origin.h"
namespace aggregation_service {
absl::optional<url::Origin> ParseAggregationCoordinator(
const std::string& str) {
std::optional<url::Origin> ParseAggregationCoordinator(const std::string& str) {
auto origin = url::Origin::Create(GURL(str));
if (IsAggregationCoordinatorOriginAllowed(origin)) {
return origin;
}
return absl::nullopt;
return std::nullopt;
}
} // namespace aggregation_service

@ -5,10 +5,10 @@
#ifndef COMPONENTS_AGGREGATION_SERVICE_PARSING_UTILS_H_
#define COMPONENTS_AGGREGATION_SERVICE_PARSING_UTILS_H_
#include <optional>
#include <string>
#include "base/component_export.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
namespace url {
class Origin;
@ -19,7 +19,7 @@ namespace aggregation_service {
// Parses aggregation coordinator identifier. Returns `kDefault` if `str` is
// nullptr or is not a pre-defined value.
COMPONENT_EXPORT(AGGREGATION_SERVICE)
absl::optional<url::Origin> ParseAggregationCoordinator(const std::string& str);
std::optional<url::Origin> ParseAggregationCoordinator(const std::string& str);
} // namespace aggregation_service

@ -4,11 +4,11 @@
#include "components/aggregation_service/parsing_utils.h"
#include <optional>
#include <string>
#include "components/aggregation_service/features.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "url/gurl.h"
#include "url/origin.h"
@ -18,11 +18,11 @@ namespace {
TEST(AggregationServiceParsingUtilsTest, ParseAggregationCoordinator) {
const struct {
std::string str;
absl::optional<url::Origin> expected;
std::optional<url::Origin> expected;
} kTestCases[] = {
{kAggregationServiceCoordinatorAwsCloud.Get(),
url::Origin::Create(GURL(kAggregationServiceCoordinatorAwsCloud.Get()))},
{"https://a.test", absl::nullopt},
{"https://a.test", std::nullopt},
};
for (const auto& test_case : kTestCases) {

@ -4,13 +4,13 @@
#include "components/allocation_recorder/crash_handler/allocation_recorder_holder.h"
#include <optional>
#include <sstream>
#include <string>
#include "base/check.h"
#include "build/build_config.h"
#include "components/allocation_recorder/internal/internal.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "third_party/crashpad/crashpad/client/annotation.h"
#include "third_party/crashpad/crashpad/snapshot/cpu_context.h"
#include "third_party/crashpad/crashpad/snapshot/exception_snapshot.h"
@ -67,7 +67,7 @@ constexpr const char* GetBitnessDescriptor(BitnessType bitness) {
// in the process_snapshot. Returns an optional containing the exact address.
// In case of an error, an empty optional is returned and details on the error
// will be written to the error_stream.
absl::optional<crashpad::VMAddress> GetRecorderVMAddress(
std::optional<crashpad::VMAddress> GetRecorderVMAddress(
const crashpad::ProcessSnapshot& process_snapshot,
std::ostream& error_stream) {
for (const auto* module : process_snapshot.Modules()) {

@ -464,7 +464,7 @@ void AutofillProviderAndroid::OnFocusNoLongerOnForm(
return;
}
bridge_->OnFocusChanged(absl::nullopt);
bridge_->OnFocusChanged(std::nullopt);
}
void AutofillProviderAndroid::OnFocusOnFormField(

@ -7,12 +7,12 @@
#include <jni.h>
#include <optional>
#include <string>
#include "base/containers/span.h"
#include "components/autofill/core/common/form_field_data.h"
#include "components/autofill/core/common/mojom/autofill_types.mojom.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "third_party/jni_zero/scoped_java_ref.h"
namespace gfx {
@ -76,7 +76,7 @@ class AutofillProviderAndroidBridge {
virtual void HideDatalistPopup() = 0;
// Informs the Java side that a focus change has happened to `field`.
virtual void OnFocusChanged(const absl::optional<FieldInfo>& field) = 0;
virtual void OnFocusChanged(const std::optional<FieldInfo>& field) = 0;
// Informs the Java side that the `field` has changed.
virtual void OnFormFieldDidChange(const FieldInfo& field) = 0;

@ -98,7 +98,7 @@ void AutofillProviderAndroidBridgeImpl::OnServerPredictionsAvailable() {
}
void AutofillProviderAndroidBridgeImpl::OnFocusChanged(
const absl::optional<FieldInfo>& field) {
const std::optional<FieldInfo>& field) {
JNIEnv* env = AttachCurrentThread();
ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
if (obj.is_null()) {

@ -5,15 +5,15 @@
#ifndef COMPONENTS_ANDROID_AUTOFILL_BROWSER_AUTOFILL_PROVIDER_ANDROID_BRIDGE_IMPL_H_
#define COMPONENTS_ANDROID_AUTOFILL_BROWSER_AUTOFILL_PROVIDER_ANDROID_BRIDGE_IMPL_H_
#include "components/android_autofill/browser/autofill_provider_android_bridge.h"
#include <jni.h>
#include <optional>
#include "base/android/jni_weak_ref.h"
#include "base/containers/span.h"
#include "base/memory/raw_ref.h"
#include "components/android_autofill/browser/autofill_provider_android_bridge.h"
#include "components/autofill/core/common/mojom/autofill_types.mojom.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
namespace autofill {
@ -34,7 +34,7 @@ class AutofillProviderAndroidBridgeImpl : public AutofillProviderAndroidBridge {
void ShowDatalistPopup(base::span<const SelectOption> options,
bool is_rtl) override;
void HideDatalistPopup() override;
void OnFocusChanged(const absl::optional<FieldInfo>& field) override;
void OnFocusChanged(const std::optional<FieldInfo>& field) override;
void OnFormFieldDidChange(const FieldInfo& field) override;
void OnFormFieldVisibilitiesDidChange(base::span<const int> indices) override;
void OnTextFieldDidScroll(const FieldInfo& field) override;

@ -191,7 +191,7 @@ class MockAutofillProviderAndroidBridge : public AutofillProviderAndroidBridge {
MOCK_METHOD(void, HideDatalistPopup, (), (override));
MOCK_METHOD(void,
OnFocusChanged,
(const absl::optional<FieldInfo>&),
(const std::optional<FieldInfo>&),
(override));
MOCK_METHOD(void, OnFormFieldDidChange, (const FieldInfo&), (override));
MOCK_METHOD(void,
@ -344,7 +344,7 @@ TEST_F(AutofillProviderAndroidTest, OnFocusChangeInsideCurrentAutofillForm) {
EXPECT_CALL(provider_bridge(),
OnFocusChanged(Optional(EqualsFieldInfo(/*index=*/1))));
EXPECT_CALL(check, Call(1));
EXPECT_CALL(provider_bridge(), OnFocusChanged(Eq(absl::nullopt)));
EXPECT_CALL(provider_bridge(), OnFocusChanged(Eq(std::nullopt)));
EXPECT_CALL(check, Call(2));
}

@ -4,6 +4,7 @@
#include "components/android_autofill/browser/form_field_data_android_bridge_impl.h"
#include <optional>
#include <string>
#include <string_view>
@ -16,7 +17,6 @@
#include "components/autofill/core/browser/autofill_type.h"
#include "components/autofill/core/common/autofill_util.h"
#include "components/autofill/core/common/form_field_data.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
namespace autofill {

@ -18,10 +18,10 @@ uint16_t ParseMessageLength(base::span<const uint8_t> message, size_t offset) {
} // namespace
absl::optional<ApduCommand> ApduCommand::CreateFromMessage(
std::optional<ApduCommand> ApduCommand::CreateFromMessage(
base::span<const uint8_t> message) {
if (message.size() < kApduMinHeader || message.size() > kApduMaxLength)
return absl::nullopt;
return std::nullopt;
uint8_t cla = message[0];
uint8_t ins = message[1];
@ -38,12 +38,12 @@ absl::optional<ApduCommand> ApduCommand::CreateFromMessage(
// Invalid encoding sizes.
case kApduMinHeader + 1:
case kApduMinHeader + 2:
return absl::nullopt;
return std::nullopt;
// No data present; response expected.
case kApduMinHeader + 3:
// Fifth byte must be 0.
if (message[4] != 0)
return absl::nullopt;
return std::nullopt;
response_length = ParseMessageLength(message, kApduCommandLengthOffset);
// Special case where response length of 0x0000 corresponds to 65536
// as defined in ISO7816-4.
@ -53,7 +53,7 @@ absl::optional<ApduCommand> ApduCommand::CreateFromMessage(
default:
// Fifth byte must be 0.
if (message[4] != 0)
return absl::nullopt;
return std::nullopt;
auto data_length = ParseMessageLength(message, kApduCommandLengthOffset);
if (message.size() == data_length + kApduCommandDataOffset) {
@ -71,7 +71,7 @@ absl::optional<ApduCommand> ApduCommand::CreateFromMessage(
if (response_length == 0)
response_length = kApduMaxResponseLength;
} else {
return absl::nullopt;
return std::nullopt;
}
break;
}

@ -6,13 +6,13 @@
#define COMPONENTS_APDU_APDU_COMMAND_H_
#include <cinttypes>
#include <optional>
#include <utility>
#include <vector>
#include "base/component_export.h"
#include "base/containers/span.h"
#include "base/gtest_prod_util.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
namespace apdu {
@ -27,7 +27,7 @@ namespace apdu {
class COMPONENT_EXPORT(APDU) ApduCommand {
public:
// Constructs an APDU command from the serialized message data.
static absl::optional<ApduCommand> CreateFromMessage(
static std::optional<ApduCommand> CreateFromMessage(
base::span<const uint8_t> message);
ApduCommand();

@ -11,11 +11,11 @@
namespace apdu {
// static
absl::optional<ApduResponse> ApduResponse::CreateFromMessage(
std::optional<ApduResponse> ApduResponse::CreateFromMessage(
base::span<const uint8_t> data) {
// Invalid message size, data is appended by status byte.
if (data.size() < 2)
return absl::nullopt;
return std::nullopt;
uint16_t status_bytes = data[data.size() - 2] << 8;
status_bytes |= data[data.size() - 1];

@ -7,12 +7,12 @@
#include <stdint.h>
#include <optional>
#include <vector>
#include "base/component_export.h"
#include "base/containers/span.h"
#include "base/gtest_prod_util.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
namespace apdu {
@ -32,7 +32,7 @@ class COMPONENT_EXPORT(APDU) ApduResponse {
};
// Create a APDU response from the serialized message.
static absl::optional<ApduResponse> CreateFromMessage(
static std::optional<ApduResponse> CreateFromMessage(
base::span<const uint8_t> data);
ApduResponse(std::vector<uint8_t> data, Status response_status);

@ -169,7 +169,7 @@ void ArcIntentHelperBridge::OnIntentFiltersUpdated(
intent_filters_[filter.package_name()].push_back(std::move(filter));
for (auto& observer : observer_list_)
observer.OnIntentFiltersUpdated(absl::nullopt);
observer.OnIntentFiltersUpdated(std::nullopt);
}
void ArcIntentHelperBridge::OnOpenDownloads() {

@ -190,7 +190,7 @@ TEST_F(ArcIntentHelperTest, TestObserver) {
{
// Observer should be called when an intent filter is updated.
EXPECT_CALL(observer, OnIntentFiltersUpdated(testing::Eq(absl::nullopt)));
EXPECT_CALL(observer, OnIntentFiltersUpdated(testing::Eq(std::nullopt)));
instance_->OnIntentFiltersUpdated(/*filters=*/std::vector<IntentFilter>());
testing::Mock::VerifyAndClearExpectations(&observer);
}

@ -19,7 +19,7 @@ class ArcIntentHelperObserver {
virtual ~ArcIntentHelperObserver() = default;
// Called when intent filters are added, removed or updated.
// A absl::nullopt |package_name| indicates that intent filters were updated
// A std::nullopt |package_name| indicates that intent filters were updated
// for all packages. Otherwise, |package_name| contains the name of the
// package whose filters were changed.
virtual void OnIntentFiltersUpdated(

@ -6,6 +6,7 @@
#include <stdint.h>
#include <optional>
#include <utility>
#include "base/types/expected.h"
@ -14,7 +15,6 @@
#include "components/attribution_reporting/filters.h"
#include "components/attribution_reporting/parsing_utils.h"
#include "components/attribution_reporting/trigger_registration_error.mojom.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "third_party/abseil-cpp/absl/types/variant.h"
namespace attribution_reporting {
@ -48,7 +48,7 @@ AggregatableDedupKey::FromJSON(base::Value& value) {
AggregatableDedupKey::AggregatableDedupKey() = default;
AggregatableDedupKey::AggregatableDedupKey(absl::optional<uint64_t> dedup_key,
AggregatableDedupKey::AggregatableDedupKey(std::optional<uint64_t> dedup_key,
FilterPair filters)
: dedup_key(dedup_key), filters(std::move(filters)) {}

@ -7,12 +7,13 @@
#include <stdint.h>
#include <optional>
#include "base/component_export.h"
#include "base/types/expected.h"
#include "base/values.h"
#include "components/attribution_reporting/filters.h"
#include "components/attribution_reporting/trigger_registration_error.mojom-forward.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
namespace attribution_reporting {
@ -22,7 +23,7 @@ struct COMPONENT_EXPORT(ATTRIBUTION_REPORTING) AggregatableDedupKey {
// Key specified for deduplication against existing trigger with the same
// source. If absent, no deduplication is performed.
absl::optional<uint64_t> dedup_key;
std::optional<uint64_t> dedup_key;
// The filters used to determine whether this `AggregatableDedupKey`'s dedup
// key is used.
@ -30,7 +31,7 @@ struct COMPONENT_EXPORT(ATTRIBUTION_REPORTING) AggregatableDedupKey {
AggregatableDedupKey();
AggregatableDedupKey(absl::optional<uint64_t> dedup_key, FilterPair);
AggregatableDedupKey(std::optional<uint64_t> dedup_key, FilterPair);
base::Value::Dict ToJson() const;

@ -35,7 +35,7 @@ TEST(AggregatableDedupKeyTest, FromJSON) {
{
"empty",
R"json({})json",
ValueIs(AllOf(Field(&AggregatableDedupKey::dedup_key, absl::nullopt),
ValueIs(AllOf(Field(&AggregatableDedupKey::dedup_key, std::nullopt),
Field(&AggregatableDedupKey::filters, FilterPair()))),
},
{

@ -6,6 +6,7 @@
#include <stddef.h>
#include <optional>
#include <string>
#include <utility>
@ -17,7 +18,6 @@
#include "components/attribution_reporting/features.h"
#include "components/attribution_reporting/source_registration_time_config.mojom.h"
#include "components/attribution_reporting/trigger_registration_error.mojom.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
namespace attribution_reporting {
@ -84,7 +84,7 @@ bool IsTriggerContextIdAllowed(
}
bool IsValid(SourceRegistrationTimeConfig source_registration_time_config,
const absl::optional<std::string>& trigger_context_id) {
const std::optional<std::string>& trigger_context_id) {
if (!trigger_context_id.has_value()) {
return true;
}
@ -93,12 +93,12 @@ bool IsValid(SourceRegistrationTimeConfig source_registration_time_config,
IsTriggerContextIdAllowed(source_registration_time_config);
}
base::expected<absl::optional<std::string>, TriggerRegistrationError>
base::expected<std::optional<std::string>, TriggerRegistrationError>
ParseTriggerContextId(base::Value* value) {
if (!base::FeatureList::IsEnabled(
features::kAttributionReportingTriggerContextId) ||
!value) {
return absl::nullopt;
return std::nullopt;
}
std::string* s = value->GetIfString();
@ -118,7 +118,7 @@ AggregatableTriggerConfig::Parse(base::Value::Dict& dict) {
ParseAggregatableSourceRegistrationTime(
dict.Find(kAggregatableSourceRegistrationTime)));
ASSIGN_OR_RETURN(absl::optional<std::string> trigger_context_id,
ASSIGN_OR_RETURN(std::optional<std::string> trigger_context_id,
ParseTriggerContextId(dict.Find(kTriggerContextId)));
if (trigger_context_id.has_value() &&
@ -133,11 +133,11 @@ AggregatableTriggerConfig::Parse(base::Value::Dict& dict) {
}
// static
absl::optional<AggregatableTriggerConfig> AggregatableTriggerConfig::Create(
std::optional<AggregatableTriggerConfig> AggregatableTriggerConfig::Create(
SourceRegistrationTimeConfig source_registration_time_config,
absl::optional<std::string> trigger_context_id) {
std::optional<std::string> trigger_context_id) {
if (!IsValid(source_registration_time_config, trigger_context_id)) {
return absl::nullopt;
return std::nullopt;
}
return AggregatableTriggerConfig(source_registration_time_config,
std::move(trigger_context_id));
@ -147,7 +147,7 @@ AggregatableTriggerConfig::AggregatableTriggerConfig() = default;
AggregatableTriggerConfig::AggregatableTriggerConfig(
SourceRegistrationTimeConfig source_registration_time_config,
absl::optional<std::string> trigger_context_id)
std::optional<std::string> trigger_context_id)
: source_registration_time_config_(source_registration_time_config),
trigger_context_id_(std::move(trigger_context_id)) {
CHECK(IsValid(source_registration_time_config_, trigger_context_id_));

@ -5,6 +5,7 @@
#ifndef COMPONENTS_ATTRIBUTION_REPORTING_AGGREGATABLE_TRIGGER_CONFIG_H_
#define COMPONENTS_ATTRIBUTION_REPORTING_AGGREGATABLE_TRIGGER_CONFIG_H_
#include <optional>
#include <string>
#include "base/component_export.h"
@ -12,7 +13,6 @@
#include "base/values.h"
#include "components/attribution_reporting/source_registration_time_config.mojom.h"
#include "components/attribution_reporting/trigger_registration_error.mojom-forward.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
namespace attribution_reporting {
@ -22,9 +22,9 @@ class COMPONENT_EXPORT(ATTRIBUTION_REPORTING) AggregatableTriggerConfig {
mojom::TriggerRegistrationError>
Parse(base::Value::Dict&);
static absl::optional<AggregatableTriggerConfig> Create(
static std::optional<AggregatableTriggerConfig> Create(
mojom::SourceRegistrationTimeConfig,
absl::optional<std::string> trigger_context_id);
std::optional<std::string> trigger_context_id);
AggregatableTriggerConfig();
@ -45,18 +45,18 @@ class COMPONENT_EXPORT(ATTRIBUTION_REPORTING) AggregatableTriggerConfig {
return source_registration_time_config_;
}
const absl::optional<std::string>& trigger_context_id() const {
const std::optional<std::string>& trigger_context_id() const {
return trigger_context_id_;
}
private:
AggregatableTriggerConfig(mojom::SourceRegistrationTimeConfig,
absl::optional<std::string> trigger_context_id);
std::optional<std::string> trigger_context_id);
mojom::SourceRegistrationTimeConfig source_registration_time_config_ =
mojom::SourceRegistrationTimeConfig::kExclude;
absl::optional<std::string> trigger_context_id_;
std::optional<std::string> trigger_context_id_;
};
} // namespace attribution_reporting

@ -4,6 +4,7 @@
#include "components/attribution_reporting/aggregatable_trigger_config.h"
#include <optional>
#include <string>
#include "base/test/gmock_expected_support.h"
@ -16,7 +17,6 @@
#include "components/attribution_reporting/trigger_registration_error.mojom.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
namespace attribution_reporting {
namespace {
@ -124,7 +124,7 @@ TEST(AggregatableTriggerConfigTest, ParseTriggerContextId) {
kTriggerContextIdInvalidSourceRegistrationTimeConfig),
ValueIs(*AggregatableTriggerConfig::Create(
SourceRegistrationTimeConfig::kInclude,
/*trigger_context_id=*/absl::nullopt)),
/*trigger_context_id=*/std::nullopt)),
},
};
@ -160,8 +160,8 @@ TEST(AggregatableTriggerConfigTest, Create) {
const struct {
const char* desc;
SourceRegistrationTimeConfig source_registration_time_config;
absl::optional<std::string> trigger_context_id;
absl::optional<AggregatableTriggerConfig> expected;
std::optional<std::string> trigger_context_id;
std::optional<AggregatableTriggerConfig> expected;
} kTestCases[] = {
{
"valid_exclude_source_registration_time_with_trigger_context_id",
@ -173,33 +173,33 @@ TEST(AggregatableTriggerConfigTest, Create) {
{
"valid_exclude_source_registration_time_without_trigger_context_id",
SourceRegistrationTimeConfig::kExclude,
absl::nullopt,
std::nullopt,
AggregatableTriggerConfig(),
},
{
"valid_include_source_registration_time_without_trigger_context_id",
SourceRegistrationTimeConfig::kInclude,
absl::nullopt,
std::nullopt,
*AggregatableTriggerConfig::Create(
SourceRegistrationTimeConfig::kInclude, absl::nullopt),
SourceRegistrationTimeConfig::kInclude, std::nullopt),
},
{
"trigger_context_id_empty",
SourceRegistrationTimeConfig::kExclude,
"",
absl::nullopt,
std::nullopt,
},
{
"trigger_context_id_too_long",
SourceRegistrationTimeConfig::kExclude,
std::string(65, 'a'),
absl::nullopt,
std::nullopt,
},
{
"trigger_context_id_disallowed",
SourceRegistrationTimeConfig::kInclude,
"123",
absl::nullopt,
std::nullopt,
},
};
@ -244,7 +244,7 @@ TEST(AggregatableTriggerConfigTest, Serialize) {
{
*AggregatableTriggerConfig::Create(
SourceRegistrationTimeConfig::kInclude,
/*trigger_context_id=*/absl::nullopt),
/*trigger_context_id=*/std::nullopt),
R"json({
"aggregatable_source_registration_time":"include"
})json",

@ -4,6 +4,7 @@
#include "components/attribution_reporting/aggregatable_trigger_data.h"
#include <optional>
#include <string>
#include <utility>
@ -16,7 +17,6 @@
#include "components/attribution_reporting/parsing_utils.h"
#include "components/attribution_reporting/trigger_registration_error.mojom.h"
#include "third_party/abseil-cpp/absl/numeric/int128.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
namespace attribution_reporting {
@ -102,12 +102,12 @@ void SerializeSourceKeysIfNotEmpty(base::Value::Dict& dict,
} // namespace
// static
absl::optional<AggregatableTriggerData> AggregatableTriggerData::Create(
std::optional<AggregatableTriggerData> AggregatableTriggerData::Create(
absl::uint128 key_piece,
Keys source_keys,
FilterPair filters) {
if (!AreSourceKeysValid(source_keys))
return absl::nullopt;
return std::nullopt;
return AggregatableTriggerData(key_piece, std::move(source_keys),
std::move(filters));

@ -5,6 +5,7 @@
#ifndef COMPONENTS_ATTRIBUTION_REPORTING_AGGREGATABLE_TRIGGER_DATA_H_
#define COMPONENTS_ATTRIBUTION_REPORTING_AGGREGATABLE_TRIGGER_DATA_H_
#include <optional>
#include <string>
#include <vector>
@ -14,7 +15,6 @@
#include "components/attribution_reporting/filters.h"
#include "components/attribution_reporting/trigger_registration_error.mojom-forward.h"
#include "third_party/abseil-cpp/absl/numeric/int128.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
namespace attribution_reporting {
@ -22,9 +22,9 @@ class COMPONENT_EXPORT(ATTRIBUTION_REPORTING) AggregatableTriggerData {
public:
using Keys = std::vector<std::string>;
static absl::optional<AggregatableTriggerData> Create(absl::uint128 key_piece,
Keys source_keys,
FilterPair);
static std::optional<AggregatableTriggerData> Create(absl::uint128 key_piece,
Keys source_keys,
FilterPair);
static base::expected<AggregatableTriggerData,
mojom::TriggerRegistrationError>

@ -4,6 +4,7 @@
#include "components/attribution_reporting/aggregatable_values.h"
#include <optional>
#include <utility>
#include "base/check.h"
@ -15,7 +16,6 @@
#include "components/attribution_reporting/constants.h"
#include "components/attribution_reporting/parsing_utils.h"
#include "components/attribution_reporting/trigger_registration_error.mojom.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
namespace attribution_reporting {
@ -37,9 +37,9 @@ bool IsValid(const AggregatableValues::Values& values) {
} // namespace
// static
absl::optional<AggregatableValues> AggregatableValues::Create(Values values) {
std::optional<AggregatableValues> AggregatableValues::Create(Values values) {
if (!IsValid(values))
return absl::nullopt;
return std::nullopt;
return AggregatableValues(std::move(values));
}
@ -64,7 +64,7 @@ AggregatableValues::FromJSON(const base::Value* input_value) {
TriggerRegistrationError::kAggregatableValuesKeyTooLong);
}
absl::optional<int> int_value = key_value.GetIfInt();
std::optional<int> int_value = key_value.GetIfInt();
if (!int_value.has_value()) {
return base::unexpected(
TriggerRegistrationError::kAggregatableValuesValueWrongType);

@ -7,6 +7,7 @@
#include <stdint.h>
#include <optional>
#include <string>
#include "base/component_export.h"
@ -14,7 +15,6 @@
#include "base/types/expected.h"
#include "base/values.h"
#include "components/attribution_reporting/trigger_registration_error.mojom-forward.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
namespace attribution_reporting {
@ -22,7 +22,7 @@ class COMPONENT_EXPORT(ATTRIBUTION_REPORTING) AggregatableValues {
public:
using Values = base::flat_map<std::string, uint32_t>;
static absl::optional<AggregatableValues> Create(Values);
static std::optional<AggregatableValues> Create(Values);
static base::expected<AggregatableValues, mojom::TriggerRegistrationError>
FromJSON(const base::Value*);

@ -6,6 +6,7 @@
#include <stddef.h>
#include <optional>
#include <string>
#include <utility>
@ -17,7 +18,6 @@
#include "components/attribution_reporting/trigger_registration_error.mojom.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
namespace attribution_reporting {
namespace {

@ -4,6 +4,7 @@
#include "components/attribution_reporting/aggregation_keys.h"
#include <optional>
#include <string>
#include <utility>
@ -18,7 +19,6 @@
#include "components/attribution_reporting/parsing_utils.h"
#include "components/attribution_reporting/source_registration_error.mojom.h"
#include "third_party/abseil-cpp/absl/numeric/int128.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
namespace attribution_reporting {
@ -46,9 +46,9 @@ void RecordAggregatableKeysPerSource(base::HistogramBase::Sample count) {
} // namespace
// static
absl::optional<AggregationKeys> AggregationKeys::FromKeys(Keys keys) {
std::optional<AggregationKeys> AggregationKeys::FromKeys(Keys keys) {
if (!IsValid(keys))
return absl::nullopt;
return std::nullopt;
return AggregationKeys(std::move(keys));
}

@ -5,6 +5,7 @@
#ifndef COMPONENTS_ATTRIBUTION_REPORTING_AGGREGATION_KEYS_H_
#define COMPONENTS_ATTRIBUTION_REPORTING_AGGREGATION_KEYS_H_
#include <optional>
#include <string>
#include "base/component_export.h"
@ -13,7 +14,6 @@
#include "base/values.h"
#include "components/attribution_reporting/source_registration_error.mojom-forward.h"
#include "third_party/abseil-cpp/absl/numeric/int128.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
namespace attribution_reporting {
@ -21,8 +21,8 @@ class COMPONENT_EXPORT(ATTRIBUTION_REPORTING) AggregationKeys {
public:
using Keys = base::flat_map<std::string, absl::uint128>;
// Returns `absl::nullopt` if `keys` is invalid.
static absl::optional<AggregationKeys> FromKeys(Keys keys);
// Returns `std::nullopt` if `keys` is invalid.
static std::optional<AggregationKeys> FromKeys(Keys keys);
static base::expected<AggregationKeys, mojom::SourceRegistrationError>
FromJSON(const base::Value*);

@ -6,6 +6,7 @@
#include <stddef.h>
#include <optional>
#include <string>
#include <utility>
@ -20,7 +21,6 @@
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/abseil-cpp/absl/numeric/int128.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
namespace attribution_reporting {
namespace {

@ -4,6 +4,7 @@
#include "components/attribution_reporting/destination_set.h"
#include <optional>
#include <string>
#include <utility>
#include <vector>
@ -19,7 +20,6 @@
#include "components/attribution_reporting/suitable_origin.h"
#include "mojo/public/cpp/bindings/default_construct_tag.h"
#include "net/base/schemeful_site.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
namespace attribution_reporting {
@ -35,10 +35,10 @@ bool DestinationsValid(const DestinationSet::Destinations& destinations) {
} // namespace
// static
absl::optional<DestinationSet> DestinationSet::Create(
std::optional<DestinationSet> DestinationSet::Create(
Destinations destinations) {
if (!DestinationsValid(destinations)) {
return absl::nullopt;
return std::nullopt;
}
return DestinationSet(std::move(destinations));
}

@ -5,13 +5,14 @@
#ifndef COMPONENTS_ATTRIBUTION_REPORTING_DESTINATION_SET_H_
#define COMPONENTS_ATTRIBUTION_REPORTING_DESTINATION_SET_H_
#include <optional>
#include "base/check.h"
#include "base/component_export.h"
#include "base/containers/flat_set.h"
#include "base/types/expected.h"
#include "components/attribution_reporting/source_registration_error.mojom-forward.h"
#include "mojo/public/cpp/bindings/default_construct_tag.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
namespace base {
class Value;
@ -27,7 +28,7 @@ class COMPONENT_EXPORT(ATTRIBUTION_REPORTING) DestinationSet {
public:
using Destinations = base::flat_set<net::SchemefulSite>;
static absl::optional<DestinationSet> Create(Destinations);
static std::optional<DestinationSet> Create(Destinations);
static base::expected<DestinationSet, mojom::SourceRegistrationError>
FromJSON(const base::Value*);

@ -4,12 +4,13 @@
#include "components/attribution_reporting/event_level_epsilon.h"
#include <optional>
#include "base/check.h"
#include "base/check_op.h"
#include "base/types/expected.h"
#include "base/values.h"
#include "components/attribution_reporting/source_registration_error.mojom.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
namespace attribution_reporting {
@ -35,7 +36,7 @@ EventLevelEpsilon::Parse(const base::Value::Dict& dict) {
return EventLevelEpsilon();
}
absl::optional<double> d = value->GetIfDouble();
std::optional<double> d = value->GetIfDouble();
if (!d.has_value()) {
return base::unexpected(
SourceRegistrationError::kEventLevelEpsilonWrongType);

@ -9,6 +9,7 @@
#include <algorithm>
#include <functional>
#include <iterator>
#include <optional>
#include <utility>
#include <vector>
@ -24,7 +25,6 @@
#include "components/attribution_reporting/parsing_utils.h"
#include "components/attribution_reporting/source_registration_error.mojom-shared.h"
#include "components/attribution_reporting/source_type.mojom-shared.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
namespace attribution_reporting {
@ -65,26 +65,26 @@ base::Time ReportTimeFromDeadline(base::Time source_time,
} // namespace
// static
absl::optional<EventReportWindows> EventReportWindows::FromDefaults(
std::optional<EventReportWindows> EventReportWindows::FromDefaults(
base::TimeDelta report_window,
SourceType source_type) {
if (!IsReportWindowValid(report_window)) {
return absl::nullopt;
return std::nullopt;
}
return EventReportWindows(report_window, source_type);
}
// static
absl::optional<EventReportWindows> EventReportWindows::Create(
std::optional<EventReportWindows> EventReportWindows::Create(
base::TimeDelta start_time,
std::vector<base::TimeDelta> end_times) {
if (!IsStrictlyIncreasing(end_times)) {
return absl::nullopt;
return std::nullopt;
}
base::flat_set<base::TimeDelta> end_times_set(base::sorted_unique,
std::move(end_times));
if (!IsValid(start_time, end_times_set)) {
return absl::nullopt;
return std::nullopt;
}
return EventReportWindows(start_time, std::move(end_times_set));
}
@ -232,7 +232,7 @@ EventReportWindows::ParseWindowsJSON(const base::Value& v,
base::TimeDelta start_time = base::Seconds(0);
if (const base::Value* start_time_value = dict->Find(kStartTime)) {
absl::optional<int> int_value = start_time_value->GetIfInt();
std::optional<int> int_value = start_time_value->GetIfInt();
if (!int_value.has_value()) {
return base::unexpected(
SourceRegistrationError::kEventReportWindowsStartTimeWrongType);
@ -270,7 +270,7 @@ EventReportWindows::ParseWindowsJSON(const base::Value& v,
base::TimeDelta start_duration = start_time;
for (const auto& item : *end_times_list) {
const absl::optional<int> item_int = item.GetIfInt();
const std::optional<int> item_int = item.GetIfInt();
if (!item_int.has_value()) {
return base::unexpected(
SourceRegistrationError::kEventReportWindowsEndTimeValueWrongType);

@ -5,6 +5,7 @@
#ifndef COMPONENTS_ATTRIBUTION_REPORTING_EVENT_REPORT_WINDOWS_H_
#define COMPONENTS_ATTRIBUTION_REPORTING_EVENT_REPORT_WINDOWS_H_
#include <optional>
#include <vector>
#include "base/component_export.h"
@ -14,7 +15,6 @@
#include "base/values.h"
#include "components/attribution_reporting/source_registration_error.mojom-forward.h"
#include "components/attribution_reporting/source_type.mojom-forward.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
namespace attribution_reporting {
@ -33,13 +33,13 @@ class COMPONENT_EXPORT(ATTRIBUTION_REPORTING) EventReportWindows {
kMaxValue = kNotStarted,
};
static absl::optional<EventReportWindows> Create(
static std::optional<EventReportWindows> Create(
base::TimeDelta start_time,
std::vector<base::TimeDelta> end_times);
// Uses default windows based on the source type, but truncated at
// `report_window`.
static absl::optional<EventReportWindows> FromDefaults(
static std::optional<EventReportWindows> FromDefaults(
base::TimeDelta report_window,
mojom::SourceType);

@ -4,6 +4,7 @@
#include "components/attribution_reporting/event_report_windows.h"
#include <optional>
#include <vector>
#include "base/test/gmock_expected_support.h"
@ -15,7 +16,6 @@
#include "components/attribution_reporting/test_utils.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
namespace attribution_reporting {
@ -38,19 +38,19 @@ TEST(EventReportWindowsTest, FromDefaults) {
const char* desc;
base::TimeDelta report_window;
SourceType source_type;
::testing::Matcher<absl::optional<EventReportWindows>> matches;
::testing::Matcher<std::optional<EventReportWindows>> matches;
} kTestCases[] = {
{
"negative-navigation",
base::Seconds(-1),
SourceType::kNavigation,
Eq(absl::nullopt),
Eq(std::nullopt),
},
{
"negative-event",
base::Seconds(-1),
SourceType::kEvent,
Eq(absl::nullopt),
Eq(std::nullopt),
},
{
"=-last-navigation",
@ -114,56 +114,56 @@ TEST(EventReportWindowsTest, CreateWindows) {
const char* name;
base::TimeDelta start_time;
std::vector<base::TimeDelta> end_times;
::testing::Matcher<absl::optional<EventReportWindows>> matches;
::testing::Matcher<std::optional<EventReportWindows>> matches;
} kTestCases[] = {
{
.name = "end_time-eq-start_time",
.start_time = base::Hours(1),
.end_times = {base::Hours(1)},
.matches = Eq(absl::nullopt),
.matches = Eq(std::nullopt),
},
{
.name = "end_time-lt-start_time",
.start_time = base::Hours(2),
.end_times = {base::Hours(2) - base::Microseconds(1)},
.matches = Eq(absl::nullopt),
.matches = Eq(std::nullopt),
},
{
.name = "end_time-eq-prev-end_time",
.start_time = base::Seconds(0),
.end_times = {base::Hours(1), base::Hours(1)},
.matches = Eq(absl::nullopt),
.matches = Eq(std::nullopt),
},
{
.name = "end_time-lt-prev-end_time",
.start_time = base::Seconds(0),
.end_times = {base::Hours(2), base::Hours(2) - base::Microseconds(1)},
.matches = Eq(absl::nullopt),
.matches = Eq(std::nullopt),
},
{
.name = "negative-start_time",
.start_time = base::Seconds(-1),
.end_times = {base::Hours(1)},
.matches = Eq(absl::nullopt),
.matches = Eq(std::nullopt),
},
{
.name = "empty-end_times",
.start_time = base::Seconds(0),
.end_times = {},
.matches = Eq(absl::nullopt),
.matches = Eq(std::nullopt),
},
{
.name = "too-many-end_times",
.start_time = base::Seconds(0),
.end_times = {base::Hours(1), base::Hours(2), base::Hours(3),
base::Hours(4), base::Hours(5), base::Hours(6)},
.matches = Eq(absl::nullopt),
.matches = Eq(std::nullopt),
},
{
.name = "end-time-less-than-min-report-window",
.start_time = base::Seconds(0),
.end_times = {base::Hours(1) - base::Microseconds(1)},
.matches = Eq(absl::nullopt),
.matches = Eq(std::nullopt),
},
{
.name = "valid",

@ -62,7 +62,7 @@ EventTriggerData::EventTriggerData() = default;
EventTriggerData::EventTriggerData(uint64_t data,
int64_t priority,
absl::optional<uint64_t> dedup_key,
std::optional<uint64_t> dedup_key,
FilterPair filters)
: data(data),
priority(priority),

@ -7,12 +7,13 @@
#include <stdint.h>
#include <optional>
#include "base/component_export.h"
#include "base/types/expected.h"
#include "base/values.h"
#include "components/attribution_reporting/filters.h"
#include "components/attribution_reporting/trigger_registration_error.mojom-forward.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
namespace attribution_reporting {
@ -33,7 +34,7 @@ struct COMPONENT_EXPORT(ATTRIBUTION_REPORTING) EventTriggerData {
// Key specified in conversion redirect for deduplication against existing
// conversions with the same source. If absent, no deduplication is
// performed.
absl::optional<uint64_t> dedup_key;
std::optional<uint64_t> dedup_key;
// The filters used to determine whether this `EventTriggerData'`s fields
// are used.
@ -43,7 +44,7 @@ struct COMPONENT_EXPORT(ATTRIBUTION_REPORTING) EventTriggerData {
EventTriggerData(uint64_t data,
int64_t priority,
absl::optional<uint64_t> dedup_key,
std::optional<uint64_t> dedup_key,
FilterPair);
base::Value::Dict ToJson() const;

@ -37,7 +37,7 @@ TEST(EventTriggerDataTest, FromJSON) {
R"json({})json",
ValueIs(AllOf(Field(&EventTriggerData::data, 0),
Field(&EventTriggerData::priority, 0),
Field(&EventTriggerData::dedup_key, absl::nullopt),
Field(&EventTriggerData::dedup_key, std::nullopt),
Field(&EventTriggerData::filters, FilterPair()))),
},
{

@ -4,6 +4,7 @@
#include "components/attribution_reporting/filters.h"
#include <optional>
#include <string>
#include <utility>
#include <vector>
@ -24,7 +25,6 @@
#include "components/attribution_reporting/source_type.h"
#include "components/attribution_reporting/source_type.mojom-forward.h"
#include "components/attribution_reporting/trigger_registration_error.mojom.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
namespace attribution_reporting {
@ -169,9 +169,9 @@ base::Value::Dict FilterValuesToJson(const FilterValues& filter_values) {
} // namespace
// static
absl::optional<FilterData> FilterData::Create(FilterValues filter_values) {
std::optional<FilterData> FilterData::Create(FilterValues filter_values) {
if (!IsValidForSource(filter_values)) {
return absl::nullopt;
return std::nullopt;
}
return FilterData(std::move(filter_values));
@ -338,17 +338,17 @@ bool FilterData::Matches(mojom::SourceType source_type,
FilterConfig::FilterConfig() = default;
absl::optional<FilterConfig> FilterConfig::Create(
std::optional<FilterConfig> FilterConfig::Create(
FilterValues filter_values,
absl::optional<base::TimeDelta> lookback_window) {
std::optional<base::TimeDelta> lookback_window) {
if (lookback_window && !lookback_window->is_positive()) {
return absl::nullopt;
return std::nullopt;
}
return FilterConfig(std::move(filter_values), lookback_window);
}
FilterConfig::FilterConfig(FilterValues filter_values,
absl::optional<base::TimeDelta> lookback_window)
std::optional<base::TimeDelta> lookback_window)
: lookback_window_(lookback_window),
filter_values_(std::move(filter_values)) {
DCHECK(!lookback_window_.has_value() || lookback_window_->is_positive());
@ -398,10 +398,10 @@ base::expected<FiltersDisjunction, TriggerRegistrationError> FiltersFromJSON(
return base::unexpected(TriggerRegistrationError::kFiltersWrongType);
}
absl::optional<base::TimeDelta> lookback_window;
if (absl::optional<base::Value> lookback_window_value =
std::optional<base::TimeDelta> lookback_window;
if (std::optional<base::Value> lookback_window_value =
dict->Extract(FilterConfig::kLookbackWindowKey)) {
if (absl::optional<int> int_val = lookback_window_value->GetIfInt()) {
if (std::optional<int> int_val = lookback_window_value->GetIfInt()) {
lookback_window = base::Seconds(*int_val);
} else {
return base::unexpected(

@ -5,6 +5,7 @@
#ifndef COMPONENTS_ATTRIBUTION_REPORTING_FILTERS_H_
#define COMPONENTS_ATTRIBUTION_REPORTING_FILTERS_H_
#include <optional>
#include <string>
#include <vector>
@ -16,7 +17,6 @@
#include "components/attribution_reporting/source_registration_error.mojom-forward.h"
#include "components/attribution_reporting/source_type.mojom-forward.h"
#include "components/attribution_reporting/trigger_registration_error.mojom-forward.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
namespace attribution_reporting {
@ -34,7 +34,7 @@ class COMPONENT_EXPORT(ATTRIBUTION_REPORTING) FilterData {
static constexpr char kSourceTypeFilterKey[] = "source_type";
// Filter data is not allowed to contain a `source_type` filter.
static absl::optional<FilterData> Create(FilterValues);
static std::optional<FilterData> Create(FilterValues);
static base::expected<FilterData, mojom::SourceRegistrationError> FromJSON(
base::Value*);
@ -108,9 +108,9 @@ class COMPONENT_EXPORT(ATTRIBUTION_REPORTING) FilterConfig {
static constexpr char kReservedKeyPrefix[] = "_";
// If set, FilterConfig's `lookback_window` must be positive.
static absl::optional<FilterConfig> Create(
static std::optional<FilterConfig> Create(
FilterValues,
absl::optional<base::TimeDelta> lookback_window = absl::nullopt);
std::optional<base::TimeDelta> lookback_window = std::nullopt);
FilterConfig();
~FilterConfig();
@ -121,7 +121,7 @@ class COMPONENT_EXPORT(ATTRIBUTION_REPORTING) FilterConfig {
FilterConfig& operator=(const FilterConfig&);
FilterConfig& operator=(FilterConfig&&);
const absl::optional<base::TimeDelta>& lookback_window() const {
const std::optional<base::TimeDelta>& lookback_window() const {
return lookback_window_;
}
@ -131,8 +131,8 @@ class COMPONENT_EXPORT(ATTRIBUTION_REPORTING) FilterConfig {
private:
explicit FilterConfig(FilterValues,
absl::optional<base::TimeDelta> lookback_window);
absl::optional<base::TimeDelta> lookback_window_;
std::optional<base::TimeDelta> lookback_window);
std::optional<base::TimeDelta> lookback_window_;
FilterValues filter_values_;
};

@ -6,6 +6,7 @@
#include <stddef.h>
#include <optional>
#include <string>
#include <utility>
#include <vector>
@ -25,7 +26,6 @@
#include "components/attribution_reporting/trigger_registration_error.mojom.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
namespace attribution_reporting {
namespace {
@ -82,13 +82,13 @@ const base::Time kTriggerTime = kSourceTime + base::Seconds(5);
const struct {
const char* description;
absl::optional<base::Value> json;
std::optional<base::Value> json;
base::expected<FilterData, SourceRegistrationError> expected_filter_data;
base::expected<FiltersDisjunction, TriggerRegistrationError> expected_filters;
} kParseTestCases[] = {
{
"Null",
absl::nullopt,
std::nullopt,
FilterData(),
FiltersDisjunction(),
},
@ -178,7 +178,7 @@ const struct {
const struct {
const char* description;
absl::optional<base::Value> json;
std::optional<base::Value> json;
SourceRegistrationError expected_filter_data_error;
} kSizeTestCases[] = {
{
@ -222,18 +222,18 @@ TEST(FilterDataTest, Create_LimitsFilterCount) {
TEST(FilterDataTest, FromJSON) {
for (auto& test_case : kParseTestCases) {
absl::optional<base::Value> json_copy =
test_case.json ? absl::make_optional(test_case.json->Clone())
: absl::nullopt;
std::optional<base::Value> json_copy =
test_case.json ? std::make_optional(test_case.json->Clone())
: std::nullopt;
EXPECT_EQ(FilterData::FromJSON(base::OptionalToPtr(json_copy)),
test_case.expected_filter_data)
<< test_case.description;
}
for (auto& test_case : kSizeTestCases) {
absl::optional<base::Value> json_copy =
test_case.json ? absl::make_optional(test_case.json->Clone())
: absl::nullopt;
std::optional<base::Value> json_copy =
test_case.json ? std::make_optional(test_case.json->Clone())
: std::nullopt;
EXPECT_THAT(FilterData::FromJSON(base::OptionalToPtr(json_copy)),
base::test::ErrorIs(test_case.expected_filter_data_error))
<< test_case.description;
@ -264,7 +264,7 @@ TEST(FilterDataTest, FromJSON_RecordsMetrics) {
using ::base::Bucket;
using ::testing::ElementsAre;
absl::optional<base::Value> json = base::test::ParseJson(R"json({
std::optional<base::Value> json = base::test::ParseJson(R"json({
"a": ["1", "2", "3"],
"b": [],
"c": ["4"],
@ -286,9 +286,9 @@ TEST(FiltersTest, FromJSON) {
for (auto& test_case : kParseTestCases) {
SCOPED_TRACE(test_case.description);
absl::optional<base::Value> json_copy =
test_case.json ? absl::make_optional(test_case.json->Clone())
: absl::nullopt;
std::optional<base::Value> json_copy =
test_case.json ? std::make_optional(test_case.json->Clone())
: std::nullopt;
EXPECT_EQ(FiltersFromJSONForTesting(base::OptionalToPtr(json_copy)),
test_case.expected_filters);
}
@ -296,9 +296,9 @@ TEST(FiltersTest, FromJSON) {
for (auto& test_case : kSizeTestCases) {
SCOPED_TRACE(test_case.description);
absl::optional<base::Value> json_copy =
test_case.json ? absl::make_optional(test_case.json->Clone())
: absl::nullopt;
std::optional<base::Value> json_copy =
test_case.json ? std::make_optional(test_case.json->Clone())
: std::nullopt;
auto result = FiltersFromJSONForTesting(base::OptionalToPtr(json_copy));
EXPECT_TRUE(result.has_value()) << result.error();
@ -438,7 +438,7 @@ TEST(FilterDataTest, EmptyOrMissingAttributionFilters) {
// Behavior should match for negated and non-negated filters as it
// requires a value on each side.
for (const auto& test_case : kTestCases) {
absl::optional<FilterData> filter_data =
std::optional<FilterData> filter_data =
FilterData::Create(test_case.filter_data);
ASSERT_TRUE(filter_data) << test_case.description;
@ -501,7 +501,7 @@ TEST(FilterDataTest, AttributionFilterDataMatch) {
false},
};
for (const auto& test_case : kTestCases) {
absl::optional<FilterData> filter_data =
std::optional<FilterData> filter_data =
FilterData::Create(test_case.filter_data);
ASSERT_TRUE(filter_data) << test_case.description;
@ -645,7 +645,7 @@ TEST(FilterDataTest, NegatedAttributionFilterDataMatch) {
};
for (const auto& test_case : kTestCases) {
absl::optional<FilterData> filter_data =
std::optional<FilterData> filter_data =
FilterData::Create(test_case.filter_data);
ASSERT_TRUE(filter_data) << test_case.description;

@ -4,12 +4,13 @@
#include "components/attribution_reporting/max_event_level_reports.h"
#include <optional>
#include "base/check.h"
#include "base/types/expected.h"
#include "base/values.h"
#include "components/attribution_reporting/source_registration_error.mojom.h"
#include "components/attribution_reporting/source_type.mojom.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
namespace attribution_reporting {
@ -46,7 +47,7 @@ MaxEventLevelReports::Parse(const base::Value::Dict& dict,
return MaxEventLevelReports(source_type);
}
absl::optional<int> i = value->GetIfInt();
std::optional<int> i = value->GetIfInt();
if (!i.has_value() || !IsMaxEventLevelReportsValid(*i)) {
return base::unexpected(
SourceRegistrationError::kMaxEventLevelReportsValueInvalid);

@ -4,12 +4,12 @@
#include "components/attribution_reporting/os_registration.h"
#include <optional>
#include <utility>
#include <vector>
#include "base/check_op.h"
#include "net/http/structured_headers.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "url/gurl.h"
namespace attribution_reporting {

@ -7,6 +7,7 @@
#include <stdint.h>
#include <cmath>
#include <optional>
#include <sstream>
#include <string>
#include <string_view>
@ -21,7 +22,6 @@
#include "components/attribution_reporting/constants.h"
#include "components/attribution_reporting/source_registration_error.mojom-forward.h"
#include "third_party/abseil-cpp/absl/numeric/int128.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "third_party/abseil-cpp/absl/types/variant.h"
namespace attribution_reporting {
@ -34,13 +34,13 @@ constexpr char kDeduplicationKey[] = "deduplication_key";
constexpr char kPriority[] = "priority";
template <typename T>
base::expected<absl::optional<T>, absl::monostate> ParseIntegerFromString(
base::expected<std::optional<T>, absl::monostate> ParseIntegerFromString(
const base::Value::Dict& dict,
std::string_view key,
bool (*parse)(std::string_view, T*)) {
const base::Value* value = dict.Find(key);
if (!value) {
return absl::nullopt;
return std::nullopt;
}
T parsed_val;
@ -82,13 +82,13 @@ std::string HexEncodeAggregationKey(absl::uint128 value) {
return out.str();
}
base::expected<absl::optional<uint64_t>, absl::monostate> ParseUint64(
base::expected<std::optional<uint64_t>, absl::monostate> ParseUint64(
const base::Value::Dict& dict,
std::string_view key) {
return ParseIntegerFromString<uint64_t>(dict, key, &base::StringToUint64);
}
base::expected<absl::optional<int64_t>, absl::monostate> ParseInt64(
base::expected<std::optional<int64_t>, absl::monostate> ParseInt64(
const base::Value::Dict& dict,
std::string_view key) {
return ParseIntegerFromString<int64_t>(dict, key, &base::StringToInt64);
@ -99,11 +99,11 @@ base::expected<int64_t, absl::monostate> ParsePriority(
return ParseInt64(dict, kPriority).transform(&ValueOrZero<int64_t>);
}
absl::optional<uint64_t> ParseDebugKey(const base::Value::Dict& dict) {
return ParseUint64(dict, kDebugKey).value_or(absl::nullopt);
std::optional<uint64_t> ParseDebugKey(const base::Value::Dict& dict) {
return ParseUint64(dict, kDebugKey).value_or(std::nullopt);
}
base::expected<absl::optional<uint64_t>, absl::monostate> ParseDeduplicationKey(
base::expected<std::optional<uint64_t>, absl::monostate> ParseDeduplicationKey(
const base::Value::Dict& dict) {
return ParseUint64(dict, kDeduplicationKey);
}
@ -121,7 +121,7 @@ ParseLegacyDuration(const base::Value& value,
// Reporting API itself clamps values to 30 days:
// https://wicg.github.io/attribution-reporting-api/#valid-source-expiry-range
if (absl::optional<int> int_value = value.GetIfInt()) {
if (std::optional<int> int_value = value.GetIfInt()) {
if (*int_value < 0) {
return base::unexpected(error);
}
@ -156,7 +156,7 @@ void SerializePriority(base::Value::Dict& dict, int64_t priority) {
}
void SerializeDebugKey(base::Value::Dict& dict,
absl::optional<uint64_t> debug_key) {
std::optional<uint64_t> debug_key) {
if (debug_key) {
SerializeUint64(dict, kDebugKey, *debug_key);
}
@ -167,7 +167,7 @@ void SerializeDebugReporting(base::Value::Dict& dict, bool debug_reporting) {
}
void SerializeDeduplicationKey(base::Value::Dict& dict,
absl::optional<uint64_t> dedup_key) {
std::optional<uint64_t> dedup_key) {
if (dedup_key) {
SerializeUint64(dict, kDeduplicationKey, *dedup_key);
}
@ -198,7 +198,7 @@ base::expected<uint32_t, mojom::SourceRegistrationError> ParseUint32(
//
// TODO(apaseltiner): Consider test coverage for all `uint32_t` values, or
// some kind of fuzzer.
absl::optional<double> double_value = value.GetIfDouble();
std::optional<double> double_value = value.GetIfDouble();
if (double int_part;
!double_value.has_value() || std::modf(*double_value, &int_part) != 0) {
return base::unexpected(wrong_type_error);

@ -8,6 +8,7 @@
#include <stdint.h>
#include <concepts>
#include <optional>
#include <string>
#include <string_view>
@ -16,7 +17,6 @@
#include "base/values.h"
#include "components/attribution_reporting/source_registration_error.mojom-forward.h"
#include "third_party/abseil-cpp/absl/numeric/int128.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "third_party/abseil-cpp/absl/types/variant.h"
namespace base {
@ -42,17 +42,17 @@ bool AggregationKeyIdHasValidLength(const std::string& key);
template <typename T>
requires(std::integral<T>)
constexpr T ValueOrZero(absl::optional<T> value) {
constexpr T ValueOrZero(std::optional<T> value) {
return value.value_or(0);
}
COMPONENT_EXPORT(ATTRIBUTION_REPORTING)
base::expected<absl::optional<uint64_t>, absl::monostate> ParseUint64(
base::expected<std::optional<uint64_t>, absl::monostate> ParseUint64(
const base::Value::Dict&,
std::string_view key);
COMPONENT_EXPORT(ATTRIBUTION_REPORTING)
base::expected<absl::optional<int64_t>, absl::monostate> ParseInt64(
base::expected<std::optional<int64_t>, absl::monostate> ParseInt64(
const base::Value::Dict&,
std::string_view key);
@ -62,13 +62,13 @@ base::expected<int64_t, absl::monostate> ParsePriority(
// Returns `debug_key` value as we do not need to fail the source registration
// if the value is invalid, see
// https://github.com/WICG/attribution-reporting-api/issues/793 for context.
absl::optional<uint64_t> ParseDebugKey(const base::Value::Dict& dict);
std::optional<uint64_t> ParseDebugKey(const base::Value::Dict& dict);
// Returns false if `dict` contains `debug_reporting` key but the value is
// invalid, returns true otherwise.
[[nodiscard]] bool ParseDebugReporting(const base::Value::Dict& dict);
base::expected<absl::optional<uint64_t>, absl::monostate> ParseDeduplicationKey(
base::expected<std::optional<uint64_t>, absl::monostate> ParseDeduplicationKey(
const base::Value::Dict&);
base::expected<base::TimeDelta, mojom::SourceRegistrationError>
@ -81,12 +81,12 @@ void SerializeInt64(base::Value::Dict&, std::string_view key, int64_t value);
void SerializePriority(base::Value::Dict&, int64_t priority);
void SerializeDebugKey(base::Value::Dict&, absl::optional<uint64_t> debug_key);
void SerializeDebugKey(base::Value::Dict&, std::optional<uint64_t> debug_key);
void SerializeDebugReporting(base::Value::Dict&, bool debug_reporting);
void SerializeDeduplicationKey(base::Value::Dict&,
absl::optional<uint64_t> dedup_key);
std::optional<uint64_t> dedup_key);
void SerializeTimeDeltaInSeconds(base::Value::Dict& dict,
std::string_view key,

@ -7,6 +7,7 @@
#include <stdint.h>
#include <limits>
#include <optional>
#include <string>
#include "base/test/gmock_expected_support.h"
@ -16,7 +17,6 @@
#include "components/attribution_reporting/constants.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/abseil-cpp/absl/numeric/int128.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "third_party/abseil-cpp/absl/types/variant.h"
namespace attribution_reporting {
@ -52,12 +52,12 @@ TEST(AttributionReportingParsingUtilsTest, ParseUint64) {
const struct {
const char* description;
const char* json;
base::expected<absl::optional<uint64_t>, absl::monostate> expected;
base::expected<std::optional<uint64_t>, absl::monostate> expected;
} kTestCases[] = {
{
"missing_key",
R"json({})json",
absl::nullopt,
std::nullopt,
},
{
"not_string",
@ -102,12 +102,12 @@ TEST(AttributionReportingParsingUtilsTest, ParseInt64) {
const struct {
const char* description;
const char* json;
base::expected<absl::optional<int64_t>, absl::monostate> expected;
base::expected<std::optional<int64_t>, absl::monostate> expected;
} kTestCases[] = {
{
"missing_key",
R"json({})json",
absl::nullopt,
std::nullopt,
},
{
"not_string",

@ -6,6 +6,7 @@
#include <stdint.h>
#include <optional>
#include <string>
#include <utility>
#include <vector>
@ -34,7 +35,6 @@
#include "net/base/schemeful_site.h"
#include "services/network/public/cpp/schemeful_site_mojom_traits.h"
#include "third_party/abseil-cpp/absl/numeric/int128.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "url/mojom/origin_mojom_traits.h"
#include "url/origin.h"
@ -70,7 +70,7 @@ bool StructTraits<attribution_reporting::mojom::FilterDataDataView,
return false;
}
absl::optional<attribution_reporting::FilterData> filter_data =
std::optional<attribution_reporting::FilterData> filter_data =
attribution_reporting::FilterData::Create(std::move(filter_values));
if (!filter_data.has_value()) {
return false;
@ -90,7 +90,7 @@ bool StructTraits<attribution_reporting::mojom::FilterConfigDataView,
return false;
}
absl::optional<base::TimeDelta> lookback_window;
std::optional<base::TimeDelta> lookback_window;
if (!data.ReadLookbackWindow(&lookback_window)) {
return false;
}
@ -115,7 +115,7 @@ bool StructTraits<attribution_reporting::mojom::AggregationKeysDataView,
return false;
}
absl::optional<attribution_reporting::AggregationKeys> aggregation_keys =
std::optional<attribution_reporting::AggregationKeys> aggregation_keys =
attribution_reporting::AggregationKeys::FromKeys(std::move(keys));
if (!aggregation_keys.has_value()) {
return false;
@ -361,12 +361,12 @@ bool StructTraits<attribution_reporting::mojom::TriggerRegistrationDataView,
return false;
}
absl::optional<std::string> trigger_context_id;
std::optional<std::string> trigger_context_id;
if (!data.ReadTriggerContextId(&trigger_context_id)) {
return false;
}
absl::optional<attribution_reporting::AggregatableTriggerConfig>
std::optional<attribution_reporting::AggregatableTriggerConfig>
aggregatable_trigger_config =
attribution_reporting::AggregatableTriggerConfig::Create(
data.source_registration_time_config(),

@ -7,6 +7,7 @@
#include <stdint.h>
#include <optional>
#include <string>
#include <vector>
@ -34,7 +35,6 @@
#include "net/base/schemeful_site.h"
#include "services/network/public/cpp/schemeful_site_mojom_traits.h"
#include "third_party/abseil-cpp/absl/numeric/int128.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "url/gurl.h"
#include "url/mojom/origin_mojom_traits.h"
#include "url/mojom/url_gurl_mojom_traits.h"
@ -72,7 +72,7 @@ template <>
struct COMPONENT_EXPORT(ATTRIBUTION_REPORTING_REGISTRATION_MOJOM_TRAITS)
StructTraits<attribution_reporting::mojom::FilterConfigDataView,
attribution_reporting::FilterConfig> {
static const absl::optional<base::TimeDelta>& lookback_window(
static const std::optional<base::TimeDelta>& lookback_window(
const attribution_reporting::FilterConfig& filter_config) {
return filter_config.lookback_window();
}
@ -201,7 +201,7 @@ struct COMPONENT_EXPORT(ATTRIBUTION_REPORTING_REGISTRATION_MOJOM_TRAITS)
return source.priority;
}
static absl::optional<uint64_t> debug_key(
static std::optional<uint64_t> debug_key(
const attribution_reporting::SourceRegistration& source) {
return source.debug_key;
}
@ -267,7 +267,7 @@ struct COMPONENT_EXPORT(ATTRIBUTION_REPORTING_REGISTRATION_MOJOM_TRAITS)
return data.priority;
}
static absl::optional<uint64_t> dedup_key(
static std::optional<uint64_t> dedup_key(
const attribution_reporting::EventTriggerData& data) {
return data.dedup_key;
}
@ -331,7 +331,7 @@ struct COMPONENT_EXPORT(ATTRIBUTION_REPORTING_REGISTRATION_MOJOM_TRAITS)
return trigger.aggregatable_values.values();
}
static absl::optional<uint64_t> debug_key(
static std::optional<uint64_t> debug_key(
const attribution_reporting::TriggerRegistration& trigger) {
return trigger.debug_key;
}
@ -347,7 +347,7 @@ struct COMPONENT_EXPORT(ATTRIBUTION_REPORTING_REGISTRATION_MOJOM_TRAITS)
return trigger.debug_reporting;
}
static const absl::optional<attribution_reporting::SuitableOrigin>&
static const std::optional<attribution_reporting::SuitableOrigin>&
aggregation_coordinator_origin(
const attribution_reporting::TriggerRegistration& trigger) {
return trigger.aggregation_coordinator_origin;
@ -360,7 +360,7 @@ struct COMPONENT_EXPORT(ATTRIBUTION_REPORTING_REGISTRATION_MOJOM_TRAITS)
.source_registration_time_config();
}
static const absl::optional<std::string>& trigger_context_id(
static const std::optional<std::string>& trigger_context_id(
const attribution_reporting::TriggerRegistration& trigger) {
return trigger.aggregatable_trigger_config.trigger_context_id();
}
@ -374,7 +374,7 @@ template <>
struct COMPONENT_EXPORT(ATTRIBUTION_REPORTING_REGISTRATION_MOJOM_TRAITS)
StructTraits<attribution_reporting::mojom::AggregatableDedupKeyDataView,
attribution_reporting::AggregatableDedupKey> {
static absl::optional<uint64_t> dedup_key(
static std::optional<uint64_t> dedup_key(
const attribution_reporting::AggregatableDedupKey& data) {
return data.dedup_key;
}

@ -7,6 +7,7 @@
#include <stdint.h>
#include <algorithm>
#include <optional>
#include <string>
#include <utility>
@ -30,7 +31,6 @@
#include "components/attribution_reporting/suitable_origin.h"
#include "components/attribution_reporting/trigger_config.h"
#include "mojo/public/cpp/bindings/default_construct_tag.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "third_party/abseil-cpp/absl/types/variant.h"
namespace attribution_reporting {
@ -163,7 +163,7 @@ SourceRegistration::Parse(std::string_view json, SourceType source_type) {
base::expected<SourceRegistration, SourceRegistrationError> source =
base::unexpected(SourceRegistrationError::kInvalidJson);
absl::optional<base::Value> value =
std::optional<base::Value> value =
base::JSONReader::Read(json, base::JSON_PARSE_RFC);
if (value) {

@ -7,6 +7,7 @@
#include <stdint.h>
#include <optional>
#include <string_view>
#include "base/component_export.h"
@ -24,7 +25,6 @@
#include "components/attribution_reporting/source_type.mojom-forward.h"
#include "components/attribution_reporting/trigger_data_matching.mojom.h"
#include "mojo/public/cpp/bindings/default_construct_tag.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
namespace attribution_reporting {
@ -72,7 +72,7 @@ struct COMPONENT_EXPORT(ATTRIBUTION_REPORTING) SourceRegistration {
MaxEventLevelReports max_event_level_reports;
int64_t priority = 0;
FilterData filter_data;
absl::optional<uint64_t> debug_key;
std::optional<uint64_t> debug_key;
AggregationKeys aggregation_keys;
bool debug_reporting = false;
mojom::TriggerDataMatching trigger_data_matching =

@ -2,9 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/attribution_reporting/source_registration.h"
#include <stdlib.h>
#include <iostream>
#include <optional>
#include <string>
#include <tuple>
#include <utility>
@ -14,12 +17,10 @@
#include "base/json/json_reader.h"
#include "base/logging.h"
#include "base/values.h"
#include "components/attribution_reporting/source_registration.h"
#include "components/attribution_reporting/source_type.mojom.h"
#include "testing/libfuzzer/proto/json.pb.h"
#include "testing/libfuzzer/proto/json_proto_converter.h"
#include "testing/libfuzzer/proto/lpm_interface.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
namespace attribution_reporting {
@ -44,7 +45,7 @@ DEFINE_PROTO_FUZZER(const json_proto::JsonValue& json_value) {
if (getenv("LPM_DUMP_NATIVE_INPUT"))
std::cout << native_input << std::endl;
absl::optional<base::Value> input = base::JSONReader::Read(
std::optional<base::Value> input = base::JSONReader::Read(
native_input, base::JSONParserOptions::JSON_PARSE_RFC);
if (!input || !input->is_dict())
return;

@ -4,6 +4,7 @@
#include "components/attribution_reporting/source_registration.h"
#include <optional>
#include <utility>
#include "base/functional/function_ref.h"
@ -27,7 +28,6 @@
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/abseil-cpp/absl/numeric/int128.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
namespace attribution_reporting {
namespace {
@ -85,7 +85,7 @@ TEST(SourceRegistrationTest, Parse) {
MaxEventLevelReports(SourceType::kNavigation)),
Field(&SourceRegistration::priority, 0),
Field(&SourceRegistration::filter_data, FilterData()),
Field(&SourceRegistration::debug_key, absl::nullopt),
Field(&SourceRegistration::debug_key, std::nullopt),
Field(&SourceRegistration::aggregation_keys, AggregationKeys()),
Field(&SourceRegistration::debug_reporting, false),
Field(&SourceRegistration::trigger_data_matching,
@ -281,12 +281,12 @@ TEST(SourceRegistrationTest, Parse) {
{
"debug_key_invalid",
R"json({"debug_key":"-5","destination":"https://d.example"})json",
ValueIs(Field(&SourceRegistration::debug_key, absl::nullopt)),
ValueIs(Field(&SourceRegistration::debug_key, std::nullopt)),
},
{
"debug_key_wrong_type",
R"json({"debug_key":5,"destination":"https://d.example"})json",
ValueIs(Field(&SourceRegistration::debug_key, absl::nullopt)),
ValueIs(Field(&SourceRegistration::debug_key, std::nullopt)),
},
{
"filter_data_valid",

@ -4,6 +4,7 @@
#include "components/attribution_reporting/suitable_origin.h"
#include <optional>
#include <string>
#include <utility>
@ -11,7 +12,6 @@
#include "components/attribution_reporting/is_origin_suitable.h"
#include "mojo/public/cpp/bindings/default_construct_tag.h"
#include "net/base/schemeful_site.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "url/gurl.h"
#include "url/origin.h"
@ -28,20 +28,20 @@ bool SuitableOrigin::IsSuitable(const url::Origin& origin) {
}
// static
absl::optional<SuitableOrigin> SuitableOrigin::Create(url::Origin origin) {
std::optional<SuitableOrigin> SuitableOrigin::Create(url::Origin origin) {
if (!IsSuitable(origin))
return absl::nullopt;
return std::nullopt;
return SuitableOrigin(std::move(origin));
}
// static
absl::optional<SuitableOrigin> SuitableOrigin::Create(const GURL& url) {
std::optional<SuitableOrigin> SuitableOrigin::Create(const GURL& url) {
return Create(url::Origin::Create(url));
}
// static
absl::optional<SuitableOrigin> SuitableOrigin::Deserialize(
std::optional<SuitableOrigin> SuitableOrigin::Deserialize(
std::string_view str) {
return Create(GURL(str));
}

@ -6,6 +6,7 @@
#define COMPONENTS_ATTRIBUTION_REPORTING_SUITABLE_ORIGIN_H_
#include <compare>
#include <optional>
#include <string>
#include <string_view>
#include <utility>
@ -13,7 +14,6 @@
#include "base/check.h"
#include "base/component_export.h"
#include "mojo/public/cpp/bindings/default_construct_tag.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "url/origin.h"
class GURL;
@ -45,16 +45,16 @@ class COMPONENT_EXPORT(ATTRIBUTION_REPORTING) SuitableOrigin {
public:
static bool IsSuitable(const url::Origin&);
static absl::optional<SuitableOrigin> Create(url::Origin);
static std::optional<SuitableOrigin> Create(url::Origin);
static absl::optional<SuitableOrigin> Create(const GURL&);
static std::optional<SuitableOrigin> Create(const GURL&);
// Creates a `SuitableOrigin` from the given string, which is first converted
// to a `GURL`, then to a `url::Origin`, and then subject to this class's
// invariants.
//
// All parts of the URL other than the origin are ignored.
static absl::optional<SuitableOrigin> Deserialize(std::string_view);
static std::optional<SuitableOrigin> Deserialize(std::string_view);
// Creates an invalid instance for use with Mojo deserialization, which
// requires types to be default-constructible.

@ -4,9 +4,10 @@
#include "components/attribution_reporting/suitable_origin.h"
#include <optional>
#include "net/base/schemeful_site.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "url/gurl.h"
#include "url/origin.h"
@ -49,7 +50,7 @@ TEST(SuitableOriginTest, Create) {
SuitableOrigin::IsSuitable(test_case.origin))
<< test_case.origin;
absl::optional<SuitableOrigin> actual =
std::optional<SuitableOrigin> actual =
SuitableOrigin::Create(test_case.origin);
EXPECT_EQ(test_case.expected_suitable, actual.has_value())
@ -65,17 +66,17 @@ TEST(SuitableOriginTest, Create) {
TEST(SuitableOriginTest, Deserialize_Serialize) {
const struct {
std::string_view str;
absl::optional<url::Origin> expected;
std::optional<url::Origin> expected;
const char* expected_serialization;
} kTestCases[] = {
{
"",
absl::nullopt,
std::nullopt,
nullptr,
},
{
"http://a.test",
absl::nullopt,
std::nullopt,
nullptr,
},
{
@ -95,18 +96,18 @@ TEST(SuitableOriginTest, Deserialize_Serialize) {
},
{
"ws://a.test",
absl::nullopt,
std::nullopt,
nullptr,
},
{
"wss://a.test",
absl::nullopt,
std::nullopt,
nullptr,
},
};
for (const auto& test_case : kTestCases) {
absl::optional<SuitableOrigin> actual =
std::optional<SuitableOrigin> actual =
SuitableOrigin::Deserialize(test_case.str);
EXPECT_EQ(test_case.expected.has_value(), actual.has_value())

@ -4,6 +4,7 @@
#include "components/attribution_reporting/test_utils.h"
#include <optional>
#include <ostream>
#include <string>
@ -27,14 +28,13 @@
#include "components/attribution_reporting/trigger_config.h"
#include "components/attribution_reporting/trigger_registration.h"
#include "net/base/schemeful_site.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "url/origin.h"
namespace attribution_reporting {
FiltersDisjunction FiltersForSourceType(
mojom::SourceType source_type,
absl::optional<base::TimeDelta> lookback_window) {
std::optional<base::TimeDelta> lookback_window) {
return {*FilterConfig::Create(
{
{

@ -6,11 +6,11 @@
#define COMPONENTS_ATTRIBUTION_REPORTING_TEST_UTILS_H_
#include <iosfwd>
#include <optional>
#include "components/attribution_reporting/filters.h"
#include "components/attribution_reporting/source_type.mojom-forward.h"
#include "components/attribution_reporting/trigger_config.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
namespace base {
class TimeDelta;
@ -35,7 +35,7 @@ struct TriggerRegistration;
FiltersDisjunction FiltersForSourceType(
mojom::SourceType,
absl::optional<base::TimeDelta> lookback_window = absl::nullopt);
std::optional<base::TimeDelta> lookback_window = std::nullopt);
std::ostream& operator<<(std::ostream&, const AggregationKeys&);

@ -6,6 +6,7 @@
#include <stdint.h>
#include <optional>
#include <string>
#include <utility>
#include <vector>
@ -24,7 +25,6 @@
#include "components/attribution_reporting/source_registration_error.mojom.h"
#include "components/attribution_reporting/source_type.mojom.h"
#include "components/attribution_reporting/trigger_data_matching.mojom.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
namespace attribution_reporting {
@ -282,11 +282,11 @@ TriggerSpecs TriggerSpecs::Default(SourceType source_type,
}
// static
absl::optional<TriggerSpecs> TriggerSpecs::Create(
std::optional<TriggerSpecs> TriggerSpecs::Create(
TriggerDataIndices trigger_data_indices,
std::vector<TriggerSpec> specs) {
if (!AreSpecsValid(trigger_data_indices, specs)) {
return absl::nullopt;
return std::nullopt;
}
return TriggerSpecs(std::move(trigger_data_indices), std::move(specs));
}

@ -71,8 +71,8 @@ class COMPONENT_EXPORT(ATTRIBUTION_REPORTING) TriggerSpecs {
// source type.
static TriggerSpecs Default(mojom::SourceType, EventReportWindows);
static absl::optional<TriggerSpecs> Create(TriggerDataIndices,
std::vector<TriggerSpec>);
static std::optional<TriggerSpecs> Create(TriggerDataIndices,
std::vector<TriggerSpec>);
static TriggerSpecs CreateForTesting(TriggerDataIndices,
std::vector<TriggerSpec>);

@ -4,6 +4,7 @@
#include "components/attribution_reporting/trigger_registration.h"
#include <optional>
#include <utility>
#include <vector>
@ -26,7 +27,6 @@
#include "components/attribution_reporting/parsing_utils.h"
#include "components/attribution_reporting/suitable_origin.h"
#include "components/attribution_reporting/trigger_registration_error.mojom.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
namespace attribution_reporting {
@ -42,13 +42,13 @@ constexpr char kAggregatableTriggerData[] = "aggregatable_trigger_data";
constexpr char kAggregatableValues[] = "aggregatable_values";
constexpr char kEventTriggerData[] = "event_trigger_data";
base::expected<absl::optional<SuitableOrigin>, TriggerRegistrationError>
base::expected<std::optional<SuitableOrigin>, TriggerRegistrationError>
ParseAggregationCoordinator(const base::Value* value) {
// The default value is used for backward compatibility prior to this
// attribute being added, but ideally this would invalidate the registration
// if other aggregatable fields were present.
if (!value) {
return absl::nullopt;
return std::nullopt;
}
const std::string* str = value->GetIfString();
@ -57,7 +57,7 @@ ParseAggregationCoordinator(const base::Value* value) {
TriggerRegistrationError::kAggregationCoordinatorWrongType);
}
absl::optional<url::Origin> aggregation_coordinator =
std::optional<url::Origin> aggregation_coordinator =
aggregation_service::ParseAggregationCoordinator(*str);
if (!aggregation_coordinator.has_value()) {
return base::unexpected(
@ -165,7 +165,7 @@ TriggerRegistration::Parse(std::string_view json) {
base::expected<TriggerRegistration, TriggerRegistrationError> trigger =
base::unexpected(TriggerRegistrationError::kInvalidJson);
absl::optional<base::Value> value =
std::optional<base::Value> value =
base::JSONReader::Read(json, base::JSON_PARSE_RFC);
if (value) {

@ -7,6 +7,7 @@
#include <stdint.h>
#include <optional>
#include <string_view>
#include <vector>
@ -18,7 +19,6 @@
#include "components/attribution_reporting/filters.h"
#include "components/attribution_reporting/suitable_origin.h"
#include "components/attribution_reporting/trigger_registration_error.mojom-forward.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
namespace attribution_reporting {
@ -52,13 +52,13 @@ struct COMPONENT_EXPORT(ATTRIBUTION_REPORTING) TriggerRegistration {
const TriggerRegistration&) = default;
FilterPair filters;
absl::optional<uint64_t> debug_key;
std::optional<uint64_t> debug_key;
std::vector<AggregatableDedupKey> aggregatable_dedup_keys;
std::vector<EventTriggerData> event_triggers;
std::vector<AggregatableTriggerData> aggregatable_trigger_data;
AggregatableValues aggregatable_values;
bool debug_reporting = false;
absl::optional<SuitableOrigin> aggregation_coordinator_origin;
std::optional<SuitableOrigin> aggregation_coordinator_origin;
AggregatableTriggerConfig aggregatable_trigger_config;
};

@ -2,9 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/attribution_reporting/trigger_registration.h"
#include <stdlib.h>
#include <iostream>
#include <optional>
#include <string>
#include <tuple>
#include <utility>
@ -14,11 +17,9 @@
#include "base/json/json_reader.h"
#include "base/logging.h"
#include "base/values.h"
#include "components/attribution_reporting/trigger_registration.h"
#include "testing/libfuzzer/proto/json.pb.h"
#include "testing/libfuzzer/proto/json_proto_converter.h"
#include "testing/libfuzzer/proto/lpm_interface.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
namespace attribution_reporting {
@ -43,7 +44,7 @@ DEFINE_PROTO_FUZZER(const json_proto::JsonValue& json_value) {
if (getenv("LPM_DUMP_NATIVE_INPUT"))
std::cout << native_input << std::endl;
absl::optional<base::Value> input = base::JSONReader::Read(
std::optional<base::Value> input = base::JSONReader::Read(
native_input, base::JSONParserOptions::JSON_PARSE_RFC);
if (!input || !input->is_dict())
return;

@ -4,6 +4,7 @@
#include "components/attribution_reporting/trigger_registration.h"
#include <optional>
#include <string>
#include <utility>
#include <vector>
@ -30,7 +31,6 @@
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/abseil-cpp/absl/numeric/int128.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "url/gurl.h"
#include "url/origin.h"
@ -77,7 +77,7 @@ TEST(TriggerRegistrationTest, Parse) {
R"json({})json",
ValueIs(AllOf(
Field(&TriggerRegistration::filters, FilterPair()),
Field(&TriggerRegistration::debug_key, absl::nullopt),
Field(&TriggerRegistration::debug_key, std::nullopt),
Field(&TriggerRegistration::aggregatable_dedup_keys, IsEmpty()),
Field(&TriggerRegistration::event_triggers, IsEmpty()),
Field(&TriggerRegistration::aggregatable_trigger_data, IsEmpty()),
@ -85,7 +85,7 @@ TEST(TriggerRegistrationTest, Parse) {
AggregatableValues()),
Field(&TriggerRegistration::debug_reporting, false),
Field(&TriggerRegistration::aggregation_coordinator_origin,
absl::nullopt),
std::nullopt),
Field(&TriggerRegistration::aggregatable_trigger_config,
AggregatableTriggerConfig()))),
},
@ -126,22 +126,21 @@ TEST(TriggerRegistrationTest, Parse) {
{
"debug_key_invalid",
R"json({"debug_key":"-5"})json",
ValueIs(Field(&TriggerRegistration::debug_key, absl::nullopt)),
ValueIs(Field(&TriggerRegistration::debug_key, std::nullopt)),
},
{
"debug_key_wrong_type",
R"json({"debug_key":5})json",
ValueIs(Field(&TriggerRegistration::debug_key, absl::nullopt)),
ValueIs(Field(&TriggerRegistration::debug_key, std::nullopt)),
},
{
"event_triggers_valid",
R"json({"event_trigger_data":[{}, {"trigger_data":"5"}]})json",
ValueIs(
Field(&TriggerRegistration::event_triggers,
ElementsAre(EventTriggerData(),
EventTriggerData(/*data=*/5, /*priority=*/0,
/*dedup_key=*/absl::nullopt,
FilterPair())))),
ValueIs(Field(&TriggerRegistration::event_triggers,
ElementsAre(EventTriggerData(),
EventTriggerData(/*data=*/5, /*priority=*/0,
/*dedup_key=*/std::nullopt,
FilterPair())))),
},
{
"event_triggers_wrong_type",

@ -388,7 +388,7 @@ void ProfileImportProcess::AcceptWithoutEdits() {
void ProfileImportProcess::AcceptWithEdits(AutofillProfile edited_profile) {
SetUserDecision(UserDecision::kEditAccepted,
absl::make_optional(edited_profile));
std::make_optional(edited_profile));
}
void ProfileImportProcess::Declined() {

@ -846,7 +846,7 @@ TEST_F(AutofillSuggestionGeneratorTest,
EXPECT_THAT(
suggestion_generator()->CreateSuggestionsFromProfiles(
{&profile}, {NAME_FIRST, NAME_LAST},
/*last_targeted_fields=*/absl::nullopt, NAME_FIRST,
/*last_targeted_fields=*/std::nullopt, NAME_FIRST,
/*trigger_field_max_length=*/0),
SuggestionVectorMainTextsAre(Suggestion::Text(
profile.GetRawInfo(NAME_FULL), Suggestion::Text::IsPrimary(true))));
@ -900,7 +900,7 @@ TEST_P(
EXPECT_THAT(suggestion_generator()->CreateSuggestionsFromProfiles(
{&profile},
{NAME_FULL, ADDRESS_HOME_STREET_ADDRESS, ADDRESS_HOME_ZIP},
/*last_targeted_fields=*/absl::nullopt, trigerring_field_type,
/*last_targeted_fields=*/std::nullopt, trigerring_field_type,
/*trigger_field_max_length=*/0),
ElementsAre(AllOf(testing::Field(
&Suggestion::labels,
@ -926,7 +926,7 @@ TEST_P(
EXPECT_THAT(
suggestion_generator()->CreateSuggestionsFromProfiles(
{&profile1, &profile2}, {NAME_FULL, ADDRESS_HOME_STREET_ADDRESS},
/*last_targeted_fields=*/absl::nullopt, trigerring_field_type,
/*last_targeted_fields=*/std::nullopt, trigerring_field_type,
/*trigger_field_max_length=*/0),
ElementsAre(
AllOf(testing::Field(
@ -959,7 +959,7 @@ TEST_P(
EXPECT_THAT(
suggestion_generator()->CreateSuggestionsFromProfiles(
{&profile1, &profile2}, {NAME_FULL, ADDRESS_HOME_STREET_ADDRESS},
/*last_targeted_fields=*/absl::nullopt, trigerring_field_type,
/*last_targeted_fields=*/std::nullopt, trigerring_field_type,
/*trigger_field_max_length=*/0),
ElementsAre(
AllOf(testing::Field(

@ -2918,7 +2918,7 @@ std::vector<Suggestion> BrowserAutofillManager::GetProfileSuggestions(
// not used and only holds semantic value.
return suggestion_generator_->GetSuggestionsForProfiles(
/*field_types=*/{UNKNOWN_TYPE}, trigger_field, UNKNOWN_TYPE,
/*last_targeted_fields=*/absl::nullopt, trigger_source);
/*last_targeted_fields=*/std::nullopt, trigger_source);
}
// If not manual fallback, `form_structure` and `autofill_field` should exist.
CHECK(form_structure && trigger_autofill_field);

@ -416,7 +416,7 @@ struct FillUtilExpirationDateTestCase {
bool expected_response;
const char* opt_label = nullptr;
FieldType server_override = UNKNOWN_TYPE;
// If this is absl::nullopt, a test is valid regardless whether the
// If this is std::nullopt, a test is valid regardless whether the
// features::kAutofillEnableExpirationDateImprovements is enabled or not.
// If it is true, it should only execute if
// features::kAutofillEnableExpirationDateImprovements is enabled. The inverse

@ -74,11 +74,11 @@ RegexMatchesCache::Key RegexMatchesCache::BuildKey(
std::hash<std::u16string_view>{}(pattern));
}
absl::optional<bool> RegexMatchesCache::Get(RegexMatchesCache::Key key) {
std::optional<bool> RegexMatchesCache::Get(RegexMatchesCache::Key key) {
if (auto it = cache_.Get(key); it != cache_.end()) {
return it->second;
}
return absl::nullopt;
return std::nullopt;
}
void RegexMatchesCache::Put(RegexMatchesCache::Key key, bool value) {
@ -112,7 +112,7 @@ bool FormFieldParser::MatchesRegexWithCache(
RegexMatchesCache::Key key;
if (!groups && context.matches_cache) {
key = RegexMatchesCache::BuildKey(input, pattern);
absl::optional<bool> cache_entry = context.matches_cache->Get(key);
std::optional<bool> cache_entry = context.matches_cache->Get(key);
if (cache_entry.has_value()) {
return cache_entry.value();
}

@ -71,8 +71,8 @@ class RegexMatchesCache {
static Key BuildKey(base::StringPiece16 input, base::StringPiece16 pattern);
// Returns whether `pattern` in the key matched `input` if this information is
// cached. absl::nullopt if the information is not cached.
absl::optional<bool> Get(Key key);
// cached. std::nullopt if the information is not cached.
std::optional<bool> Get(Key key);
// Stores whether `pattern` in the key matched `input`.
void Put(Key key, bool value);

@ -15,7 +15,7 @@ namespace autofill {
TEST(LabelProcessingUtil, GetParseableNameStringPieces) {
std::vector<base::StringPiece16> labels{u"City", u"Street & House Number",
u"", u"Zip"};
auto expectation = absl::make_optional(
auto expectation = std::make_optional(
std::vector<std::u16string>{u"City", u"Street", u"House Number", u"Zip"});
EXPECT_EQ(GetParseableLabels(labels), expectation);
@ -27,7 +27,7 @@ TEST(LabelProcessingUtil, GetParseableNameStringPieces) {
TEST(LabelProcessingUtil, GetParseableNameStringPieces_ThreeComponents) {
EXPECT_EQ(GetParseableLabels(
{u"City", u"Street & House Number & Floor", u"", u"", u"Zip"}),
absl::make_optional(std::vector<std::u16string>{
std::make_optional(std::vector<std::u16string>{
u"City", u"Street", u"House Number", u"Floor", u"Zip"}));
}

@ -348,7 +348,7 @@ class FormStructure {
if (randomized_encoder_) {
return randomized_encoder_.get();
}
return absl::nullopt;
return std::nullopt;
}
const LanguageCode& current_page_language() const {

@ -3718,7 +3718,7 @@ TEST_F(PersonalDataManagerTest, ClearUrlsFromBrowsingHistoryInTimeRange) {
history::DeletionInfo deletion_info(
history::DeletionTimeRange(base::Time::Min(), end_of_deletion), false,
deleted_urls, {},
absl::make_optional<std::set<GURL>>({first_url, second_url}));
std::make_optional<std::set<GURL>>({first_url, second_url}));
personal_data_->OnURLsDeleted(/*history_service=*/nullptr, deletion_info);

@ -226,7 +226,7 @@ TEST_F(AutofillAcrossIframesTest, WithChildFrames) {
// Get the frame tokens from the registrar. Wrap this in a block because the
// registrar receives these from each frame in a separate JS message.
__block absl::optional<LocalFrameToken> local_token1, local_token2;
__block std::optional<LocalFrameToken> local_token1, local_token2;
ASSERT_TRUE(base::test::ios::WaitUntilConditionOrTimeout(
base::test::ios::kWaitForJSCompletionTimeout, ^bool {
local_token1 = registrar->LookupChildFrame(

@ -167,7 +167,7 @@ constexpr base::TimeDelta kA11yAnnouncementQueueDelay = base::Seconds(1);
// The autofill data that needs to be send when the |webState_| is shown.
// The pair contains the frame ID and the base::Value::Dict to send.
// If the value is nullopt, no data needs to be sent.
absl::optional<std::pair<std::string, base::Value::Dict>> _pendingFormData;
std::optional<std::pair<std::string, base::Value::Dict>> _pendingFormData;
// Bridge to listen to pref changes.
std::unique_ptr<PrefObserverBridge> _prefObserverBridge;
@ -796,7 +796,7 @@ constexpr base::TimeDelta kA11yAnnouncementQueueDelay = base::Seconds(1);
std::pair<std::string, base::Value::Dict> pendingFormData =
std::move(_pendingFormData).value();
_pendingFormData = absl::nullopt;
_pendingFormData = std::nullopt;
// The frameID cannot be empty.
DCHECK(!pendingFormData.first.empty());

@ -85,7 +85,7 @@ bool IsContextSecureForWebState(web::WebState* web_state) {
}
std::unique_ptr<base::Value> ParseJson(NSString* json_string) {
absl::optional<base::Value> json_value =
std::optional<base::Value> json_value =
base::JSONReader::Read(base::SysNSStringToUTF8(json_string));
if (!json_value) {
return nullptr;
@ -316,7 +316,7 @@ bool ExtractFormFieldData(const base::Value::Dict& field,
field.FindString("autocomplete_attribute")) {
field_data->autocomplete_attribute = *autocomplete_attribute;
}
if (absl::optional<int> max_length = field.FindInt("max_length")) {
if (std::optional<int> max_length = field.FindInt("max_length")) {
field_data->max_length = *max_length;
}
field_data->parsed_autocomplete =
@ -347,7 +347,7 @@ bool ExtractFormFieldData(const base::Value::Dict& field,
// RoleAttribute::kOther is the default value. The only other value as of this
// writing is RoleAttribute::kPresentation.
absl::optional<int> role = field.FindInt("role");
std::optional<int> role = field.FindInt("role");
if (role &&
*role == static_cast<int>(FormFieldData::RoleAttribute::kPresentation)) {
field_data->role = FormFieldData::RoleAttribute::kPresentation;

@ -78,7 +78,7 @@ bool FormActivityParams::FromMessage(const web::ScriptMessage& message,
const std::string* field_type = message_body->FindString("fieldType");
const std::string* type = message_body->FindString("type");
const std::string* value = message_body->FindString("value");
absl::optional<bool> has_user_gesture =
std::optional<bool> has_user_gesture =
message_body->FindBool("hasUserGesture");
if (!field_identifier || !unique_field_id || !field_type || !type || !value ||
!has_user_gesture) {

@ -59,7 +59,7 @@ void FormHandlersJavaScriptFeature::ToggleTrackingUserEditedFields(
base::Value::List().Append(track_user_edited_fields));
}
absl::optional<std::string>
std::optional<std::string>
FormHandlersJavaScriptFeature::GetScriptMessageHandlerName() const {
return kScriptMessageName;
}

@ -5,6 +5,7 @@
#ifndef COMPONENTS_BACKGROUND_SYNC_BACKGROUND_SYNC_DELEGATE_H_
#define COMPONENTS_BACKGROUND_SYNC_BACKGROUND_SYNC_DELEGATE_H_
#include <optional>
#include <set>
#include "base/functional/callback.h"
@ -12,7 +13,6 @@
#include "build/build_config.h"
#include "content/public/browser/background_sync_controller.h"
#include "services/metrics/public/cpp/ukm_source_id.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "third_party/blink/public/mojom/background_sync/background_sync.mojom-forward.h"
#include "url/origin.h"
@ -37,10 +37,10 @@ class BackgroundSyncDelegate {
#endif
// Gets the source_ID to log the UKM event for, and calls |callback| with that
// source_id, or with absl::nullopt if UKM recording is not allowed.
// source_id, or with std::nullopt if UKM recording is not allowed.
virtual void GetUkmSourceId(
const url::Origin& origin,
base::OnceCallback<void(absl::optional<ukm::SourceId>)> callback) = 0;
base::OnceCallback<void(std::optional<ukm::SourceId>)> callback) = 0;
// Handles browser shutdown.
virtual void Shutdown() = 0;

@ -83,7 +83,7 @@ void BackgroundSyncMetrics::MaybeRecordPeriodicSyncEventCompletion(
void BackgroundSyncMetrics::DidGetBackgroundSourceId(
RecordCallback record_callback,
absl::optional<ukm::SourceId> source_id) {
std::optional<ukm::SourceId> source_id) {
// This background event did not meet the requirements for the UKM service.
if (!source_id)
return;

@ -5,11 +5,12 @@
#ifndef COMPONENTS_BACKGROUND_SYNC_BACKGROUND_SYNC_METRICS_H_
#define COMPONENTS_BACKGROUND_SYNC_BACKGROUND_SYNC_METRICS_H_
#include <optional>
#include "base/functional/callback.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "services/metrics/public/cpp/ukm_source_id.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "third_party/blink/public/common/service_worker/service_worker_status_code.h"
namespace {
@ -62,7 +63,7 @@ class BackgroundSyncMetrics {
friend class BackgroundSyncMetricsBrowserTest;
void DidGetBackgroundSourceId(RecordCallback record_callback,
absl::optional<ukm::SourceId> source_id);
std::optional<ukm::SourceId> source_id);
void RecordOneShotSyncRegistrationEvent(bool can_fire,
bool is_reregistered,

@ -6,10 +6,11 @@
#define COMPONENTS_BACKGROUND_TASK_SCHEDULER_TASK_INFO_H_
#include <stdint.h>
#include <optional>
#include <string>
#include "components/background_task_scheduler/task_ids.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
namespace background_task {
@ -64,8 +65,8 @@ struct TaskInfo {
bool update_current = false;
std::string extras;
absl::optional<PeriodicInfo> periodic_info;
absl::optional<OneOffInfo> one_off_info;
std::optional<PeriodicInfo> periodic_info;
std::optional<OneOffInfo> one_off_info;
};
} // namespace background_task

@ -116,7 +116,7 @@ void PopupBlockerTabHelper::ShowBlockedPopup(
BlockedRequest* popup = it->second.get();
absl::optional<WindowOpenDisposition> updated_disposition;
std::optional<WindowOpenDisposition> updated_disposition;
if (disposition != WindowOpenDisposition::CURRENT_TAB)
updated_disposition = disposition;

@ -5,8 +5,9 @@
#ifndef COMPONENTS_BLOCKED_CONTENT_POPUP_NAVIGATION_DELEGATE_H_
#define COMPONENTS_BLOCKED_CONTENT_POPUP_NAVIGATION_DELEGATE_H_
#include <optional>
#include "base/memory/raw_ptr.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "third_party/blink/public/mojom/window_features/window_features.mojom-forward.h"
#include "ui/base/window_open_disposition.h"
@ -42,7 +43,7 @@ class PopupNavigationDelegate {
};
virtual NavigateResult NavigateWithGesture(
const blink::mojom::WindowFeatures& window_features,
absl::optional<WindowOpenDisposition> updated_disposition) = 0;
std::optional<WindowOpenDisposition> updated_disposition) = 0;
// Called when the navigation represented by this class was blocked.
virtual void OnPopupBlocked(content::WebContents* web_contents,

Some files were not shown because too many files have changed in this diff Show More