Skip to content

Commit

Permalink
Rename {absl => std}::optional in //tools/
Browse files Browse the repository at this point in the history
Automated patch, intended to be effectively a no-op.

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

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 "^tools" \
    | sort \
    | uniq \
    | grep \
      -e "\.h" \
      -e "\.cc" \
      -e "\.mm" \
      -e "\.py" \
    | 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>"
git cl format
```

NOTRY=True

Bug: chromium:1500249
Change-Id: I7536d03fa09fb48f8cf7113eba8eb727d5efba7b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5185809
Reviewed-by: Nico Weber <[email protected]>
Commit-Queue: Arthur Sonzogni <[email protected]>
Auto-Submit: Arthur Sonzogni <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1245840}
  • Loading branch information
ArthurSonzogni authored and Chromium LUCI CQ committed Jan 11, 2024
1 parent 7bba8ed commit b263d25
Show file tree
Hide file tree
Showing 34 changed files with 155 additions and 149 deletions.
4 changes: 2 additions & 2 deletions tools/accessibility/inspect/ax_dump_events.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ int main(int argc, char** argv) {
return 0;
}

absl::optional<ui::AXInspectScenario> scenario =
std::optional<ui::AXInspectScenario> scenario =
tools::ScenarioFromCommandLine(*command_line);
if (!scenario) {
return 1;
}

absl::optional<AXTreeSelector> selector =
std::optional<AXTreeSelector> selector =
tools::TreeSelectorFromCommandLine(*command_line);

if (!selector || selector->empty()) {
Expand Down
4 changes: 2 additions & 2 deletions tools/accessibility/inspect/ax_dump_tree.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ int main(int argc, char** argv) {
return 0;
}

absl::optional<ui::AXTreeSelector> selector =
std::optional<ui::AXTreeSelector> selector =
tools::TreeSelectorFromCommandLine(*command_line);

if (!selector || selector->empty()) {
Expand Down Expand Up @@ -109,7 +109,7 @@ int main(int argc, char** argv) {
if (api == ui::AXApiType::kNone && !apis.empty())
api = apis[0];

absl::optional<ui::AXInspectScenario> scenario =
std::optional<ui::AXInspectScenario> scenario =
tools::ScenarioFromCommandLine(*command_line, api);
if (!scenario) {
return 1;
Expand Down
12 changes: 6 additions & 6 deletions tools/accessibility/inspect/ax_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ void PrintHelpFooter() {
"automated-testing/ax-inspect\n");
}

absl::optional<AXTreeSelector> TreeSelectorFromCommandLine(
std::optional<AXTreeSelector> TreeSelectorFromCommandLine(
const base::CommandLine& command_line) {
int selectors = AXTreeSelector::None;
if (command_line.HasSwitch(kChromeSwitch)) {
Expand All @@ -116,7 +116,7 @@ absl::optional<AXTreeSelector> TreeSelectorFromCommandLine(
unsigned hwnd_or_pid = 0;
if (!StringToInt(id_str, &hwnd_or_pid)) {
LOG(ERROR) << "Error: can't convert window id string to integer.";
return absl::nullopt;
return std::nullopt;
}
return AXTreeSelector(selectors, pattern_str,
CastToAcceleratedWidget(hwnd_or_pid));
Expand All @@ -140,13 +140,13 @@ std::string DirectivePrefixFromAPIType(ui::AXApiType::Type api) {
}
}

absl::optional<ui::AXInspectScenario> ScenarioFromCommandLine(
std::optional<ui::AXInspectScenario> ScenarioFromCommandLine(
const base::CommandLine& command_line,
ui::AXApiType::Type api) {
base::FilePath filters_path = command_line.GetSwitchValuePath(kFiltersSwitch);
if (filters_path.empty() && command_line.HasSwitch(kFiltersSwitch)) {
LOG(ERROR) << "Error: empty filter path given. Run with --help for help.";
return absl::nullopt;
return std::nullopt;
}

std::string directive_prefix = DirectivePrefixFromAPIType(api);
Expand All @@ -157,13 +157,13 @@ absl::optional<ui::AXInspectScenario> ScenarioFromCommandLine(
std::vector<std::string>());
}

absl::optional<ui::AXInspectScenario> scenario =
std::optional<ui::AXInspectScenario> scenario =
ui::AXInspectScenario::From(directive_prefix, filters_path);
if (!scenario) {
LOG(ERROR) << "Error: failed to open filters file " << filters_path
<< ". Note: path traversal components ('..') are not allowed "
"for security reasons";
return absl::nullopt;
return std::nullopt;
}
return scenario;
}
Expand Down
7 changes: 4 additions & 3 deletions tools/accessibility/inspect/ax_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
#ifndef TOOLS_ACCESSIBILITY_INSPECT_AX_UTILS_H_
#define TOOLS_ACCESSIBILITY_INSPECT_AX_UTILS_H_

#include <optional>

#include "base/command_line.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "ui/accessibility/platform/inspect/ax_api_type.h"
#include "ui/accessibility/platform/inspect/ax_inspect.h"
#include "ui/accessibility/platform/inspect/ax_inspect_scenario.h"
Expand All @@ -27,12 +28,12 @@ void PrintHelpFooter();

// Returns tree selector from the command line arguments. Returns nullopt in
// case of error.
absl::optional<ui::AXTreeSelector> TreeSelectorFromCommandLine(
std::optional<ui::AXTreeSelector> TreeSelectorFromCommandLine(
const base::CommandLine& command_line);

// Returns inspect scenario from the command line arguments. Returns nullopt in
// case of error.
absl::optional<ui::AXInspectScenario> ScenarioFromCommandLine(
std::optional<ui::AXInspectScenario> ScenarioFromCommandLine(
const base::CommandLine& command_line,
ui::AXApiType::Type api = ui::AXApiType::kNone);

Expand Down
12 changes: 6 additions & 6 deletions tools/aggregation_service/aggregation_service_tool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ namespace aggregation_service {

namespace {

absl::optional<content::TestAggregationService::Operation> ConvertToOperation(
std::optional<content::TestAggregationService::Operation> ConvertToOperation(
const std::string& operation_string) {
if (operation_string == "histogram")
return content::TestAggregationService::Operation::kHistogram;

return absl::nullopt;
return std::nullopt;
}

absl::optional<content::TestAggregationService::AggregationMode>
std::optional<content::TestAggregationService::AggregationMode>
ConvertToAggregationMode(const std::string& aggregation_mode_string) {
if (aggregation_mode_string == "tee-based")
return content::TestAggregationService::AggregationMode::kTeeBased;
Expand All @@ -49,7 +49,7 @@ ConvertToAggregationMode(const std::string& aggregation_mode_string) {
if (aggregation_mode_string == "default")
return content::TestAggregationService::AggregationMode::kDefault;

return absl::nullopt;
return std::nullopt;
}

} // namespace
Expand Down Expand Up @@ -128,7 +128,7 @@ base::Value::Dict AggregationServiceTool::AssembleReport(
std::string api_identifier) {
base::Value::Dict result;

absl::optional<content::TestAggregationService::Operation> operation =
std::optional<content::TestAggregationService::Operation> operation =
ConvertToOperation(operation_str);
if (!operation.has_value()) {
LOG(ERROR) << "Invalid operation: " << operation_str;
Expand All @@ -147,7 +147,7 @@ base::Value::Dict AggregationServiceTool::AssembleReport(
return result;
}

absl::optional<content::TestAggregationService::AggregationMode>
std::optional<content::TestAggregationService::AggregationMode>
aggregation_mode = ConvertToAggregationMode(aggregation_mode_str);
if (!aggregation_mode.has_value()) {
LOG(ERROR) << "Invalid aggregation mode: " << aggregation_mode_str;
Expand Down
4 changes: 2 additions & 2 deletions tools/clang/blink_gc_plugin/tests/forbidden_fields.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ class AnotherHeapObject : public GarbageCollected<AnotherHeapObject> {
TaskRunnerTimer<AnotherHeapObject> array_of_bad_typ_e[2];
SecondLevelPartObject array_of_embedded_object_[2];
std::vector<TaskRunnerTimer<AnotherHeapObject>> std_vec_of_timers_;
absl::optional<TaskRunnerTimer<AnotherHeapObject>> optional_timer_;
std::optional<TaskRunnerTimer<AnotherHeapObject>> optional_timer_;
std::optional<TaskRunnerTimer<AnotherHeapObject>> optional_timer2_;
absl::optional<SecondLevelPartObject> optional_embedded_object_;
std::optional<SecondLevelPartObject> optional_embedded_object_;
std::optional<SecondLevelPartObject> optional_embedded_object2_;
absl::variant<SecondLevelPartObject> variant_embedded_object_;
std::variant<SecondLevelPartObject> variant_embedded_object2_;
Expand Down
2 changes: 1 addition & 1 deletion tools/imagediff/image_diff.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <algorithm>
#include <iostream>
#include <memory>
#include <optional>
#include <string>
#include <unordered_map>
#include <vector>
Expand All @@ -29,7 +30,6 @@
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "tools/imagediff/image_diff_png.h"

#if BUILDFLAG(IS_WIN)
Expand Down
4 changes: 2 additions & 2 deletions tools/ipc_fuzzer/fuzzer/fuzzer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1523,12 +1523,12 @@ struct FuzzTraits<url::Origin> {
if (!FuzzParam(&port, fuzzer))
return false;

absl::optional<url::Origin> origin;
std::optional<url::Origin> origin;
if (!opaque) {
origin = url::Origin::UnsafelyCreateTupleOriginWithoutNormalization(
scheme, host, port);
} else {
absl::optional<base::UnguessableToken> token;
std::optional<base::UnguessableToken> token;
if (auto* nonce = p->GetNonceForSerialization()) {
token = *nonce;
} else {
Expand Down
6 changes: 3 additions & 3 deletions tools/json_to_struct/element_generator_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ def testGenerateClassFieldContent(self):
lines = []
GenerateFieldContent('', {
'type': 'class',
'default': 'absl::nullopt'
'default': 'std::nullopt'
}, None, lines, ' ', {})
self.assertEquals([' absl::nullopt,'], lines)
self.assertEquals([' std::nullopt,'], lines)
lines = []
GenerateFieldContent('', {
'type': 'class',
'default': 'absl::nullopt'
'default': 'std::nullopt'
}, 'true', lines, ' ', {})
self.assertEquals([' true,'], lines)
lines = []
Expand Down
4 changes: 2 additions & 2 deletions tools/json_to_struct/struct_generator_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ def testGenerateArrayField(self):

def testGenerateClassField(self):
self.assertEquals(
'const absl::optional<bool> bar',
'const std::optional<bool> bar',
GenerateField({
'type': 'class',
'field': 'bar',
'ctype': 'absl::optional<bool>'
'ctype': 'std::optional<bool>'
}))

def testGenerateStruct(self):
Expand Down
11 changes: 6 additions & 5 deletions tools/mac/power/power_sampler/battery_sampler.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
#define TOOLS_MAC_POWER_POWER_SAMPLER_BATTERY_SAMPLER_H_

#include <stdint.h>

#include <cstdint>
#include <memory>
#include <optional>

#include "base/mac/scoped_ioobject.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "tools/mac/power/power_sampler/sampler.h"

namespace power_sampler {
Expand Down Expand Up @@ -71,13 +72,13 @@ class BatterySampler : public Sampler {
int64_t update_time_seconds_since_epoch;
};
using MaybeGetBatteryDataFn =
absl::optional<BatteryData> (*)(io_service_t power_source);
std::optional<BatteryData> (*)(io_service_t power_source);
using GetSecondsSinceEpochFn = int64_t (*)();

// TODO(siggi): It'd be possible to test the data extraction part of this
// function by splitting it in two and passing it a dictionary to
// dissect.
static absl::optional<BatteryData> MaybeGetBatteryData(
static std::optional<BatteryData> MaybeGetBatteryData(
io_service_t power_source);

struct AvgConsumption {
Expand All @@ -87,7 +88,7 @@ class BatterySampler : public Sampler {

// Yields average for |prev_data|, |new_data| and |duration| if the current
// capacity has changed between |prev_data| and |new_data|.
static absl::optional<AvgConsumption> MaybeComputeAvgConsumption(
static std::optional<AvgConsumption> MaybeComputeAvgConsumption(
base::TimeDelta duration,
const BatteryData& prev_data,
const BatteryData& new_data);
Expand Down Expand Up @@ -129,7 +130,7 @@ class BatterySampler : public Sampler {
// capacity change, it's possible to keep track of the actual current
// consumption.
base::TimeTicks prev_battery_sample_time_ = base::TimeTicks::Min();
absl::optional<BatteryData> prev_battery_data_;
std::optional<BatteryData> prev_battery_data_;
};

} // namespace power_sampler
Expand Down
34 changes: 17 additions & 17 deletions tools/mac/power/power_sampler/battery_sampler.mm
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,24 @@
// Returns the value corresponding to |key| in the dictionary |description|.
// Returns |default_value| if the dictionary does not contain |key|, the
// corresponding value is nullptr or it could not be converted to SInt64.
absl::optional<SInt64> GetValueAsSInt64(CFDictionaryRef description,
CFStringRef key) {
std::optional<SInt64> GetValueAsSInt64(CFDictionaryRef description,
CFStringRef key) {
CFNumberRef number_ref =
base::apple::GetValueFromDictionary<CFNumberRef>(description, key);

SInt64 value;
if (number_ref && CFNumberGetValue(number_ref, kCFNumberSInt64Type, &value))
return value;

return absl::nullopt;
return std::nullopt;
}

absl::optional<bool> GetValueAsBoolean(CFDictionaryRef description,
CFStringRef key) {
std::optional<bool> GetValueAsBoolean(CFDictionaryRef description,
CFStringRef key) {
CFBooleanRef boolean =
base::apple::GetValueFromDictionary<CFBooleanRef>(description, key);
if (!boolean)
return absl::nullopt;
return std::nullopt;
return CFBooleanGetValue(boolean);
}

Expand Down Expand Up @@ -86,7 +86,7 @@
}

Sampler::Sample BatterySampler::GetSample(base::TimeTicks sample_time) {
absl::optional<BatteryData> new_battery_data =
std::optional<BatteryData> new_battery_data =
maybe_get_battery_data_fn_(power_source_.get());
if (!new_battery_data.has_value())
return Sample();
Expand Down Expand Up @@ -127,30 +127,30 @@
}

// static
absl::optional<BatterySampler::BatteryData> BatterySampler::MaybeGetBatteryData(
std::optional<BatterySampler::BatteryData> BatterySampler::MaybeGetBatteryData(
io_service_t power_source) {
base::apple::ScopedCFTypeRef<CFMutableDictionaryRef> dict;
kern_return_t result = IORegistryEntryCreateCFProperties(
power_source, dict.InitializeInto(), 0, 0);
if (result != KERN_SUCCESS) {
MACH_LOG(ERROR, result) << "IORegistryEntryCreateCFProperties";
return absl::nullopt;
return std::nullopt;
}

absl::optional<bool> external_connected =
std::optional<bool> external_connected =
GetValueAsBoolean(dict.get(), CFSTR("ExternalConnected"));
absl::optional<SInt64> voltage_mv =
std::optional<SInt64> voltage_mv =
GetValueAsSInt64(dict.get(), CFSTR(kIOPSVoltageKey));
absl::optional<SInt64> current_capacity_mah =
std::optional<SInt64> current_capacity_mah =
GetValueAsSInt64(dict.get(), CFSTR("AppleRawCurrentCapacity"));
absl::optional<SInt64> max_capacity_mah =
std::optional<SInt64> max_capacity_mah =
GetValueAsSInt64(dict.get(), CFSTR("AppleRawMaxCapacity"));
absl::optional<SInt64> update_time =
std::optional<SInt64> update_time =
GetValueAsSInt64(dict.get(), CFSTR("UpdateTime"));

if (!external_connected.has_value() || !voltage_mv.has_value() ||
!current_capacity_mah.has_value() || !max_capacity_mah.has_value()) {
return absl::nullopt;
return std::nullopt;
}

BatteryData data{.external_connected = external_connected.value(),
Expand All @@ -163,7 +163,7 @@
}

// static
absl::optional<BatterySampler::AvgConsumption>
std::optional<BatterySampler::AvgConsumption>
BatterySampler::MaybeComputeAvgConsumption(base::TimeDelta duration,
const BatteryData& prev_data,
const BatteryData& new_data) {
Expand All @@ -183,7 +183,7 @@
int64_t delta_current_consumed_mah =
prev_current_consumed_mah - new_current_consumed_mah;
if (delta_current_consumed_mah == 0)
return absl::nullopt;
return std::nullopt;

double avg_voltage_v =
(new_data.voltage_mv + prev_data.voltage_mv) / (2.0 * 1000.0);
Expand Down
Loading

0 comments on commit b263d25

Please sign in to comment.