0

Remove uses of implicit conversion of ScopedTypeRef in /components

Implicit unwrapping of a scoper to its underlying pointer is dangerous
and that capability is being removed. This converts uses of implicit
conversion to be explicit in preparation for its removal, and performs
other cleanup and modernization.

Bug: 1495439
Change-Id: I4d64f17d3442682281e61030a33cd55b5a493031
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4979673
Reviewed-by: Sylvain Defresne <sdefresne@chromium.org>
Commit-Queue: Avi Drissman <avi@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1217168}
This commit is contained in:
Avi Drissman
2023-10-30 20:24:38 +00:00
committed by Chromium LUCI CQ
parent 6ca8326972
commit a84d64e3c8
20 changed files with 130 additions and 122 deletions

@ -184,12 +184,12 @@ absl::optional<std::string> GetBoardIdForThisMachine() {
// coefficients file for the local computer.
base::apple::ScopedCFTypeRef<CFDataRef> board_id_data(
base::apple::CFCast<CFDataRef>(IORegistryEntryCreateCFProperty(
platform_expert, CFSTR("board-id"), kCFAllocatorDefault, 0)));
platform_expert.get(), CFSTR("board-id"), kCFAllocatorDefault, 0)));
if (!board_id_data)
return absl::nullopt;
return reinterpret_cast<const char*>(CFDataGetBytePtr(board_id_data));
return reinterpret_cast<const char*>(CFDataGetBytePtr(board_id_data.get()));
}
} // namespace internal

@ -38,7 +38,7 @@ absl::optional<double> GetEventFloatValue(IOHIDServiceClientRef service,
IOHIDServiceClientCopyEvent(service, event_type, 0, 0));
if (!event)
return absl::nullopt;
return IOHIDEventGetFloatValue(event, IOHIDEventFieldBase(event_type));
return IOHIDEventGetFloatValue(event.get(), IOHIDEventFieldBase(event_type));
}
} // namespace
@ -55,14 +55,16 @@ std::unique_ptr<M1SensorsReader> M1SensorsReader::Create() {
base::apple::ScopedCFTypeRef<IOHIDEventSystemClientRef> system(
IOHIDEventSystemClientCreate(kCFAllocatorDefault));
if (system == nil)
if (!system) {
return nullptr;
}
NSDictionary* filter = @{
@kIOHIDPrimaryUsagePageKey : @(kHIDPage_AppleVendor),
@kIOHIDPrimaryUsageKey : @(kHIDUsage_AppleVendor_TemperatureSensor),
};
IOHIDEventSystemClientSetMatching(system, base::apple::NSToCFPtrCast(filter));
IOHIDEventSystemClientSetMatching(system.get(),
base::apple::NSToCFPtrCast(filter));
return base::WrapUnique(new M1SensorsReader(std::move(system)));
}
@ -78,18 +80,18 @@ M1SensorsReader::TemperaturesCelsius M1SensorsReader::ReadTemperatures() {
double sum_p_core_temp = 0;
double sum_e_core_temp = 0;
for (CFIndex i = 0; i < CFArrayGetCount(services); ++i) {
for (CFIndex i = 0; i < CFArrayGetCount(services.get()); ++i) {
IOHIDServiceClientRef service =
(IOHIDServiceClientRef)CFArrayGetValueAtIndex(services, i);
(IOHIDServiceClientRef)CFArrayGetValueAtIndex(services.get(), i);
base::apple::ScopedCFTypeRef<CFStringRef> product(
base::apple::CFCast<CFStringRef>(
IOHIDServiceClientCopyProperty(service, CFSTR(kIOHIDProductKey))));
if (product == nil) {
if (!product) {
continue;
}
if (CFStringHasPrefix(product, CFSTR("pACC MTR Temp Sensor"))) {
if (CFStringHasPrefix(product.get(), CFSTR("pACC MTR Temp Sensor"))) {
absl::optional<double> temp =
GetEventFloatValue(service, kIOHIDEventTypeTemperature);
if (temp.has_value()) {
@ -98,7 +100,7 @@ M1SensorsReader::TemperaturesCelsius M1SensorsReader::ReadTemperatures() {
}
}
if (CFStringHasPrefix(product, CFSTR("eACC MTR Temp Sensor"))) {
if (CFStringHasPrefix(product.get(), CFSTR("eACC MTR Temp Sensor"))) {
absl::optional<double> temp =
GetEventFloatValue(service, kIOHIDEventTypeTemperature);
if (temp.has_value()) {

@ -25,7 +25,7 @@ std::unique_ptr<SMCReader> SMCReader::Create() {
IOServiceGetMatchingService(kIOMasterPortDefault,
IOServiceMatching("AppleSMC")));
base::mac::ScopedIOObject<io_object_t> connect;
if (IOServiceOpen(smc_service, mach_task_self(), 1,
if (IOServiceOpen(smc_service.get(), mach_task_self(), 1,
connect.InitializeInto()) != kIOReturnSuccess) {
return nullptr;
}
@ -92,8 +92,8 @@ bool SMCReader::SMCKey::CallSMCFunction(uint8_t function, SMCParamStruct* out) {
// `kSMCUserClientClose` doesn't seem to affect behavior. Consider removing
// them.
if (IOConnectCallMethod(connect_, kSMCUserClientOpen, nullptr, 0, nullptr, 0,
nullptr, nullptr, nullptr, nullptr)) {
if (IOConnectCallMethod(connect_.get(), kSMCUserClientOpen, nullptr, 0,
nullptr, 0, nullptr, nullptr, nullptr, nullptr)) {
connect_.reset();
return false;
}
@ -105,11 +105,11 @@ bool SMCReader::SMCKey::CallSMCFunction(uint8_t function, SMCParamStruct* out) {
size_t out_size = sizeof(*out);
const bool success =
IOConnectCallStructMethod(connect_, kSMCHandleYPCEvent, &in, sizeof(in),
out, &out_size) == kIOReturnSuccess;
IOConnectCallStructMethod(connect_.get(), kSMCHandleYPCEvent, &in,
sizeof(in), out, &out_size) == kIOReturnSuccess;
if (IOConnectCallMethod(connect_, kSMCUserClientClose, nullptr, 0, nullptr, 0,
nullptr, nullptr, nullptr, nullptr)) {
if (IOConnectCallMethod(connect_.get(), kSMCUserClientClose, nullptr, 0,
nullptr, 0, nullptr, nullptr, nullptr, nullptr)) {
connect_.reset();
}