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:

committed by
Chromium LUCI CQ

parent
6ca8326972
commit
a84d64e3c8
components
crash
core
common
device_signals
core
system_signals
memory_pressure
metal_util
metrics
policy
core
power_metrics
remote_cocoa
app_shim
services
storage_monitor
sync_device_info
viz
service
display_embedder
wifi
@ -54,44 +54,45 @@ namespace {
|
||||
// call in |ZombieDealloc()|.
|
||||
TEST(ObjcZombieTest, CxxDestructors) {
|
||||
base::apple::scoped_nsobject<id> anObject([[NSObject alloc] init]);
|
||||
EXPECT_EQ(1u, [anObject retainCount]);
|
||||
EXPECT_EQ(1u, [anObject.get() retainCount]);
|
||||
|
||||
ASSERT_TRUE(ObjcEvilDoers::ZombieEnable(YES, 100));
|
||||
|
||||
base::apple::scoped_nsobject<ZombieCxxDestructTest> soonInfected(
|
||||
[[ZombieCxxDestructTest alloc] initWith:anObject]);
|
||||
EXPECT_EQ(2u, [anObject retainCount]);
|
||||
[[ZombieCxxDestructTest alloc] initWith:anObject.get()]);
|
||||
EXPECT_EQ(2u, [anObject.get() retainCount]);
|
||||
|
||||
// When |soonInfected| becomes a zombie, the C++ destructors should
|
||||
// run and release a reference to |anObject|.
|
||||
soonInfected.reset();
|
||||
EXPECT_EQ(1u, [anObject retainCount]);
|
||||
EXPECT_EQ(1u, [anObject.get() retainCount]);
|
||||
|
||||
// The local reference should remain (C++ destructors aren't re-run).
|
||||
ObjcEvilDoers::ZombieDisable();
|
||||
EXPECT_EQ(1u, [anObject retainCount]);
|
||||
EXPECT_EQ(1u, [anObject.get() retainCount]);
|
||||
}
|
||||
|
||||
// Verify that the associated objects are released when the object is
|
||||
// released.
|
||||
TEST(ObjcZombieTest, AssociatedObjectsReleased) {
|
||||
base::apple::scoped_nsobject<id> anObject([[NSObject alloc] init]);
|
||||
EXPECT_EQ(1u, [anObject retainCount]);
|
||||
EXPECT_EQ(1u, [anObject.get() retainCount]);
|
||||
|
||||
ASSERT_TRUE(ObjcEvilDoers::ZombieEnable(YES, 100));
|
||||
|
||||
base::apple::scoped_nsobject<ZombieAssociatedObjectTest> soonInfected(
|
||||
[[ZombieAssociatedObjectTest alloc] initWithAssociatedObject:anObject]);
|
||||
EXPECT_EQ(2u, [anObject retainCount]);
|
||||
[[ZombieAssociatedObjectTest alloc]
|
||||
initWithAssociatedObject:anObject.get()]);
|
||||
EXPECT_EQ(2u, [anObject.get() retainCount]);
|
||||
|
||||
// When |soonInfected| becomes a zombie, the associated object
|
||||
// should be released.
|
||||
soonInfected.reset();
|
||||
EXPECT_EQ(1u, [anObject retainCount]);
|
||||
EXPECT_EQ(1u, [anObject.get() retainCount]);
|
||||
|
||||
// The local reference should remain (associated objects not re-released).
|
||||
ObjcEvilDoers::ZombieDisable();
|
||||
EXPECT_EQ(1u, [anObject retainCount]);
|
||||
EXPECT_EQ(1u, [anObject.get() retainCount]);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
@ -95,21 +95,21 @@ MacPlatformDelegate::GetSigningCertificatesPublicKeys(
|
||||
base::apple::ScopedCFTypeRef<CFURLRef> file_url =
|
||||
base::apple::FilePathToCFURL(file_path);
|
||||
base::apple::ScopedCFTypeRef<SecStaticCodeRef> file_code;
|
||||
if (SecStaticCodeCreateWithPath(file_url, kSecCSDefaultFlags,
|
||||
if (SecStaticCodeCreateWithPath(file_url.get(), kSecCSDefaultFlags,
|
||||
file_code.InitializeInto()) !=
|
||||
errSecSuccess) {
|
||||
return public_keys;
|
||||
}
|
||||
|
||||
base::apple::ScopedCFTypeRef<CFDictionaryRef> signing_information;
|
||||
if (SecCodeCopySigningInformation(file_code, kSecCSSigningInformation,
|
||||
if (SecCodeCopySigningInformation(file_code.get(), kSecCSSigningInformation,
|
||||
signing_information.InitializeInto()) !=
|
||||
errSecSuccess) {
|
||||
return public_keys;
|
||||
}
|
||||
|
||||
CFArrayRef cert_chain = base::apple::GetValueFromDictionary<CFArrayRef>(
|
||||
signing_information, kSecCodeInfoCertificates);
|
||||
signing_information.get(), kSecCodeInfoCertificates);
|
||||
if (!cert_chain) {
|
||||
return public_keys;
|
||||
}
|
||||
@ -132,8 +132,8 @@ MacPlatformDelegate::GetSigningCertificatesPublicKeys(
|
||||
base::StringPiece spki_bytes;
|
||||
if (!net::asn1::ExtractSPKIFromDERCert(
|
||||
base::StringPiece(
|
||||
reinterpret_cast<const char*>(CFDataGetBytePtr(der_data)),
|
||||
CFDataGetLength(der_data)),
|
||||
reinterpret_cast<const char*>(CFDataGetBytePtr(der_data.get())),
|
||||
CFDataGetLength(der_data.get())),
|
||||
&spki_bytes)) {
|
||||
return public_keys;
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ SystemMemoryPressureEvaluator::SystemMemoryPressureEvaluator(
|
||||
|
||||
// Attach an event handler to the memory pressure event source.
|
||||
if (memory_level_event_source_.get()) {
|
||||
dispatch_source_set_event_handler(memory_level_event_source_, ^{
|
||||
dispatch_source_set_event_handler(memory_level_event_source_.get(), ^{
|
||||
task_runner->PostTask(
|
||||
FROM_HERE,
|
||||
base::BindRepeating(
|
||||
@ -68,14 +68,14 @@ SystemMemoryPressureEvaluator::SystemMemoryPressureEvaluator(
|
||||
});
|
||||
|
||||
// Start monitoring the event source.
|
||||
dispatch_resume(memory_level_event_source_);
|
||||
dispatch_resume(memory_level_event_source_.get());
|
||||
}
|
||||
}
|
||||
|
||||
SystemMemoryPressureEvaluator::~SystemMemoryPressureEvaluator() {
|
||||
// Remove the memory pressure event source.
|
||||
if (memory_level_event_source_.get()) {
|
||||
dispatch_source_cancel(memory_level_event_source_);
|
||||
dispatch_source_cancel(memory_level_event_source_.get());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -227,7 +227,7 @@ id<MTLRenderPipelineState> CreateRenderPipelineState(id<MTLDevice> device) {
|
||||
self.pixelFormat = MTLPixelFormatRGBA16Float;
|
||||
base::apple::ScopedCFTypeRef<CGColorSpaceRef> colorSpace(
|
||||
CGColorSpaceCreateWithName(kCGColorSpaceExtendedLinearSRGB));
|
||||
self.colorspace = colorSpace;
|
||||
self.colorspace = colorSpace.get();
|
||||
}
|
||||
return self;
|
||||
}
|
||||
@ -257,9 +257,9 @@ id<MTLRenderPipelineState> CreateRenderPipelineState(id<MTLDevice> device) {
|
||||
gfx::GenerateContentLightLevelInfo(hdrMetadata);
|
||||
edrMetadata = [CAEDRMetadata
|
||||
HDR10MetadataWithDisplayInfo:base::apple::CFToNSPtrCast(
|
||||
display_info)
|
||||
display_info.get())
|
||||
contentInfo:base::apple::CFToNSPtrCast(
|
||||
content_info)
|
||||
content_info.get())
|
||||
opticalOutputScale:100];
|
||||
break;
|
||||
}
|
||||
|
@ -40,22 +40,23 @@ bool DriveMetricsProvider::HasSeekPenalty(const base::FilePath& path,
|
||||
if (!session)
|
||||
return false;
|
||||
|
||||
base::apple::ScopedCFTypeRef<DADiskRef> disk(
|
||||
DADiskCreateFromBSDName(kCFAllocatorDefault, session, bsd_name.c_str()));
|
||||
base::apple::ScopedCFTypeRef<DADiskRef> disk(DADiskCreateFromBSDName(
|
||||
kCFAllocatorDefault, session.get(), bsd_name.c_str()));
|
||||
if (!disk)
|
||||
return false;
|
||||
|
||||
base::mac::ScopedIOObject<io_object_t> io_media(DADiskCopyIOMedia(disk));
|
||||
base::mac::ScopedIOObject<io_object_t> io_media(
|
||||
DADiskCopyIOMedia(disk.get()));
|
||||
base::apple::ScopedCFTypeRef<CFDictionaryRef> characteristics(
|
||||
static_cast<CFDictionaryRef>(IORegistryEntrySearchCFProperty(
|
||||
io_media, kIOServicePlane, CFSTR(kIOPropertyDeviceCharacteristicsKey),
|
||||
kCFAllocatorDefault,
|
||||
io_media.get(), kIOServicePlane,
|
||||
CFSTR(kIOPropertyDeviceCharacteristicsKey), kCFAllocatorDefault,
|
||||
kIORegistryIterateRecursively | kIORegistryIterateParents)));
|
||||
if (!characteristics)
|
||||
return false;
|
||||
|
||||
CFStringRef type_ref = base::apple::GetValueFromDictionary<CFStringRef>(
|
||||
characteristics, CFSTR(kIOPropertyMediumTypeKey));
|
||||
characteristics.get(), CFSTR(kIOPropertyMediumTypeKey));
|
||||
if (!type_ref)
|
||||
return false;
|
||||
|
||||
|
@ -64,7 +64,7 @@ TEST(PolicyMacUtilTest, ValueToPropertyRoundTrip) {
|
||||
base::apple::ScopedCFTypeRef<CFPropertyListRef> property(
|
||||
ValueToProperty(root_val));
|
||||
ASSERT_TRUE(property);
|
||||
std::unique_ptr<base::Value> value = PropertyToValue(property);
|
||||
std::unique_ptr<base::Value> value = PropertyToValue(property.get());
|
||||
ASSERT_TRUE(value);
|
||||
EXPECT_EQ(root_val, *value);
|
||||
}
|
||||
|
@ -100,7 +100,7 @@ void PolicyLoaderMac::InitOnBackgroundThread() {
|
||||
}
|
||||
|
||||
PolicyBundle PolicyLoaderMac::Load() {
|
||||
preferences_->AppSynchronize(application_id_);
|
||||
preferences_->AppSynchronize(application_id_.get());
|
||||
PolicyBundle bundle;
|
||||
|
||||
// Load Chrome's policy.
|
||||
@ -114,19 +114,20 @@ PolicyBundle PolicyLoaderMac::Load() {
|
||||
base::apple::ScopedCFTypeRef<CFStringRef> name(
|
||||
base::SysUTF8ToCFStringRef(it.key()));
|
||||
base::apple::ScopedCFTypeRef<CFPropertyListRef> value(
|
||||
preferences_->CopyAppValue(name, application_id_));
|
||||
preferences_->CopyAppValue(name.get(), application_id_.get()));
|
||||
if (!value)
|
||||
continue;
|
||||
bool forced = preferences_->AppValueIsForced(name, application_id_);
|
||||
bool forced =
|
||||
preferences_->AppValueIsForced(name.get(), application_id_.get());
|
||||
PolicyLevel level =
|
||||
forced ? POLICY_LEVEL_MANDATORY : POLICY_LEVEL_RECOMMENDED;
|
||||
PolicyScope scope = POLICY_SCOPE_USER;
|
||||
if (forced) {
|
||||
scope = preferences_->IsManagedPolicyAvailableForMachineScope(name)
|
||||
scope = preferences_->IsManagedPolicyAvailableForMachineScope(name.get())
|
||||
? POLICY_SCOPE_MACHINE
|
||||
: POLICY_SCOPE_USER;
|
||||
}
|
||||
std::unique_ptr<base::Value> policy = PropertyToValue(value);
|
||||
std::unique_ptr<base::Value> policy = PropertyToValue(value.get());
|
||||
if (policy) {
|
||||
chrome_policy.Set(it.key(), level, scope, POLICY_SOURCE_PLATFORM,
|
||||
std::move(*policy), nullptr);
|
||||
@ -178,7 +179,7 @@ base::FilePath PolicyLoaderMac::GetManagedPolicyPath(CFStringRef bundle_id) {
|
||||
void PolicyLoaderMac::LoadPolicyForDomain(PolicyDomain domain,
|
||||
const std::string& domain_name,
|
||||
PolicyBundle* bundle) {
|
||||
std::string id_prefix(base::SysCFStringRefToUTF8(application_id_));
|
||||
std::string id_prefix(base::SysCFStringRefToUTF8(application_id_.get()));
|
||||
id_prefix.append(".").append(domain_name).append(".");
|
||||
|
||||
const ComponentMap* components = schema_map()->GetComponents(domain);
|
||||
@ -206,26 +207,28 @@ void PolicyLoaderMac::LoadPolicyForComponent(
|
||||
|
||||
base::apple::ScopedCFTypeRef<CFStringRef> bundle_id =
|
||||
base::SysUTF8ToCFStringRef(bundle_id_string);
|
||||
preferences_->AppSynchronize(bundle_id);
|
||||
preferences_->AppSynchronize(bundle_id.get());
|
||||
|
||||
for (Schema::Iterator it = schema.GetPropertiesIterator(); !it.IsAtEnd();
|
||||
it.Advance()) {
|
||||
base::apple::ScopedCFTypeRef<CFStringRef> pref_name =
|
||||
base::SysUTF8ToCFStringRef(it.key());
|
||||
base::apple::ScopedCFTypeRef<CFPropertyListRef> value(
|
||||
preferences_->CopyAppValue(pref_name, bundle_id));
|
||||
preferences_->CopyAppValue(pref_name.get(), bundle_id.get()));
|
||||
if (!value)
|
||||
continue;
|
||||
bool forced = preferences_->AppValueIsForced(pref_name, bundle_id);
|
||||
bool forced =
|
||||
preferences_->AppValueIsForced(pref_name.get(), bundle_id.get());
|
||||
PolicyLevel level =
|
||||
forced ? POLICY_LEVEL_MANDATORY : POLICY_LEVEL_RECOMMENDED;
|
||||
PolicyScope scope = POLICY_SCOPE_USER;
|
||||
if (forced) {
|
||||
scope = preferences_->IsManagedPolicyAvailableForMachineScope(pref_name)
|
||||
? POLICY_SCOPE_MACHINE
|
||||
: POLICY_SCOPE_USER;
|
||||
scope =
|
||||
preferences_->IsManagedPolicyAvailableForMachineScope(pref_name.get())
|
||||
? POLICY_SCOPE_MACHINE
|
||||
: POLICY_SCOPE_USER;
|
||||
}
|
||||
std::unique_ptr<base::Value> policy_value = PropertyToValue(value);
|
||||
std::unique_ptr<base::Value> policy_value = PropertyToValue(value.get());
|
||||
if (policy_value) {
|
||||
policy->Set(it.key(), level, scope, POLICY_SOURCE_PLATFORM,
|
||||
std::move(*policy_value), nullptr);
|
||||
|
@ -90,7 +90,8 @@ void TestHarness::InstallStringPolicy(const std::string& policy_name,
|
||||
const std::string& policy_value) {
|
||||
ScopedCFTypeRef<CFStringRef> name(base::SysUTF8ToCFStringRef(policy_name));
|
||||
ScopedCFTypeRef<CFStringRef> value(base::SysUTF8ToCFStringRef(policy_value));
|
||||
prefs_->AddTestItem(name, value, /*is_forced=*/true, /*is_machine=*/true);
|
||||
prefs_->AddTestItem(name.get(), value.get(), /*is_forced=*/true,
|
||||
/*is_machine=*/true);
|
||||
}
|
||||
|
||||
void TestHarness::InstallIntegerPolicy(const std::string& policy_name,
|
||||
@ -98,13 +99,15 @@ void TestHarness::InstallIntegerPolicy(const std::string& policy_name,
|
||||
ScopedCFTypeRef<CFStringRef> name(base::SysUTF8ToCFStringRef(policy_name));
|
||||
ScopedCFTypeRef<CFNumberRef> value(
|
||||
CFNumberCreate(nullptr, kCFNumberIntType, &policy_value));
|
||||
prefs_->AddTestItem(name, value, /*is_forced=*/true, /*is_machine=*/true);
|
||||
prefs_->AddTestItem(name.get(), value.get(), /*is_forced=*/true,
|
||||
/*is_machine=*/true);
|
||||
}
|
||||
|
||||
void TestHarness::InstallBooleanPolicy(const std::string& policy_name,
|
||||
bool policy_value) {
|
||||
ScopedCFTypeRef<CFStringRef> name(base::SysUTF8ToCFStringRef(policy_name));
|
||||
prefs_->AddTestItem(name, policy_value ? kCFBooleanTrue : kCFBooleanFalse,
|
||||
prefs_->AddTestItem(name.get(),
|
||||
policy_value ? kCFBooleanTrue : kCFBooleanFalse,
|
||||
/*is_forced=*/true, /*is_machine=*/true);
|
||||
}
|
||||
|
||||
@ -115,7 +118,8 @@ void TestHarness::InstallStringListPolicy(
|
||||
ScopedCFTypeRef<CFPropertyListRef> array(
|
||||
ValueToProperty(base::Value(policy_value.Clone())));
|
||||
ASSERT_TRUE(array);
|
||||
prefs_->AddTestItem(name, array, /*is_forced=*/true, /*is_machine=*/true);
|
||||
prefs_->AddTestItem(name.get(), array.get(), /*is_forced=*/true,
|
||||
/*is_machine=*/true);
|
||||
}
|
||||
|
||||
void TestHarness::InstallDictionaryPolicy(
|
||||
@ -125,7 +129,8 @@ void TestHarness::InstallDictionaryPolicy(
|
||||
ScopedCFTypeRef<CFPropertyListRef> dict(
|
||||
ValueToProperty(base::Value(policy_value.Clone())));
|
||||
ASSERT_TRUE(dict);
|
||||
prefs_->AddTestItem(name, dict, /*is_forced=*/true, /*is_machine=*/true);
|
||||
prefs_->AddTestItem(name.get(), dict.get(), /*is_forced=*/true,
|
||||
/*is_machine=*/true);
|
||||
}
|
||||
|
||||
// static
|
||||
@ -177,9 +182,9 @@ TEST_F(PolicyLoaderMacTest, Invalid) {
|
||||
CFDataCreate(kCFAllocatorDefault, reinterpret_cast<const UInt8*>(buffer),
|
||||
std::size(buffer)));
|
||||
ASSERT_TRUE(invalid_data);
|
||||
prefs_->AddTestItem(name, invalid_data.get(), /*is_forced=*/true,
|
||||
prefs_->AddTestItem(name.get(), invalid_data.get(), /*is_forced=*/true,
|
||||
/*is_machine=*/true);
|
||||
prefs_->AddTestItem(name, invalid_data.get(), /*is_forced=*/false,
|
||||
prefs_->AddTestItem(name.get(), invalid_data.get(), /*is_forced=*/false,
|
||||
/*is_machine=*/true);
|
||||
|
||||
// Make the provider read the updated |prefs_|.
|
||||
@ -194,7 +199,7 @@ TEST_F(PolicyLoaderMacTest, TestNonForcedValue) {
|
||||
base::SysUTF8ToCFStringRef(test_keys::kKeyString));
|
||||
CFPropertyListRef test_value = CFSTR("string value");
|
||||
ASSERT_TRUE(test_value);
|
||||
prefs_->AddTestItem(name, test_value, /*is_forced=*/false,
|
||||
prefs_->AddTestItem(name.get(), test_value, /*is_forced=*/false,
|
||||
/*is_machine=*/true);
|
||||
|
||||
// Make the provider read the updated |prefs_|.
|
||||
@ -212,7 +217,7 @@ TEST_F(PolicyLoaderMacTest, TestUserScopeValue) {
|
||||
base::SysUTF8ToCFStringRef(test_keys::kKeyString));
|
||||
CFPropertyListRef test_value = CFSTR("string value");
|
||||
ASSERT_TRUE(test_value);
|
||||
prefs_->AddTestItem(name, test_value, /*is_forced=*/true,
|
||||
prefs_->AddTestItem(name.get(), test_value, /*is_forced=*/true,
|
||||
/*is_machine=*/false);
|
||||
|
||||
// Make the provider read the updated |prefs_|.
|
||||
@ -230,13 +235,15 @@ TEST_F(PolicyLoaderMacTest, LoadPrecedencePolicies) {
|
||||
const PolicyNamespace chrome_ns(POLICY_DOMAIN_CHROME, std::string());
|
||||
RegisterChromeSchema(chrome_ns);
|
||||
|
||||
prefs_->AddTestItem(ScopedCFTypeRef<CFStringRef>(base::SysUTF8ToCFStringRef(
|
||||
key::kCloudPolicyOverridesPlatformPolicy)),
|
||||
kCFBooleanTrue,
|
||||
/*is_forced=*/true,
|
||||
/*is_machine=*/true);
|
||||
prefs_->AddTestItem(ScopedCFTypeRef<CFStringRef>(base::SysUTF8ToCFStringRef(
|
||||
key::kCloudUserPolicyOverridesCloudMachinePolicy)),
|
||||
prefs_->AddTestItem(
|
||||
base::SysUTF8ToCFStringRef(key::kCloudPolicyOverridesPlatformPolicy)
|
||||
.get(),
|
||||
kCFBooleanTrue,
|
||||
/*is_forced=*/true,
|
||||
/*is_machine=*/true);
|
||||
prefs_->AddTestItem(base::SysUTF8ToCFStringRef(
|
||||
key::kCloudUserPolicyOverridesCloudMachinePolicy)
|
||||
.get(),
|
||||
kCFBooleanTrue,
|
||||
/*is_forced=*/true,
|
||||
/*is_machine=*/true);
|
||||
|
@ -96,7 +96,7 @@ CFPropertyListRef ValueToProperty(const base::Value& value) {
|
||||
base::apple::ScopedCFTypeRef<CFPropertyListRef> cf_value(
|
||||
ValueToProperty(key_value_pair.second));
|
||||
if (cf_value)
|
||||
CFDictionaryAddValue(dict, key, cf_value);
|
||||
CFDictionaryAddValue(dict, key.get(), cf_value.get());
|
||||
}
|
||||
return dict;
|
||||
}
|
||||
@ -111,7 +111,7 @@ CFPropertyListRef ValueToProperty(const base::Value& value) {
|
||||
base::apple::ScopedCFTypeRef<CFPropertyListRef> cf_value(
|
||||
ValueToProperty(entry));
|
||||
if (cf_value)
|
||||
CFArrayAppendValue(array, cf_value);
|
||||
CFArrayAppendValue(array, cf_value.get());
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
@ -26,9 +26,7 @@ Boolean MockPreferences::AppSynchronize(CFStringRef application_id) {
|
||||
CFPropertyListRef MockPreferences::CopyAppValue(CFStringRef key,
|
||||
CFStringRef application_id) {
|
||||
CFPropertyListRef value;
|
||||
Boolean found = CFDictionaryGetValueIfPresent(values_,
|
||||
key,
|
||||
&value);
|
||||
Boolean found = CFDictionaryGetValueIfPresent(values_.get(), key, &value);
|
||||
if (!found || !value)
|
||||
return NULL;
|
||||
CFRetain(value);
|
||||
@ -37,21 +35,21 @@ CFPropertyListRef MockPreferences::CopyAppValue(CFStringRef key,
|
||||
|
||||
Boolean MockPreferences::AppValueIsForced(CFStringRef key,
|
||||
CFStringRef application_id) {
|
||||
return CFSetContainsValue(forced_, key);
|
||||
return CFSetContainsValue(forced_.get(), key);
|
||||
}
|
||||
|
||||
Boolean MockPreferences::IsManagedPolicyAvailableForMachineScope(
|
||||
CFStringRef key) {
|
||||
return CFSetContainsValue(machine_, key);
|
||||
return CFSetContainsValue(machine_.get(), key);
|
||||
}
|
||||
|
||||
void MockPreferences::AddTestItem(CFStringRef key,
|
||||
CFPropertyListRef value,
|
||||
bool is_forced,
|
||||
bool is_machine) {
|
||||
CFDictionarySetValue(values_, key, value);
|
||||
CFDictionarySetValue(values_.get(), key, value);
|
||||
if (is_forced)
|
||||
CFSetAddValue(forced_, key);
|
||||
CFSetAddValue(forced_.get(), key);
|
||||
if (is_machine)
|
||||
CFSetAddValue(machine_, key);
|
||||
CFSetAddValue(machine_.get(), key);
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
@ -52,7 +52,7 @@ void ShowCertificateViewerForWindow(NSWindow* owning_window,
|
||||
NOTREACHED();
|
||||
return;
|
||||
}
|
||||
CFArrayAppendValue(policies, basic_policy.get());
|
||||
CFArrayAppendValue(policies.get(), basic_policy.get());
|
||||
|
||||
SFCertificatePanel* panel = [[SFCertificatePanel alloc] init];
|
||||
[panel setPolicies:base::apple::CFToNSPtrCast(policies.get())];
|
||||
|
@ -84,7 +84,7 @@ bool AddOriginMetadataToFile(const base::FilePath& file,
|
||||
}
|
||||
|
||||
if (list.count) {
|
||||
return MDItemSetAttribute(md_item, kMDItemWhereFroms,
|
||||
return MDItemSetAttribute(md_item.get(), kMDItemWhereFroms,
|
||||
base::apple::NSToCFPtrCast(list));
|
||||
}
|
||||
|
||||
|
@ -174,7 +174,7 @@ TEST_F(QuarantineMacTest, NoWhereFromsKeyIfNoURLs) {
|
||||
}
|
||||
|
||||
base::apple::ScopedCFTypeRef<CFTypeRef> attr(
|
||||
MDItemCopyAttribute(md_item, kMDItemWhereFroms));
|
||||
MDItemCopyAttribute(md_item.get(), kMDItemWhereFroms));
|
||||
EXPECT_FALSE(attr);
|
||||
}
|
||||
|
||||
|
@ -90,7 +90,7 @@ StorageInfo BuildStorageInfo(
|
||||
base::apple::ScopedCFTypeRef<CFStringRef> uuid_string(
|
||||
CFUUIDCreateString(nullptr, uuid));
|
||||
if (uuid_string.get())
|
||||
unique_id = base::SysCFStringRefToUTF8(uuid_string);
|
||||
unique_id = base::SysCFStringRefToUTF8(uuid_string.get());
|
||||
}
|
||||
if (unique_id.empty()) {
|
||||
std::u16string revision =
|
||||
@ -160,8 +160,8 @@ StorageMonitorMac::StorageMonitorMac() = default;
|
||||
|
||||
StorageMonitorMac::~StorageMonitorMac() {
|
||||
if (session_.get()) {
|
||||
DASessionUnscheduleFromRunLoop(
|
||||
session_, CFRunLoopGetCurrent(), kCFRunLoopCommonModes);
|
||||
DASessionUnscheduleFromRunLoop(session_.get(), CFRunLoopGetCurrent(),
|
||||
kCFRunLoopCommonModes);
|
||||
}
|
||||
}
|
||||
|
||||
@ -170,25 +170,18 @@ void StorageMonitorMac::Init() {
|
||||
|
||||
// Register for callbacks for attached, changed, and removed devices.
|
||||
// This will send notifications for existing devices too.
|
||||
DARegisterDiskAppearedCallback(
|
||||
session_,
|
||||
kDADiskDescriptionMatchVolumeMountable,
|
||||
DiskAppearedCallback,
|
||||
this);
|
||||
DARegisterDiskDisappearedCallback(
|
||||
session_,
|
||||
kDADiskDescriptionMatchVolumeMountable,
|
||||
DiskDisappearedCallback,
|
||||
this);
|
||||
DARegisterDiskAppearedCallback(session_.get(),
|
||||
kDADiskDescriptionMatchVolumeMountable,
|
||||
DiskAppearedCallback, this);
|
||||
DARegisterDiskDisappearedCallback(session_.get(),
|
||||
kDADiskDescriptionMatchVolumeMountable,
|
||||
DiskDisappearedCallback, this);
|
||||
DARegisterDiskDescriptionChangedCallback(
|
||||
session_,
|
||||
kDADiskDescriptionMatchVolumeMountable,
|
||||
kDADiskDescriptionWatchVolumePath,
|
||||
DiskDescriptionChangedCallback,
|
||||
this);
|
||||
session_.get(), kDADiskDescriptionMatchVolumeMountable,
|
||||
kDADiskDescriptionWatchVolumePath, DiskDescriptionChangedCallback, this);
|
||||
|
||||
DASessionScheduleWithRunLoop(
|
||||
session_, CFRunLoopGetCurrent(), kCFRunLoopCommonModes);
|
||||
DASessionScheduleWithRunLoop(session_.get(), CFRunLoopGetCurrent(),
|
||||
kCFRunLoopCommonModes);
|
||||
|
||||
image_capture_device_manager_ = std::make_unique<ImageCaptureDeviceManager>();
|
||||
image_capture_device_manager_->SetNotifications(receiver());
|
||||
@ -292,13 +285,13 @@ void StorageMonitorMac::EjectDevice(
|
||||
receiver()->ProcessDetach(device_id);
|
||||
|
||||
base::apple::ScopedCFTypeRef<DADiskRef> disk(
|
||||
DADiskCreateFromBSDName(nullptr, session_, bsd_name.c_str()));
|
||||
DADiskCreateFromBSDName(nullptr, session_.get(), bsd_name.c_str()));
|
||||
if (!disk.get()) {
|
||||
std::move(callback).Run(StorageMonitor::EJECT_FAILURE);
|
||||
return;
|
||||
}
|
||||
// Get the reference to the full disk for ejecting.
|
||||
disk.reset(DADiskCopyWholeDisk(disk));
|
||||
disk.reset(DADiskCopyWholeDisk(disk.get()));
|
||||
if (!disk.get()) {
|
||||
std::move(callback).Run(StorageMonitor::EJECT_FAILURE);
|
||||
return;
|
||||
@ -344,7 +337,7 @@ void StorageMonitorMac::GetDiskInfoAndUpdate(
|
||||
std::string* bsd_name = new std::string;
|
||||
base::ThreadPool::PostTaskAndReplyWithResult(
|
||||
FROM_HERE, {base::MayBlock(), base::TaskPriority::BEST_EFFORT},
|
||||
base::BindOnce(&BuildStorageInfo, dict, bsd_name),
|
||||
base::BindOnce(&BuildStorageInfo, dict.get(), bsd_name),
|
||||
base::BindOnce(&StorageMonitorMac::UpdateDisk, AsWeakPtr(), update_type,
|
||||
base::Owned(bsd_name)));
|
||||
}
|
||||
|
@ -25,16 +25,16 @@ std::string GetPersonalizableDeviceNameInternal() {
|
||||
SCDynamicStoreCreate(kCFAllocatorDefault, CFSTR("chrome_sync"),
|
||||
/*callout=*/nullptr, &context));
|
||||
base::apple::ScopedCFTypeRef<CFStringRef> machine_name(
|
||||
SCDynamicStoreCopyLocalHostName(store));
|
||||
SCDynamicStoreCopyLocalHostName(store.get()));
|
||||
if (machine_name) {
|
||||
return base::SysCFStringRefToUTF8(machine_name);
|
||||
return base::SysCFStringRefToUTF8(machine_name.get());
|
||||
}
|
||||
|
||||
// Fall back to get computer name.
|
||||
base::apple::ScopedCFTypeRef<CFStringRef> computer_name(
|
||||
SCDynamicStoreCopyComputerName(store, /*nameEncoding=*/nullptr));
|
||||
SCDynamicStoreCopyComputerName(store.get(), /*nameEncoding=*/nullptr));
|
||||
if (computer_name) {
|
||||
return base::SysCFStringRefToUTF8(computer_name);
|
||||
return base::SysCFStringRefToUTF8(computer_name.get());
|
||||
}
|
||||
|
||||
// If all else fails, return to using a slightly nicer version of the hardware
|
||||
|
@ -115,8 +115,9 @@ SkCanvas* SoftwareOutputDeviceMac::BeginPaint(
|
||||
// any position in the list.
|
||||
for (auto iter = buffer_queue_.begin(); iter != buffer_queue_.end(); ++iter) {
|
||||
Buffer* iter_buffer = iter->get();
|
||||
if (IOSurfaceIsInUse(iter_buffer->io_surface))
|
||||
if (IOSurfaceIsInUse(iter_buffer->io_surface.get())) {
|
||||
continue;
|
||||
}
|
||||
current_paint_buffer_ = iter_buffer;
|
||||
buffer_queue_.splice(buffer_queue_.end(), buffer_queue_, iter);
|
||||
break;
|
||||
@ -150,7 +151,7 @@ SkCanvas* SoftwareOutputDeviceMac::BeginPaint(
|
||||
// |current_paint_canvas_|.
|
||||
{
|
||||
TRACE_EVENT0("browser", "IOSurfaceLock for software paint");
|
||||
IOReturn io_result = IOSurfaceLock(current_paint_buffer_->io_surface,
|
||||
IOReturn io_result = IOSurfaceLock(current_paint_buffer_->io_surface.get(),
|
||||
kIOSurfaceLockAvoidSync, nullptr);
|
||||
if (io_result) {
|
||||
DLOG(ERROR) << "Failed to lock IOSurface " << io_result;
|
||||
@ -160,8 +161,9 @@ SkCanvas* SoftwareOutputDeviceMac::BeginPaint(
|
||||
}
|
||||
{
|
||||
SkPMColor* pixels = static_cast<SkPMColor*>(
|
||||
IOSurfaceGetBaseAddress(current_paint_buffer_->io_surface));
|
||||
size_t stride = IOSurfaceGetBytesPerRow(current_paint_buffer_->io_surface);
|
||||
IOSurfaceGetBaseAddress(current_paint_buffer_->io_surface.get()));
|
||||
size_t stride =
|
||||
IOSurfaceGetBytesPerRow(current_paint_buffer_->io_surface.get());
|
||||
current_paint_canvas_ = SkCanvas::MakeRasterDirectN32(
|
||||
pixel_size_.width(), pixel_size_.height(), pixels, stride);
|
||||
}
|
||||
@ -179,8 +181,9 @@ void SoftwareOutputDeviceMac::EndPaint() {
|
||||
|
||||
{
|
||||
TRACE_EVENT0("browser", "IOSurfaceUnlock");
|
||||
IOReturn io_result = IOSurfaceUnlock(current_paint_buffer_->io_surface,
|
||||
kIOSurfaceLockAvoidSync, nullptr);
|
||||
IOReturn io_result =
|
||||
IOSurfaceUnlock(current_paint_buffer_->io_surface.get(),
|
||||
kIOSurfaceLockAvoidSync, nullptr);
|
||||
if (io_result)
|
||||
DLOG(ERROR) << "Failed to unlock IOSurface " << io_result;
|
||||
}
|
||||
@ -192,7 +195,7 @@ void SoftwareOutputDeviceMac::EndPaint() {
|
||||
ca_layer_params.scale_factor = scale_factor_;
|
||||
ca_layer_params.pixel_size = pixel_size_;
|
||||
ca_layer_params.io_surface_mach_port.reset(
|
||||
IOSurfaceCreateMachPort(current_paint_buffer_->io_surface));
|
||||
IOSurfaceCreateMachPort(current_paint_buffer_->io_surface.get()));
|
||||
client_->SoftwareDeviceUpdatedCALayerParams(ca_layer_params);
|
||||
}
|
||||
|
||||
|
@ -448,7 +448,7 @@ std::string WiFiServiceMac::GetNetworkConnectionState(
|
||||
kCFAllocatorDefault,
|
||||
reinterpret_cast<const struct sockaddr*>(&local_wifi_address)));
|
||||
SCNetworkReachabilityFlags flags = 0u;
|
||||
if (SCNetworkReachabilityGetFlags(reachability, &flags) &&
|
||||
if (SCNetworkReachabilityGetFlags(reachability.get(), &flags) &&
|
||||
(flags & kSCNetworkReachabilityFlagsReachable) &&
|
||||
(flags & kSCNetworkReachabilityFlagsIsDirect)) {
|
||||
// Network is reachable, report is as |kConnected|.
|
||||
|
Reference in New Issue
Block a user