Rename {absl => std}::optional Final n°2
#cleanup Automated patch. This is a no-op. Please avoid, as much as possible, assigning unrelated bugs to this. Context: https://groups.google.com/a/chromium.org/g/cxx/c/nBD_1LaanTc/m/ghh-ZZhWAwAJ?utm_medium=email As of https://crrev.com/1204351, absl::optional is now a type alias for std::optional. We should migrate toward it. Script: ``` function replace { echo "Replacing $1 by $2" git grep -l "$1" \ | cut -f1 -d: \ | grep -v \ -e "third_party/abseil-cpp/*" \ -e "third_party/googletest/*" \ -e "third_party/leveldatabase/*" \ -e "third_party/libaddressinput/" \ -e "third_party/liburlpattern/*" \ -e "third_party/lzma_sdk/*" \ -e "third_party/maldoca/*" \ -e "third_party/mediapipe/*" \ -e "third_party/shell-encryption/*"\ -e "third_party/tflite_support/*" \ -e "third_party/webrtc_overrides/*" \ -e "third_party/zxcvbn-cpp/*" \ | grep \ -e "\.h" \ -e "\.cc" \ -e "\.mm" \ -e "\.pidl" \ | sort \ | uniq \ | xargs sed -i "s/$1/$2/g" } replace "absl::make_optional" "std::make_optional" replace "absl::optional" "std::optional" replace "absl::nullopt" "std::nullopt" replace "absl::in_place," "std::in_place," replace "absl::in_place_t," "std::in_place_t," replace "absl::in_place)" "std::in_place)" replace "absl::in_place_t)" "std::in_place_t)" replace "\"third_party\/abseil-cpp\/absl\/types\/optional.h\"" "<optional>" git status echo "Formatting" echo "IncludeBlocks: Regroup" >> ".clang-format" echo "IncludeIsMainRegex: \"(_(android|apple|chromeos|freebsd|fuchsia|fuzzer|ios|linux|mac|nacl|openbsd|posix|stubs?|win))?(_(unit|browser|perf)?tests?)?$\"" >> ".clang-format" git cl format git restore ".clang-format" ``` Cleanup: rename Bug: chromium:1500249 Change-Id: I7cb6bc208109aa9b0a2d70e6cd5a7253c3cc4c0e Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5321725 Commit-Queue: danakj <danakj@chromium.org> Owners-Override: danakj <danakj@chromium.org> Reviewed-by: danakj <danakj@chromium.org> Auto-Submit: Arthur Sonzogni <arthursonzogni@chromium.org> Cr-Commit-Position: refs/heads/main@{#1265221}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
3e1f8946b9
commit
405944145a
base/json
chrome/browser/tab
components
cast_streaming
browser
public
power_metrics
energy_impact_mac.henergy_impact_mac.mmenergy_metrics_provider.henergy_metrics_provider_linux.ccenergy_metrics_provider_linux.henergy_metrics_provider_win.ccenergy_metrics_provider_win.hm1_sensors_mac.hm1_sensors_mac.mmresource_coalition_mac.hresource_coalition_mac.mmresource_coalition_mac_unittest.mmsmc_mac.hsmc_mac.mmsystem_power_monitor_unittest.cc
zucchini
third_party/blink
@ -105,14 +105,14 @@ class BASE_EXPORT JSONReader {
|
||||
JSONReader& operator=(const JSONReader&) = delete;
|
||||
|
||||
// Reads and parses |json|, returning a Value.
|
||||
// If |json| is not a properly formed JSON string, returns absl::nullopt.
|
||||
// If |json| is not a properly formed JSON string, returns std::nullopt.
|
||||
static std::optional<Value> Read(
|
||||
std::string_view json,
|
||||
int options = JSON_PARSE_CHROMIUM_EXTENSIONS,
|
||||
size_t max_depth = internal::kAbsoluteMaxDepth);
|
||||
|
||||
// Reads and parses |json|, returning a Value::Dict.
|
||||
// If |json| is not a properly formed JSON dict string, returns absl::nullopt.
|
||||
// If |json| is not a properly formed JSON dict string, returns std::nullopt.
|
||||
static std::optional<Value::Dict> ReadDict(
|
||||
std::string_view json,
|
||||
int options = JSON_PARSE_CHROMIUM_EXTENSIONS,
|
||||
|
@ -289,7 +289,7 @@ bool ExtractNavigationEntries(
|
||||
for (int i = 0; i < entry_count; ++i) {
|
||||
// Read each SerializedNavigationEntry as a separate pickle to avoid
|
||||
// optional reads of one tab bleeding into the next tab's data.
|
||||
absl::optional<base::span<const uint8_t>> tab_entry = iter.ReadData();
|
||||
std::optional<base::span<const uint8_t>> tab_entry = iter.ReadData();
|
||||
if (!tab_entry.has_value()) {
|
||||
LOG(ERROR) << "Failed to restore tab entry from byte array.";
|
||||
return false; // It's dangerous to keep deserializing now, give up.
|
||||
|
@ -5,11 +5,12 @@
|
||||
#ifndef COMPONENTS_CAST_STREAMING_BROWSER_PUBLIC_RECEIVER_CONFIG_H_
|
||||
#define COMPONENTS_CAST_STREAMING_BROWSER_PUBLIC_RECEIVER_CONFIG_H_
|
||||
|
||||
#include <optional>
|
||||
|
||||
#include "base/time/time.h"
|
||||
#include "media/base/audio_codecs.h"
|
||||
#include "media/base/channel_layout.h"
|
||||
#include "media/base/video_codecs.h"
|
||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||
#include "ui/gfx/geometry/rect.h"
|
||||
|
||||
namespace cast_streaming {
|
||||
@ -28,7 +29,7 @@ class ReceiverConfig {
|
||||
|
||||
// Maximum maintainable frame rate. If left unset, will use the
|
||||
// implementation default.
|
||||
absl::optional<int> max_frame_rate;
|
||||
std::optional<int> max_frame_rate;
|
||||
|
||||
// Whether the embedder is capable of scaling content. If set to false, the
|
||||
// sender will manage the aspect ratio scaling.
|
||||
@ -39,11 +40,11 @@ class ReceiverConfig {
|
||||
struct AudioLimits {
|
||||
// Audio codec these limits apply to. If left empty, this instance is
|
||||
// assumed to apply to all codecs.
|
||||
absl::optional<media::AudioCodec> codec;
|
||||
std::optional<media::AudioCodec> codec;
|
||||
|
||||
// Maximum audio sample rate.If left unset, will use the implementation
|
||||
// default.
|
||||
absl::optional<int> max_sample_rate;
|
||||
std::optional<int> max_sample_rate;
|
||||
|
||||
// Maximum audio channels.
|
||||
media::ChannelLayout channel_layout = media::CHANNEL_LAYOUT_STEREO;
|
||||
@ -51,8 +52,8 @@ class ReceiverConfig {
|
||||
// Minimum and maximum bitrates. Generally capture is done at the maximum
|
||||
// bit rate, since audio bandwidth is much lower than video for most
|
||||
// content. If left unset, will use the implementation defaults.
|
||||
absl::optional<int> min_bit_rate;
|
||||
absl::optional<int> max_bit_rate;
|
||||
std::optional<int> min_bit_rate;
|
||||
std::optional<int> max_bit_rate;
|
||||
|
||||
// Max playout delay in milliseconds.
|
||||
base::TimeDelta max_delay = base::Milliseconds(1500);
|
||||
@ -62,7 +63,7 @@ class ReceiverConfig {
|
||||
struct VideoLimits {
|
||||
// Video codec these limits apply to. If left empty, this instance is
|
||||
// assumed to apply to all codecs.
|
||||
absl::optional<media::VideoCodec> codec;
|
||||
std::optional<media::VideoCodec> codec;
|
||||
|
||||
// Maximum pixels per second. Value is the standard amount of pixels for
|
||||
// 1080P at 30FPS.
|
||||
@ -74,14 +75,14 @@ class ReceiverConfig {
|
||||
|
||||
// Maximum maintainable frame rate. If left unset, will use the
|
||||
// implementation default.
|
||||
absl::optional<int> max_frame_rate;
|
||||
std::optional<int> max_frame_rate;
|
||||
|
||||
// Minimum and maximum bitrates. Default values are based on default min and
|
||||
// max dimensions, embedders that support different display dimensions
|
||||
// should strongly consider setting these fields. If left unset, will use
|
||||
// the implementation defaults.
|
||||
absl::optional<int> min_bit_rate;
|
||||
absl::optional<int> max_bit_rate;
|
||||
std::optional<int> min_bit_rate;
|
||||
std::optional<int> max_bit_rate;
|
||||
|
||||
// Max playout delay in milliseconds.
|
||||
base::TimeDelta max_delay = base::Milliseconds(1500);
|
||||
@ -147,7 +148,7 @@ class ReceiverConfig {
|
||||
std::vector<media::AudioCodec> audio_codecs,
|
||||
std::vector<AudioLimits> audio_limits,
|
||||
std::vector<VideoLimits> video_limits,
|
||||
absl::optional<Display> description);
|
||||
std::optional<Display> description);
|
||||
~ReceiverConfig();
|
||||
|
||||
ReceiverConfig(ReceiverConfig&&) noexcept;
|
||||
@ -169,12 +170,12 @@ class ReceiverConfig {
|
||||
// vector of size 1 with the |codec| field empty.
|
||||
std::vector<AudioLimits> audio_limits;
|
||||
std::vector<VideoLimits> video_limits;
|
||||
absl::optional<Display> display_description;
|
||||
std::optional<Display> display_description;
|
||||
|
||||
// Libcast remoting support is opt-in: embedders wishing to field remoting
|
||||
// offers may provide a set of remoting constraints, or leave nullptr for all
|
||||
// remoting OFFERs to be rejected in favor of continuing streaming.
|
||||
absl::optional<RemotingConstraints> remoting;
|
||||
std::optional<RemotingConstraints> remoting;
|
||||
};
|
||||
|
||||
} // namespace cast_streaming
|
||||
|
@ -5,11 +5,11 @@
|
||||
#ifndef COMPONENTS_POWER_METRICS_ENERGY_IMPACT_MAC_H_
|
||||
#define COMPONENTS_POWER_METRICS_ENERGY_IMPACT_MAC_H_
|
||||
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
#include "base/files/file_path.h"
|
||||
#include "base/time/time.h"
|
||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||
|
||||
struct coalition_resource_usage;
|
||||
|
||||
@ -47,7 +47,7 @@ struct EnergyImpactCoefficients {
|
||||
// Reads the Energy Impact coefficients for the current machine from disk, or
|
||||
// default coefficients if coefficients are not available for the current
|
||||
// machine.
|
||||
absl::optional<EnergyImpactCoefficients>
|
||||
std::optional<EnergyImpactCoefficients>
|
||||
ReadCoefficientsForCurrentMachineOrDefault();
|
||||
|
||||
// Computes the Energy Impact score for the resource consumption data in
|
||||
@ -70,7 +70,7 @@ namespace internal {
|
||||
// Reads the coefficients from the "energy_constants" sub-dictionary of the
|
||||
// plist file at |plist_file|. This is exposed for testing, production code
|
||||
// should use ReadCoefficientsForCurrentMachineOrDefault().
|
||||
absl::optional<EnergyImpactCoefficients> ReadCoefficientsFromPath(
|
||||
std::optional<EnergyImpactCoefficients> ReadCoefficientsFromPath(
|
||||
const base::FilePath& plist_file);
|
||||
|
||||
// Given a |directory| and a |board_id|, read the plist file for the board id
|
||||
@ -78,7 +78,7 @@ absl::optional<EnergyImpactCoefficients> ReadCoefficientsFromPath(
|
||||
// Returns true if either file can be loaded, false otherwise. This is exposed
|
||||
// for testing, production code should use
|
||||
// ReadCoefficientsForCurrentMachineOrDefault().
|
||||
absl::optional<EnergyImpactCoefficients> ReadCoefficientsForBoardIdOrDefault(
|
||||
std::optional<EnergyImpactCoefficients> ReadCoefficientsForBoardIdOrDefault(
|
||||
const base::FilePath& directory,
|
||||
const std::string& board_id);
|
||||
|
||||
@ -86,7 +86,7 @@ absl::optional<EnergyImpactCoefficients> ReadCoefficientsForBoardIdOrDefault(
|
||||
// the current machine. This appears to work for Intel Macs only. This is
|
||||
// exposed for testing, production code should use
|
||||
// ReadCoefficientsForCurrentMachineOrDefault().
|
||||
absl::optional<std::string> GetBoardIdForThisMachine();
|
||||
std::optional<std::string> GetBoardIdForThisMachine();
|
||||
|
||||
} // namespace internal
|
||||
|
||||
|
@ -33,11 +33,11 @@ double GetNamedCoefficientOrZero(NSDictionary* dict, NSString* key) {
|
||||
|
||||
} // namespace
|
||||
|
||||
absl::optional<EnergyImpactCoefficients>
|
||||
std::optional<EnergyImpactCoefficients>
|
||||
ReadCoefficientsForCurrentMachineOrDefault() {
|
||||
absl::optional<std::string> board_id = internal::GetBoardIdForThisMachine();
|
||||
std::optional<std::string> board_id = internal::GetBoardIdForThisMachine();
|
||||
if (!board_id.has_value())
|
||||
return absl::nullopt;
|
||||
return std::nullopt;
|
||||
|
||||
return internal::ReadCoefficientsForBoardIdOrDefault(
|
||||
base::FilePath(FILE_PATH_LITERAL("/usr/share/pmenergy")),
|
||||
@ -108,17 +108,17 @@ double ComputeEnergyImpactForResourceUsage(
|
||||
|
||||
namespace internal {
|
||||
|
||||
absl::optional<EnergyImpactCoefficients> ReadCoefficientsFromPath(
|
||||
std::optional<EnergyImpactCoefficients> ReadCoefficientsFromPath(
|
||||
const base::FilePath& plist_file) {
|
||||
@autoreleasepool {
|
||||
NSDictionary* dict = MaybeGetDictionaryFromPath(plist_file);
|
||||
if (!dict) {
|
||||
return absl::nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
NSDictionary* energy_constants = dict[@"energy_constants"];
|
||||
if (!energy_constants) {
|
||||
return absl::nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
EnergyImpactCoefficients coefficients{};
|
||||
@ -161,7 +161,7 @@ absl::optional<EnergyImpactCoefficients> ReadCoefficientsFromPath(
|
||||
}
|
||||
}
|
||||
|
||||
absl::optional<EnergyImpactCoefficients> ReadCoefficientsForBoardIdOrDefault(
|
||||
std::optional<EnergyImpactCoefficients> ReadCoefficientsForBoardIdOrDefault(
|
||||
const base::FilePath& directory,
|
||||
const std::string& board_id) {
|
||||
auto coefficients = ReadCoefficientsFromPath(
|
||||
@ -173,12 +173,12 @@ absl::optional<EnergyImpactCoefficients> ReadCoefficientsForBoardIdOrDefault(
|
||||
directory.Append(FILE_PATH_LITERAL("default.plist")));
|
||||
}
|
||||
|
||||
absl::optional<std::string> GetBoardIdForThisMachine() {
|
||||
std::optional<std::string> GetBoardIdForThisMachine() {
|
||||
base::mac::ScopedIOObject<io_service_t> platform_expert(
|
||||
IOServiceGetMatchingService(kIOMasterPortDefault,
|
||||
IOServiceMatching("IOPlatformExpertDevice")));
|
||||
if (!platform_expert)
|
||||
return absl::nullopt;
|
||||
return std::nullopt;
|
||||
|
||||
// This is what libpmenergy is observed to do in order to retrieve the correct
|
||||
// coefficients file for the local computer.
|
||||
@ -187,7 +187,7 @@ absl::optional<std::string> GetBoardIdForThisMachine() {
|
||||
platform_expert.get(), CFSTR("board-id"), kCFAllocatorDefault, 0)));
|
||||
|
||||
if (!board_id_data)
|
||||
return absl::nullopt;
|
||||
return std::nullopt;
|
||||
|
||||
return reinterpret_cast<const char*>(CFDataGetBytePtr(board_id_data.get()));
|
||||
}
|
||||
|
@ -7,8 +7,7 @@
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
|
||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||
#include <optional>
|
||||
|
||||
namespace power_metrics {
|
||||
|
||||
@ -45,7 +44,7 @@ class EnergyMetricsProvider {
|
||||
|
||||
// Used to capture energy consumption metrics. It returns nullopt if not
|
||||
// available on the current platform.
|
||||
virtual absl::optional<EnergyMetrics> CaptureMetrics() = 0;
|
||||
virtual std::optional<EnergyMetrics> CaptureMetrics() = 0;
|
||||
|
||||
protected:
|
||||
// The constructor is intentionally only exposed to subclasses. Production
|
||||
|
@ -107,10 +107,10 @@ EnergyMetricsProviderLinux::Create() {
|
||||
return base::WrapUnique(new EnergyMetricsProviderLinux());
|
||||
}
|
||||
|
||||
absl::optional<EnergyMetricsProvider::EnergyMetrics>
|
||||
std::optional<EnergyMetricsProvider::EnergyMetrics>
|
||||
EnergyMetricsProviderLinux::CaptureMetrics() {
|
||||
if (!Initialize()) {
|
||||
return absl::nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
EnergyMetrics energy_metrics = {0};
|
||||
|
@ -44,7 +44,7 @@ class EnergyMetricsProviderLinux : public EnergyMetricsProvider {
|
||||
~EnergyMetricsProviderLinux() override;
|
||||
|
||||
// EnergyMetricsProvider implementation.
|
||||
absl::optional<EnergyMetrics> CaptureMetrics() override;
|
||||
std::optional<EnergyMetrics> CaptureMetrics() override;
|
||||
|
||||
private:
|
||||
EnergyMetricsProviderLinux();
|
||||
|
@ -65,11 +65,11 @@ std::unique_ptr<EnergyMetricsProviderWin> EnergyMetricsProviderWin::Create() {
|
||||
return base::WrapUnique(new EnergyMetricsProviderWin());
|
||||
}
|
||||
|
||||
absl::optional<EnergyMetricsProvider::EnergyMetrics>
|
||||
std::optional<EnergyMetricsProvider::EnergyMetrics>
|
||||
EnergyMetricsProviderWin::CaptureMetrics() {
|
||||
if (!Initialize()) {
|
||||
handle_.Close();
|
||||
return absl::nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
base::ScopedBlockingCall scoped_blocking_call(FROM_HERE,
|
||||
@ -85,7 +85,7 @@ EnergyMetricsProviderWin::CaptureMetrics() {
|
||||
measurement_data.data(), measurement_data_size_bytes,
|
||||
&bytes_returned, nullptr)) {
|
||||
PLOG(ERROR) << "IOCTL_EMI_GET_MEASUREMENT failed";
|
||||
return absl::nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
CHECK_EQ(bytes_returned, measurement_data_size_bytes);
|
||||
|
||||
|
@ -26,7 +26,7 @@ class EnergyMetricsProviderWin : public EnergyMetricsProvider {
|
||||
~EnergyMetricsProviderWin() override;
|
||||
|
||||
// EnergyMetricsProvider implementation.
|
||||
absl::optional<EnergyMetrics> CaptureMetrics() override;
|
||||
std::optional<EnergyMetrics> CaptureMetrics() override;
|
||||
|
||||
private:
|
||||
EnergyMetricsProviderWin();
|
||||
|
@ -11,9 +11,9 @@
|
||||
#include <IOKit/hidsystem/IOHIDEventSystemClient.h>
|
||||
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
|
||||
#include "base/apple/scoped_cftyperef.h"
|
||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||
|
||||
namespace power_metrics {
|
||||
|
||||
@ -24,8 +24,8 @@ class M1SensorsReader {
|
||||
TemperaturesCelsius(const TemperaturesCelsius&) noexcept;
|
||||
~TemperaturesCelsius();
|
||||
|
||||
absl::optional<double> p_cores;
|
||||
absl::optional<double> e_cores;
|
||||
std::optional<double> p_cores;
|
||||
std::optional<double> e_cores;
|
||||
};
|
||||
|
||||
virtual ~M1SensorsReader();
|
||||
|
@ -32,12 +32,12 @@ namespace power_metrics {
|
||||
|
||||
namespace {
|
||||
|
||||
absl::optional<double> GetEventFloatValue(IOHIDServiceClientRef service,
|
||||
int64_t event_type) {
|
||||
std::optional<double> GetEventFloatValue(IOHIDServiceClientRef service,
|
||||
int64_t event_type) {
|
||||
base::apple::ScopedCFTypeRef<CFTypeRef> event(
|
||||
IOHIDServiceClientCopyEvent(service, event_type, 0, 0));
|
||||
if (!event)
|
||||
return absl::nullopt;
|
||||
return std::nullopt;
|
||||
return IOHIDEventGetFloatValue(event.get(), IOHIDEventFieldBase(event_type));
|
||||
}
|
||||
|
||||
@ -92,7 +92,7 @@ M1SensorsReader::TemperaturesCelsius M1SensorsReader::ReadTemperatures() {
|
||||
}
|
||||
|
||||
if (CFStringHasPrefix(product.get(), CFSTR("pACC MTR Temp Sensor"))) {
|
||||
absl::optional<double> temp =
|
||||
std::optional<double> temp =
|
||||
GetEventFloatValue(service, kIOHIDEventTypeTemperature);
|
||||
if (temp.has_value()) {
|
||||
num_p_core_temp += 1;
|
||||
@ -101,7 +101,7 @@ M1SensorsReader::TemperaturesCelsius M1SensorsReader::ReadTemperatures() {
|
||||
}
|
||||
|
||||
if (CFStringHasPrefix(product.get(), CFSTR("eACC MTR Temp Sensor"))) {
|
||||
absl::optional<double> temp =
|
||||
std::optional<double> temp =
|
||||
GetEventFloatValue(service, kIOHIDEventTypeTemperature);
|
||||
if (temp.has_value()) {
|
||||
num_e_core_temp += 1;
|
||||
|
@ -11,15 +11,15 @@
|
||||
#ifndef COMPONENTS_POWER_METRICS_RESOURCE_COALITION_MAC_H_
|
||||
#define COMPONENTS_POWER_METRICS_RESOURCE_COALITION_MAC_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <memory>
|
||||
|
||||
#include <mach/mach_time.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
|
||||
#include "base/process/process_handle.h"
|
||||
#include "base/time/time.h"
|
||||
#include "components/power_metrics/resource_coalition_internal_types_mac.h"
|
||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||
|
||||
namespace power_metrics {
|
||||
|
||||
@ -27,7 +27,7 @@ struct EnergyImpactCoefficients;
|
||||
|
||||
// Returns the coalition id for the process identified by |pid| or nullopt if
|
||||
// not available.
|
||||
absl::optional<uint64_t> GetProcessCoalitionId(base::ProcessId pid);
|
||||
std::optional<uint64_t> GetProcessCoalitionId(base::ProcessId pid);
|
||||
|
||||
// Returns resource usage data for the coalition identified by |coalition_id|,
|
||||
// or nullptr if not available (e.g. if `coalition_id` is invalid or if the
|
||||
@ -50,7 +50,7 @@ struct CoalitionResourceUsageRate {
|
||||
double byteswritten_per_second;
|
||||
double gpu_time_per_second;
|
||||
// Only makes sense on Intel macs, not computed on M1 macs.
|
||||
absl::optional<double> energy_impact_per_second;
|
||||
std::optional<double> energy_impact_per_second;
|
||||
// Only available on M1 macs as of September 2021.
|
||||
double power_nw;
|
||||
|
||||
@ -59,12 +59,12 @@ struct CoalitionResourceUsageRate {
|
||||
|
||||
// Returns rate of resource usage for a coalition, given the usage at
|
||||
// the beginning and end of an interval and the duration of the interval.
|
||||
absl::optional<CoalitionResourceUsageRate> GetCoalitionResourceUsageRate(
|
||||
std::optional<CoalitionResourceUsageRate> GetCoalitionResourceUsageRate(
|
||||
const coalition_resource_usage& begin,
|
||||
const coalition_resource_usage& end,
|
||||
base::TimeDelta interval_duration,
|
||||
mach_timebase_info_data_t timebase,
|
||||
absl::optional<EnergyImpactCoefficients> energy_impact_coefficients);
|
||||
std::optional<EnergyImpactCoefficients> energy_impact_coefficients);
|
||||
|
||||
} // namespace power_metrics
|
||||
|
||||
|
@ -17,13 +17,13 @@ extern "C" int coalition_info_resource_usage(
|
||||
|
||||
namespace power_metrics {
|
||||
|
||||
absl::optional<uint64_t> GetProcessCoalitionId(base::ProcessId pid) {
|
||||
std::optional<uint64_t> GetProcessCoalitionId(base::ProcessId pid) {
|
||||
proc_pidcoalitioninfo coalition_info = {};
|
||||
int res = proc_pidinfo(pid, PROC_PIDCOALITIONINFO, 0, &coalition_info,
|
||||
sizeof(coalition_info));
|
||||
|
||||
if (res != sizeof(coalition_info))
|
||||
return absl::nullopt;
|
||||
return std::nullopt;
|
||||
|
||||
return coalition_info.coalition_id[COALITION_TYPE_RESOURCE];
|
||||
}
|
||||
@ -140,12 +140,12 @@ coalition_resource_usage GetCoalitionResourceUsageDifference(
|
||||
return ret;
|
||||
}
|
||||
|
||||
absl::optional<CoalitionResourceUsageRate> GetCoalitionResourceUsageRate(
|
||||
std::optional<CoalitionResourceUsageRate> GetCoalitionResourceUsageRate(
|
||||
const coalition_resource_usage& begin,
|
||||
const coalition_resource_usage& end,
|
||||
base::TimeDelta interval_duration,
|
||||
mach_timebase_info_data_t timebase,
|
||||
absl::optional<EnergyImpactCoefficients> energy_impact_coefficients) {
|
||||
std::optional<EnergyImpactCoefficients> energy_impact_coefficients) {
|
||||
// Validate that |end| >= |begin|.
|
||||
bool end_greater_or_equal_begin =
|
||||
std::tie(end.cpu_time, end.interrupt_wakeups, end.platform_idle_wakeups,
|
||||
@ -158,7 +158,7 @@ absl::optional<CoalitionResourceUsageRate> GetCoalitionResourceUsageRate(
|
||||
end_greater_or_equal_begin = false;
|
||||
}
|
||||
if (!end_greater_or_equal_begin)
|
||||
return absl::nullopt;
|
||||
return std::nullopt;
|
||||
|
||||
auto get_rate_per_second = [&interval_duration](uint64_t begin,
|
||||
uint64_t end) -> double {
|
||||
|
@ -4,10 +4,11 @@
|
||||
|
||||
#include "components/power_metrics/resource_coalition_mac.h"
|
||||
|
||||
#include <optional>
|
||||
|
||||
#include "base/rand_util.h"
|
||||
#include "components/power_metrics/energy_impact_mac.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||
|
||||
namespace power_metrics {
|
||||
|
||||
@ -83,7 +84,7 @@ void BurnCPU() {
|
||||
} // namespace
|
||||
|
||||
TEST(ResourceCoalitionMacTest, Busy) {
|
||||
absl::optional<uint64_t> coalition_id =
|
||||
std::optional<uint64_t> coalition_id =
|
||||
GetProcessCoalitionId(base::GetCurrentProcId());
|
||||
ASSERT_TRUE(coalition_id.has_value());
|
||||
|
||||
@ -213,7 +214,7 @@ TEST(ResourceCoalitionMacTest, GetDataRate_NoEnergyImpact_Intel) {
|
||||
GetCoalitionResourceUsageRateTestData(kIntelTimebase);
|
||||
|
||||
auto rate = GetCoalitionResourceUsageRate(
|
||||
*t0_data, *t1_data, kIntervalDuration, kIntelTimebase, absl::nullopt);
|
||||
*t0_data, *t1_data, kIntervalDuration, kIntelTimebase, std::nullopt);
|
||||
ASSERT_TRUE(rate);
|
||||
EXPECT_EQ(kExpectedCPUUsagePerSecondPercent, rate->cpu_time_per_second);
|
||||
EXPECT_EQ(kExpectedInterruptWakeUpPerSecond,
|
||||
@ -240,7 +241,7 @@ TEST(ResourceCoalitionMacTest, GetDataRate_NoEnergyImpact_M1) {
|
||||
GetCoalitionResourceUsageRateTestData(kM1Timebase);
|
||||
|
||||
auto rate = GetCoalitionResourceUsageRate(
|
||||
*t0_data, *t1_data, kIntervalDuration, kM1Timebase, absl::nullopt);
|
||||
*t0_data, *t1_data, kIntervalDuration, kM1Timebase, std::nullopt);
|
||||
ASSERT_TRUE(rate);
|
||||
EXPECT_DOUBLE_EQ(kExpectedCPUUsagePerSecondPercent,
|
||||
rate->cpu_time_per_second);
|
||||
@ -330,7 +331,7 @@ bool DataOverflowInvalidatesDiffImpl(
|
||||
*field_to_overflow = 0;
|
||||
t1->cpu_time_eqos_len = COALITION_NUM_THREAD_QOS_TYPES;
|
||||
return !GetCoalitionResourceUsageRate(*t0, *t1, kIntervalDuration,
|
||||
kIntelTimebase, absl::nullopt)
|
||||
kIntelTimebase, std::nullopt)
|
||||
.has_value();
|
||||
}
|
||||
|
||||
|
@ -12,11 +12,11 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
|
||||
#include "base/containers/flat_map.h"
|
||||
#include "base/mac/scoped_ioobject.h"
|
||||
#include "components/power_metrics/smc_internal_types_mac.h"
|
||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||
|
||||
namespace power_metrics {
|
||||
|
||||
@ -29,7 +29,7 @@ class SMCReader {
|
||||
|
||||
// Returns the value of a key, or nullopt if not available.
|
||||
// Virtual for testing.
|
||||
virtual absl::optional<double> ReadKey(SMCKeyIdentifier identifier);
|
||||
virtual std::optional<double> ReadKey(SMCKeyIdentifier identifier);
|
||||
|
||||
protected:
|
||||
explicit SMCReader(base::mac::ScopedIOObject<io_object_t> connect);
|
||||
@ -44,7 +44,7 @@ class SMCReader {
|
||||
~SMCKey();
|
||||
|
||||
bool Exists() const;
|
||||
absl::optional<double> Read();
|
||||
std::optional<double> Read();
|
||||
|
||||
private:
|
||||
bool CallSMCFunction(uint8_t function, SMCParamStruct* out);
|
||||
|
@ -35,7 +35,7 @@ std::unique_ptr<SMCReader> SMCReader::Create() {
|
||||
|
||||
SMCReader::~SMCReader() = default;
|
||||
|
||||
absl::optional<double> SMCReader::ReadKey(SMCKeyIdentifier identifier) {
|
||||
std::optional<double> SMCReader::ReadKey(SMCKeyIdentifier identifier) {
|
||||
auto it = keys_.find(identifier);
|
||||
if (it == keys_.end()) {
|
||||
auto result = keys_.emplace(identifier, SMCKey(connect_, identifier));
|
||||
@ -63,13 +63,13 @@ bool SMCReader::SMCKey::Exists() const {
|
||||
return key_info_.dataSize > 0;
|
||||
}
|
||||
|
||||
absl::optional<double> SMCReader::SMCKey::Read() {
|
||||
std::optional<double> SMCReader::SMCKey::Read() {
|
||||
if (!Exists())
|
||||
return absl::nullopt;
|
||||
return std::nullopt;
|
||||
|
||||
SMCParamStruct out{};
|
||||
if (!CallSMCFunction(kSMCReadKey, &out))
|
||||
return absl::nullopt;
|
||||
return std::nullopt;
|
||||
switch (key_info_.dataType) {
|
||||
case SMCDataType::flt:
|
||||
return *reinterpret_cast<float*>(out.bytes);
|
||||
@ -80,7 +80,7 @@ absl::optional<double> SMCReader::SMCKey::Read() {
|
||||
case SMCDataType::spa5:
|
||||
return FromSMCFixedPoint(out.bytes, 5);
|
||||
default:
|
||||
return absl::nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,10 +15,10 @@ class FakeProvider : public EnergyMetricsProvider {
|
||||
public:
|
||||
void set_metrics(EnergyMetrics metrics) { metrics_ = metrics; }
|
||||
|
||||
absl::optional<EnergyMetrics> CaptureMetrics() override { return metrics_; }
|
||||
std::optional<EnergyMetrics> CaptureMetrics() override { return metrics_; }
|
||||
|
||||
private:
|
||||
absl::optional<EnergyMetrics> metrics_;
|
||||
std::optional<EnergyMetrics> metrics_;
|
||||
};
|
||||
|
||||
class FakeDelegate : public SystemPowerMonitorDelegate {
|
||||
@ -140,7 +140,7 @@ TEST_F(SystemPowerMonitorHelperTest, MonitorHelperStartStop) {
|
||||
|
||||
TEST_F(SystemPowerMonitorHelperTest, TimerStartFailed_InvalidSample) {
|
||||
// We haven't set metrics for provider, so monitor gets an
|
||||
// absl::nullopt sample at the beginning and it will not start.
|
||||
// std::nullopt sample at the beginning and it will not start.
|
||||
helper()->Start();
|
||||
ASSERT_FALSE(helper()->IsTimerRunningForTesting());
|
||||
}
|
||||
|
@ -86,42 +86,42 @@ bool EquivalenceSource::Initialize(BufferSource* source) {
|
||||
patch::ParseBuffer(source, ©_count_);
|
||||
}
|
||||
|
||||
absl::optional<Equivalence> EquivalenceSource::GetNext() {
|
||||
std::optional<Equivalence> EquivalenceSource::GetNext() {
|
||||
if (src_skip_.empty() || dst_skip_.empty() || copy_count_.empty())
|
||||
return absl::nullopt;
|
||||
return std::nullopt;
|
||||
|
||||
Equivalence equivalence = {};
|
||||
|
||||
uint32_t length = 0;
|
||||
if (!patch::ParseVarUInt<uint32_t>(©_count_, &length))
|
||||
return absl::nullopt;
|
||||
return std::nullopt;
|
||||
equivalence.length = base::strict_cast<offset_t>(length);
|
||||
|
||||
int32_t src_offset_diff = 0; // Intentionally signed.
|
||||
if (!patch::ParseVarInt<int32_t>(&src_skip_, &src_offset_diff))
|
||||
return absl::nullopt;
|
||||
return std::nullopt;
|
||||
base::CheckedNumeric<offset_t> src_offset =
|
||||
previous_src_offset_ + src_offset_diff;
|
||||
if (!src_offset.IsValid())
|
||||
return absl::nullopt;
|
||||
return std::nullopt;
|
||||
|
||||
equivalence.src_offset = src_offset.ValueOrDie();
|
||||
previous_src_offset_ = src_offset + equivalence.length;
|
||||
if (!previous_src_offset_.IsValid())
|
||||
return absl::nullopt;
|
||||
return std::nullopt;
|
||||
|
||||
uint32_t dst_offset_diff = 0; // Intentionally unsigned.
|
||||
if (!patch::ParseVarUInt<uint32_t>(&dst_skip_, &dst_offset_diff))
|
||||
return absl::nullopt;
|
||||
return std::nullopt;
|
||||
base::CheckedNumeric<offset_t> dst_offset =
|
||||
previous_dst_offset_ + dst_offset_diff;
|
||||
if (!dst_offset.IsValid())
|
||||
return absl::nullopt;
|
||||
return std::nullopt;
|
||||
|
||||
equivalence.dst_offset = dst_offset.ValueOrDie();
|
||||
previous_dst_offset_ = equivalence.dst_offset + equivalence.length;
|
||||
if (!previous_dst_offset_.IsValid())
|
||||
return absl::nullopt;
|
||||
return std::nullopt;
|
||||
|
||||
// Caveat: |equivalence| is assumed to be safe only once the
|
||||
// ValidateEquivalencesAndExtraData() method has returned true. Prior to this
|
||||
@ -139,10 +139,10 @@ bool ExtraDataSource::Initialize(BufferSource* source) {
|
||||
return patch::ParseBuffer(source, &extra_data_);
|
||||
}
|
||||
|
||||
absl::optional<ConstBufferView> ExtraDataSource::GetNext(offset_t size) {
|
||||
std::optional<ConstBufferView> ExtraDataSource::GetNext(offset_t size) {
|
||||
ConstBufferView buffer;
|
||||
if (!extra_data_.GetRegion(size, &buffer))
|
||||
return absl::nullopt;
|
||||
return std::nullopt;
|
||||
// |buffer| is assumed to always be safe/valid.
|
||||
return buffer;
|
||||
}
|
||||
@ -158,32 +158,32 @@ bool RawDeltaSource::Initialize(BufferSource* source) {
|
||||
patch::ParseBuffer(source, &raw_delta_diff_);
|
||||
}
|
||||
|
||||
absl::optional<RawDeltaUnit> RawDeltaSource::GetNext() {
|
||||
std::optional<RawDeltaUnit> RawDeltaSource::GetNext() {
|
||||
if (raw_delta_skip_.empty() || raw_delta_diff_.empty())
|
||||
return absl::nullopt;
|
||||
return std::nullopt;
|
||||
|
||||
RawDeltaUnit raw_delta = {};
|
||||
uint32_t copy_offset_diff = 0;
|
||||
if (!patch::ParseVarUInt<uint32_t>(&raw_delta_skip_, ©_offset_diff))
|
||||
return absl::nullopt;
|
||||
return std::nullopt;
|
||||
base::CheckedNumeric<offset_t> copy_offset =
|
||||
copy_offset_diff + copy_offset_compensation_;
|
||||
if (!copy_offset.IsValid())
|
||||
return absl::nullopt;
|
||||
return std::nullopt;
|
||||
raw_delta.copy_offset = copy_offset.ValueOrDie();
|
||||
|
||||
if (!raw_delta_diff_.GetValue<int8_t>(&raw_delta.diff))
|
||||
return absl::nullopt;
|
||||
return std::nullopt;
|
||||
|
||||
// A 0 value for a delta.diff is considered invalid since it has no meaning.
|
||||
if (!raw_delta.diff)
|
||||
return absl::nullopt;
|
||||
return std::nullopt;
|
||||
|
||||
// We keep track of the compensation needed for next offset, taking into
|
||||
// account delta encoding and bias of -1.
|
||||
copy_offset_compensation_ = copy_offset + 1;
|
||||
if (!copy_offset_compensation_.IsValid())
|
||||
return absl::nullopt;
|
||||
return std::nullopt;
|
||||
// |raw_delta| is assumed to always be safe/valid.
|
||||
return raw_delta;
|
||||
}
|
||||
@ -199,12 +199,12 @@ bool ReferenceDeltaSource::Initialize(BufferSource* source) {
|
||||
return patch::ParseBuffer(source, &source_);
|
||||
}
|
||||
|
||||
absl::optional<int32_t> ReferenceDeltaSource::GetNext() {
|
||||
std::optional<int32_t> ReferenceDeltaSource::GetNext() {
|
||||
if (source_.empty())
|
||||
return absl::nullopt;
|
||||
return std::nullopt;
|
||||
int32_t ref_delta = 0;
|
||||
if (!patch::ParseVarInt<int32_t>(&source_, &ref_delta))
|
||||
return absl::nullopt;
|
||||
return std::nullopt;
|
||||
// |ref_delta| is assumed to always be safe/valid.
|
||||
return ref_delta;
|
||||
}
|
||||
@ -219,22 +219,22 @@ bool TargetSource::Initialize(BufferSource* source) {
|
||||
return patch::ParseBuffer(source, &extra_targets_);
|
||||
}
|
||||
|
||||
absl::optional<offset_t> TargetSource::GetNext() {
|
||||
std::optional<offset_t> TargetSource::GetNext() {
|
||||
if (extra_targets_.empty())
|
||||
return absl::nullopt;
|
||||
return std::nullopt;
|
||||
|
||||
uint32_t target_diff = 0;
|
||||
if (!patch::ParseVarUInt<uint32_t>(&extra_targets_, &target_diff))
|
||||
return absl::nullopt;
|
||||
return std::nullopt;
|
||||
base::CheckedNumeric<offset_t> target = target_diff + target_compensation_;
|
||||
if (!target.IsValid())
|
||||
return absl::nullopt;
|
||||
return std::nullopt;
|
||||
|
||||
// We keep track of the compensation needed for next target, taking into
|
||||
// account delta encoding and bias of -1.
|
||||
target_compensation_ = target + 1;
|
||||
if (!target_compensation_.IsValid())
|
||||
return absl::nullopt;
|
||||
return std::nullopt;
|
||||
// Caveat: |target| will be a valid offset_t, but it's up to the caller to
|
||||
// check whether it's a valid offset for an image.
|
||||
return offset_t(target.ValueOrDie());
|
||||
@ -320,12 +320,12 @@ bool PatchElementReader::ValidateEquivalencesAndExtraData() {
|
||||
|
||||
/******** EnsemblePatchReader ********/
|
||||
|
||||
absl::optional<EnsemblePatchReader> EnsemblePatchReader::Create(
|
||||
std::optional<EnsemblePatchReader> EnsemblePatchReader::Create(
|
||||
ConstBufferView buffer) {
|
||||
BufferSource source(buffer);
|
||||
EnsemblePatchReader patch;
|
||||
if (!patch.Initialize(&source))
|
||||
return absl::nullopt;
|
||||
return std::nullopt;
|
||||
return patch;
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#include <map>
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
|
||||
#include "base/debug/stack_trace.h"
|
||||
@ -18,7 +19,6 @@
|
||||
#include "components/zucchini/buffer_view.h"
|
||||
#include "components/zucchini/image_utils.h"
|
||||
#include "components/zucchini/patch_utils.h"
|
||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||
|
||||
namespace zucchini {
|
||||
|
||||
@ -75,8 +75,8 @@ bool ParseVarInt(BufferSource* source, T* value) {
|
||||
// - bool Initialize(BufferSource* source): Consumes data from BufferSource and
|
||||
// initializes internal states. Returns true if successful, and false
|
||||
// otherwise (|source| may be partially consumed).
|
||||
// - absl::optional<MAIN_TYPE> GetNext(OPT_PARAMS): Decodes consumed data and
|
||||
// returns the next item as absl::optional (returns absl::nullopt on failure).
|
||||
// - std::optional<MAIN_TYPE> GetNext(OPT_PARAMS): Decodes consumed data and
|
||||
// returns the next item as std::optional (returns std::nullopt on failure).
|
||||
// - bool Done() const: Returns true if no more items remain; otherwise false.
|
||||
//
|
||||
// Usage of *Source instances don't mix, and GetNext() have dissimilar
|
||||
@ -92,7 +92,7 @@ class EquivalenceSource {
|
||||
|
||||
// Core functions.
|
||||
bool Initialize(BufferSource* source);
|
||||
absl::optional<Equivalence> GetNext();
|
||||
std::optional<Equivalence> GetNext();
|
||||
bool Done() const {
|
||||
return src_skip_.empty() && dst_skip_.empty() && copy_count_.empty();
|
||||
}
|
||||
@ -121,7 +121,7 @@ class ExtraDataSource {
|
||||
// Core functions.
|
||||
bool Initialize(BufferSource* source);
|
||||
// |size| is the size in bytes of the buffer requested.
|
||||
absl::optional<ConstBufferView> GetNext(offset_t size);
|
||||
std::optional<ConstBufferView> GetNext(offset_t size);
|
||||
bool Done() const { return extra_data_.empty(); }
|
||||
|
||||
// Accessors for unittest.
|
||||
@ -140,7 +140,7 @@ class RawDeltaSource {
|
||||
|
||||
// Core functions.
|
||||
bool Initialize(BufferSource* source);
|
||||
absl::optional<RawDeltaUnit> GetNext();
|
||||
std::optional<RawDeltaUnit> GetNext();
|
||||
bool Done() const {
|
||||
return raw_delta_skip_.empty() && raw_delta_diff_.empty();
|
||||
}
|
||||
@ -165,7 +165,7 @@ class ReferenceDeltaSource {
|
||||
|
||||
// Core functions.
|
||||
bool Initialize(BufferSource* source);
|
||||
absl::optional<int32_t> GetNext();
|
||||
std::optional<int32_t> GetNext();
|
||||
bool Done() const { return source_.empty(); }
|
||||
|
||||
// Accessors for unittest.
|
||||
@ -184,7 +184,7 @@ class TargetSource {
|
||||
|
||||
// Core functions.
|
||||
bool Initialize(BufferSource* source);
|
||||
absl::optional<offset_t> GetNext();
|
||||
std::optional<offset_t> GetNext();
|
||||
bool Done() const { return extra_targets_.empty(); }
|
||||
|
||||
// Accessors for unittest.
|
||||
@ -254,8 +254,8 @@ class PatchElementReader {
|
||||
class EnsemblePatchReader {
|
||||
public:
|
||||
// If data read from |buffer| is well-formed, initializes and returns
|
||||
// an instance of EnsemblePatchReader. Otherwise returns absl::nullopt.
|
||||
static absl::optional<EnsemblePatchReader> Create(ConstBufferView buffer);
|
||||
// an instance of EnsemblePatchReader. Otherwise returns std::nullopt.
|
||||
static std::optional<EnsemblePatchReader> Create(ConstBufferView buffer);
|
||||
|
||||
EnsemblePatchReader();
|
||||
EnsemblePatchReader(EnsemblePatchReader&&);
|
||||
|
@ -5,9 +5,10 @@
|
||||
#ifndef THIRD_PARTY_BLINK_PUBLIC_COMMON_FENCED_FRAME_FENCED_FRAME_UTILS_H_
|
||||
#define THIRD_PARTY_BLINK_PUBLIC_COMMON_FENCED_FRAME_FENCED_FRAME_UTILS_H_
|
||||
|
||||
#include <optional>
|
||||
|
||||
#include "services/network/public/cpp/web_sandbox_flags.h"
|
||||
#include "services/network/public/mojom/web_sandbox_flags.mojom-shared.h"
|
||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||
#include "third_party/blink/public/common/common_export.h"
|
||||
|
||||
class GURL;
|
||||
|
@ -368,7 +368,7 @@ TEST(BlinkStorageKeyTest, FromWireReturnValue) {
|
||||
|
||||
const struct TestCase {
|
||||
scoped_refptr<const SecurityOrigin> origin;
|
||||
// RAW_PTR_EXCLUSION: Can't wrap `absl::nullopt` in `raw_ref`. Also, these
|
||||
// RAW_PTR_EXCLUSION: Can't wrap `std::nullopt` in `raw_ref`. Also, these
|
||||
// are test-only and rewriting would add a ton of code churn.
|
||||
RAW_PTR_EXCLUSION const BlinkSchemefulSite& top_level_site;
|
||||
RAW_PTR_EXCLUSION const BlinkSchemefulSite&
|
||||
|
Reference in New Issue
Block a user