0

Move ScopedTypeRef and ScopedCFTypeRef into base:🍎:

This moves these two types into the base:🍎: namespace.

This also rolls Crashpad:

Update Crashpad to a736f7d070c872a4cc786c31755fd769fb2e50b3

50ce1550a1ca [fuchsia] Move //zircon/public/lib/zx to
             //zircon/system/ulib/zx
a736f7d070c8 Roll mini_chromium putting /base/apple files into
             base:🍎:

Fixed: 1474628
Change-Id: I3d529e6b6f4a6e48bc9edc2df830f9c2418ca678
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4799213
Owners-Override: Avi Drissman <avi@chromium.org>
Commit-Queue: Avi Drissman <avi@chromium.org>
Reviewed-by: Mark Mentovai <mark@chromium.org>
Auto-Submit: Avi Drissman <avi@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1186262}
This commit is contained in:
Avi Drissman
2023-08-22 04:06:45 +00:00
committed by Chromium LUCI CQ
parent 1d56cda2d6
commit 28154a6fbb
325 changed files with 1489 additions and 1360 deletions
base
chrome
app
browser
common
extensions
test
updater
device_management
mac
privileged_helper
policy
utility
components
content
crypto
device
extensions/browser
gpu
headless/lib/browser/policy
ios
media
audio
base
capture
cast
filters
gpu
net
printing
remoting
rlz/mac/lib
services
skia/ext
third_party
tools/mac/power/power_sampler
ui

@ -116,7 +116,7 @@ bool UseMapJit() {
// executable fails with EPERM. Although this is not enforced on x86_64, // executable fails with EPERM. Although this is not enforced on x86_64,
// MAP_JIT is harmless in that case. // MAP_JIT is harmless in that case.
base::ScopedCFTypeRef<SecTaskRef> task( base::apple::ScopedCFTypeRef<SecTaskRef> task(
SecTaskCreateFromSelf(kCFAllocatorDefault)); SecTaskCreateFromSelf(kCFAllocatorDefault));
if (!task) { if (!task) {
return true; return true;
@ -134,7 +134,7 @@ bool UseMapJit() {
// (EINVAL) to use MAP_JIT with the hardened runtime unless the JIT // (EINVAL) to use MAP_JIT with the hardened runtime unless the JIT
// entitlement is specified. // entitlement is specified.
base::ScopedCFTypeRef<CFTypeRef> jit_entitlement( base::apple::ScopedCFTypeRef<CFTypeRef> jit_entitlement(
SecTaskCopyValueForEntitlement( SecTaskCopyValueForEntitlement(
task.get(), CFSTR("com.apple.security.cs.allow-jit"), nullptr)); task.get(), CFSTR("com.apple.security.cs.allow-jit"), nullptr));
if (!jit_entitlement) { if (!jit_entitlement) {

@ -9,7 +9,7 @@
#include "base/allocator/partition_allocator/partition_alloc_base/apple/scoped_typeref.h" #include "base/allocator/partition_allocator/partition_alloc_base/apple/scoped_typeref.h"
namespace partition_alloc::internal::base { namespace partition_alloc::internal::base::apple {
// ScopedCFTypeRef<> is patterned after std::unique_ptr<>, but maintains // ScopedCFTypeRef<> is patterned after std::unique_ptr<>, but maintains
// ownership of a CoreFoundation object: any object that can be represented // ownership of a CoreFoundation object: any object that can be represented
@ -43,6 +43,6 @@ template <typename CFT>
using ScopedCFTypeRef = using ScopedCFTypeRef =
ScopedTypeRef<CFT, internal::ScopedCFTypeRefTraits<CFT>>; ScopedTypeRef<CFT, internal::ScopedCFTypeRefTraits<CFT>>;
} // namespace partition_alloc::internal::base } // namespace partition_alloc::internal::base::apple
#endif // BASE_ALLOCATOR_PARTITION_ALLOCATOR_PARTITION_ALLOC_BASE_APPLE_SCOPED_CFTYPEREF_H_ #endif // BASE_ALLOCATOR_PARTITION_ALLOCATOR_PARTITION_ALLOC_BASE_APPLE_SCOPED_CFTYPEREF_H_

@ -8,7 +8,7 @@
#include "base/allocator/partition_allocator/partition_alloc_base/check.h" #include "base/allocator/partition_allocator/partition_alloc_base/check.h"
#include "base/allocator/partition_allocator/partition_alloc_base/memory/scoped_policy.h" #include "base/allocator/partition_allocator/partition_alloc_base/memory/scoped_policy.h"
namespace partition_alloc::internal::base { namespace partition_alloc::internal::base::apple {
// ScopedTypeRef<> is patterned after std::unique_ptr<>, but maintains ownership // ScopedTypeRef<> is patterned after std::unique_ptr<>, but maintains ownership
// of a reference to any type that is maintained by Retain and Release methods. // of a reference to any type that is maintained by Retain and Release methods.
@ -33,7 +33,7 @@ namespace partition_alloc::internal::base {
// of ownership of the object. For example, continuing to use the above // of ownership of the object. For example, continuing to use the above
// CGLContextObj specialization: // CGLContextObj specialization:
// //
// base::ScopedTypeRef<CGLContextObj> context; // base::apple::ScopedTypeRef<CGLContextObj> context;
// CGLCreateContext(pixel_format, share_group, context.InitializeInto()); // CGLCreateContext(pixel_format, share_group, context.InitializeInto());
// //
// For initialization with an existing object, the caller may specify whether // For initialization with an existing object, the caller may specify whether
@ -146,6 +146,6 @@ class ScopedTypeRef {
element_type object_; element_type object_;
}; };
} // namespace partition_alloc::internal::base } // namespace partition_alloc::internal::base::apple
#endif // BASE_ALLOCATOR_PARTITION_ALLOCATOR_PARTITION_ALLOC_BASE_APPLE_SCOPED_TYPEREF_H_ #endif // BASE_ALLOCATOR_PARTITION_ALLOCATOR_PARTITION_ALLOC_BASE_APPLE_SCOPED_TYPEREF_H_

@ -44,7 +44,7 @@ TEST_F(BackupUtilTest, TestExcludeFileFromBackups_NotByPath) {
ScopedTempDir temp_dir_; ScopedTempDir temp_dir_;
ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
FilePath excluded_file_path = temp_dir_.GetPath().Append("excluded"); FilePath excluded_file_path = temp_dir_.GetPath().Append("excluded");
base::ScopedCFTypeRef<CFURLRef> excluded_url = ScopedCFTypeRef<CFURLRef> excluded_url =
apple::FilePathToCFURL(excluded_file_path); apple::FilePathToCFURL(excluded_file_path);
constexpr char placeholder_data[] = "All your base are belong to us!"; constexpr char placeholder_data[] = "All your base are belong to us!";

@ -144,7 +144,7 @@ CF_TO_NS_CAST_IMPL(CTFont, NSFont)
namespace base::apple { namespace base::apple {
template <typename CFT> template <typename CFT>
id _Nullable CFToNSOwnershipCast(base::ScopedCFTypeRef<CFT>) { id _Nullable CFToNSOwnershipCast(ScopedCFTypeRef<CFT>) {
static_assert( static_assert(
AlwaysFalse<CFT>, AlwaysFalse<CFT>,
"Error: Do not pass a ScopedCFTypeRef to CFToNSOwnershipCast. " "Error: Do not pass a ScopedCFTypeRef to CFToNSOwnershipCast. "

@ -432,8 +432,9 @@ std::ostream& operator<<(std::ostream& o, const CFStringRef string) {
} }
std::ostream& operator<<(std::ostream& o, const CFErrorRef err) { std::ostream& operator<<(std::ostream& o, const CFErrorRef err) {
base::ScopedCFTypeRef<CFStringRef> desc(CFErrorCopyDescription(err)); base::apple::ScopedCFTypeRef<CFStringRef> desc(CFErrorCopyDescription(err));
base::ScopedCFTypeRef<CFDictionaryRef> user_info(CFErrorCopyUserInfo(err)); base::apple::ScopedCFTypeRef<CFDictionaryRef> user_info(
CFErrorCopyUserInfo(err));
CFStringRef errorDesc = nullptr; CFStringRef errorDesc = nullptr;
if (user_info.get()) { if (user_info.get()) {
errorDesc = reinterpret_cast<CFStringRef>( errorDesc = reinterpret_cast<CFStringRef>(

@ -9,7 +9,7 @@
#include "base/apple/scoped_typeref.h" #include "base/apple/scoped_typeref.h"
namespace base { namespace base::apple {
// ScopedCFTypeRef<> is patterned after std::unique_ptr<>, but maintains // ScopedCFTypeRef<> is patterned after std::unique_ptr<>, but maintains
// ownership of a CoreFoundation object: any object that can be represented // ownership of a CoreFoundation object: any object that can be represented
@ -43,6 +43,6 @@ template <typename CFT>
using ScopedCFTypeRef = using ScopedCFTypeRef =
ScopedTypeRef<CFT, internal::ScopedCFTypeRefTraits<CFT>>; ScopedTypeRef<CFT, internal::ScopedCFTypeRefTraits<CFT>>;
} // namespace base } // namespace base::apple
#endif // BASE_APPLE_SCOPED_CFTYPEREF_H_ #endif // BASE_APPLE_SCOPED_CFTYPEREF_H_

@ -8,7 +8,7 @@
#include "base/check.h" #include "base/check.h"
#include "base/memory/scoped_policy.h" #include "base/memory/scoped_policy.h"
namespace base { namespace base::apple {
// ScopedTypeRef<> is patterned after std::unique_ptr<>, but maintains ownership // ScopedTypeRef<> is patterned after std::unique_ptr<>, but maintains ownership
// of a reference to any type that is maintained by Retain and Release methods. // of a reference to any type that is maintained by Retain and Release methods.
@ -33,7 +33,7 @@ namespace base {
// of ownership of the object. For example, continuing to use the above // of ownership of the object. For example, continuing to use the above
// CGLContextObj specialization: // CGLContextObj specialization:
// //
// base::ScopedTypeRef<CGLContextObj> context; // base::apple::ScopedTypeRef<CGLContextObj> context;
// CGLCreateContext(pixel_format, share_group, context.InitializeInto()); // CGLCreateContext(pixel_format, share_group, context.InitializeInto());
// //
// For initialization with an existing object, the caller may specify whether // For initialization with an existing object, the caller may specify whether
@ -146,6 +146,6 @@ class ScopedTypeRef {
element_type object_; element_type object_;
}; };
} // namespace base } // namespace base::apple
#endif // BASE_APPLE_SCOPED_TYPEREF_H_ #endif // BASE_APPLE_SCOPED_TYPEREF_H_

@ -1267,7 +1267,7 @@ int FilePath::HFSFastUnicodeCompare(StringPieceType string1,
StringType FilePath::GetHFSDecomposedForm(StringPieceType string) { StringType FilePath::GetHFSDecomposedForm(StringPieceType string) {
StringType result; StringType result;
ScopedCFTypeRef<CFStringRef> cfstring(CFStringCreateWithBytesNoCopy( apple::ScopedCFTypeRef<CFStringRef> cfstring(CFStringCreateWithBytesNoCopy(
NULL, reinterpret_cast<const UInt8*>(string.data()), NULL, reinterpret_cast<const UInt8*>(string.data()),
checked_cast<CFIndex>(string.length()), kCFStringEncodingUTF8, false, checked_cast<CFIndex>(string.length()), kCFStringEncodingUTF8, false,
kCFAllocatorNull)); kCFAllocatorNull));
@ -1310,11 +1310,11 @@ int FilePath::CompareIgnoreCase(StringPieceType string1,
// GetHFSDecomposedForm() returns an empty string in an error case. // GetHFSDecomposedForm() returns an empty string in an error case.
if (hfs1.empty() || hfs2.empty()) { if (hfs1.empty() || hfs2.empty()) {
ScopedCFTypeRef<CFStringRef> cfstring1(CFStringCreateWithBytesNoCopy( apple::ScopedCFTypeRef<CFStringRef> cfstring1(CFStringCreateWithBytesNoCopy(
NULL, reinterpret_cast<const UInt8*>(string1.data()), NULL, reinterpret_cast<const UInt8*>(string1.data()),
checked_cast<CFIndex>(string1.length()), kCFStringEncodingUTF8, false, checked_cast<CFIndex>(string1.length()), kCFStringEncodingUTF8, false,
kCFAllocatorNull)); kCFAllocatorNull));
ScopedCFTypeRef<CFStringRef> cfstring2(CFStringCreateWithBytesNoCopy( apple::ScopedCFTypeRef<CFStringRef> cfstring2(CFStringCreateWithBytesNoCopy(
NULL, reinterpret_cast<const UInt8*>(string2.data()), NULL, reinterpret_cast<const UInt8*>(string2.data()),
checked_cast<CFIndex>(string2.length()), kCFStringEncodingUTF8, false, checked_cast<CFIndex>(string2.length()), kCFStringEncodingUTF8, false,
kCFAllocatorNull)); kCFAllocatorNull));

@ -213,13 +213,13 @@ void FilePathWatcherFSEvents::UpdateEventStream(
if (fsevent_stream_) if (fsevent_stream_)
DestroyEventStream(); DestroyEventStream();
ScopedCFTypeRef<CFStringRef> cf_path(CFStringCreateWithCString( apple::ScopedCFTypeRef<CFStringRef> cf_path(CFStringCreateWithCString(
NULL, resolved_target_.value().c_str(), kCFStringEncodingMacHFS)); NULL, resolved_target_.value().c_str(), kCFStringEncodingMacHFS));
ScopedCFTypeRef<CFStringRef> cf_dir_path(CFStringCreateWithCString( apple::ScopedCFTypeRef<CFStringRef> cf_dir_path(CFStringCreateWithCString(
NULL, resolved_target_.DirName().value().c_str(), NULL, resolved_target_.DirName().value().c_str(),
kCFStringEncodingMacHFS)); kCFStringEncodingMacHFS));
CFStringRef paths_array[] = { cf_path.get(), cf_dir_path.get() }; CFStringRef paths_array[] = { cf_path.get(), cf_dir_path.get() };
ScopedCFTypeRef<CFArrayRef> watched_paths( apple::ScopedCFTypeRef<CFArrayRef> watched_paths(
CFArrayCreate(NULL, reinterpret_cast<const void**>(paths_array), CFArrayCreate(NULL, reinterpret_cast<const void**>(paths_array),
std::size(paths_array), &kCFTypeArrayCallBacks)); std::size(paths_array), &kCFTypeArrayCallBacks));

@ -129,9 +129,9 @@ std::string GetMacAddress(const std::string& interface_name) {
} }
std::string GetRandomId() { std::string GetRandomId() {
base::ScopedCFTypeRef<CFUUIDRef> uuid_object( base::apple::ScopedCFTypeRef<CFUUIDRef> uuid_object(
CFUUIDCreate(kCFAllocatorDefault)); CFUUIDCreate(kCFAllocatorDefault));
base::ScopedCFTypeRef<CFStringRef> uuid_string( base::apple::ScopedCFTypeRef<CFStringRef> uuid_string(
CFUUIDCreateString(kCFAllocatorDefault, uuid_object)); CFUUIDCreateString(kCFAllocatorDefault, uuid_object));
return base::SysCFStringRefToUTF8(uuid_string); return base::SysCFStringRefToUTF8(uuid_string);
} }
@ -177,9 +177,9 @@ std::string GetSaltedString(const std::string& in_string,
hash); hash);
CFUUIDBytes* uuid_bytes = reinterpret_cast<CFUUIDBytes*>(hash); CFUUIDBytes* uuid_bytes = reinterpret_cast<CFUUIDBytes*>(hash);
base::ScopedCFTypeRef<CFUUIDRef> uuid_object( base::apple::ScopedCFTypeRef<CFUUIDRef> uuid_object(
CFUUIDCreateFromUUIDBytes(kCFAllocatorDefault, *uuid_bytes)); CFUUIDCreateFromUUIDBytes(kCFAllocatorDefault, *uuid_bytes));
base::ScopedCFTypeRef<CFStringRef> device_id( base::apple::ScopedCFTypeRef<CFStringRef> device_id(
CFUUIDCreateString(kCFAllocatorDefault, uuid_object)); CFUUIDCreateString(kCFAllocatorDefault, uuid_object));
return base::SysCFStringRefToUTF8(device_id); return base::SysCFStringRefToUTF8(device_id);
} }

@ -65,12 +65,13 @@ class LoginItemsFileList {
// representing the specified bundle. If such an item is found, returns a // representing the specified bundle. If such an item is found, returns a
// retained reference to it. Caller is responsible for releasing the // retained reference to it. Caller is responsible for releasing the
// reference. // reference.
ScopedCFTypeRef<LSSharedFileListItemRef> GetLoginItemForApp(NSURL* url) { apple::ScopedCFTypeRef<LSSharedFileListItemRef> GetLoginItemForApp(
NSURL* url) {
DCHECK(login_items_.get()) << "Initialize() failed or not called."; DCHECK(login_items_.get()) << "Initialize() failed or not called.";
#pragma clang diagnostic push // https://crbug.com/1154377 #pragma clang diagnostic push // https://crbug.com/1154377
#pragma clang diagnostic ignored "-Wdeprecated-declarations" #pragma clang diagnostic ignored "-Wdeprecated-declarations"
ScopedCFTypeRef<CFArrayRef> login_items_array( apple::ScopedCFTypeRef<CFArrayRef> login_items_array(
LSSharedFileListCopySnapshot(login_items_, /*inList=*/nullptr)); LSSharedFileListCopySnapshot(login_items_, /*inList=*/nullptr));
#pragma clang diagnostic pop #pragma clang diagnostic pop
@ -88,27 +89,27 @@ class LoginItemsFileList {
#pragma clang diagnostic pop #pragma clang diagnostic pop
if (item_url && [item_url isEqual:url]) { if (item_url && [item_url isEqual:url]) {
return ScopedCFTypeRef<LSSharedFileListItemRef>( return apple::ScopedCFTypeRef<LSSharedFileListItemRef>(
item, base::scoped_policy::RETAIN); item, base::scoped_policy::RETAIN);
} }
} }
return ScopedCFTypeRef<LSSharedFileListItemRef>(); return apple::ScopedCFTypeRef<LSSharedFileListItemRef>();
} }
ScopedCFTypeRef<LSSharedFileListItemRef> GetLoginItemForMainApp() { apple::ScopedCFTypeRef<LSSharedFileListItemRef> GetLoginItemForMainApp() {
NSURL* url = [NSURL fileURLWithPath:base::apple::MainBundle().bundlePath]; NSURL* url = [NSURL fileURLWithPath:base::apple::MainBundle().bundlePath];
return GetLoginItemForApp(url); return GetLoginItemForApp(url);
} }
private: private:
ScopedCFTypeRef<LSSharedFileListRef> login_items_; apple::ScopedCFTypeRef<LSSharedFileListRef> login_items_;
}; };
bool IsHiddenLoginItem(LSSharedFileListItemRef item) { bool IsHiddenLoginItem(LSSharedFileListItemRef item) {
#pragma clang diagnostic push // https://crbug.com/1154377 #pragma clang diagnostic push // https://crbug.com/1154377
#pragma clang diagnostic ignored "-Wdeprecated-declarations" #pragma clang diagnostic ignored "-Wdeprecated-declarations"
ScopedCFTypeRef<CFBooleanRef> hidden( apple::ScopedCFTypeRef<CFBooleanRef> hidden(
reinterpret_cast<CFBooleanRef>(LSSharedFileListItemCopyProperty( reinterpret_cast<CFBooleanRef>(LSSharedFileListItemCopyProperty(
item, kLSSharedFileListLoginItemHidden))); item, kLSSharedFileListLoginItemHidden)));
#pragma clang diagnostic pop #pragma clang diagnostic pop
@ -164,7 +165,7 @@ void AddToLoginItems(const FilePath& app_bundle_file_path,
} }
NSURL* app_bundle_url = base::apple::FilePathToNSURL(app_bundle_file_path); NSURL* app_bundle_url = base::apple::FilePathToNSURL(app_bundle_file_path);
base::ScopedCFTypeRef<LSSharedFileListItemRef> item = apple::ScopedCFTypeRef<LSSharedFileListItemRef> item =
login_items.GetLoginItemForApp(app_bundle_url); login_items.GetLoginItemForApp(app_bundle_url);
if (item.get() && (IsHiddenLoginItem(item) == hide_on_startup)) { if (item.get() && (IsHiddenLoginItem(item) == hide_on_startup)) {
@ -185,7 +186,7 @@ void AddToLoginItems(const FilePath& app_bundle_file_path,
NSDictionary* properties = NSDictionary* properties =
@{apple::CFToNSPtrCast(kLSSharedFileListLoginItemHidden) : @(hide)}; @{apple::CFToNSPtrCast(kLSSharedFileListLoginItemHidden) : @(hide)};
ScopedCFTypeRef<LSSharedFileListItemRef> new_item( apple::ScopedCFTypeRef<LSSharedFileListItemRef> new_item(
LSSharedFileListInsertItemURL( LSSharedFileListInsertItemURL(
login_items.GetLoginFileList(), kLSSharedFileListItemLast, login_items.GetLoginFileList(), kLSSharedFileListItemLast,
/*inDisplayName=*/nullptr, /*inDisplayName=*/nullptr,
@ -205,7 +206,7 @@ void RemoveFromLoginItems(const FilePath& app_bundle_file_path) {
} }
NSURL* app_bundle_url = base::apple::FilePathToNSURL(app_bundle_file_path); NSURL* app_bundle_url = base::apple::FilePathToNSURL(app_bundle_file_path);
base::ScopedCFTypeRef<LSSharedFileListItemRef> item = apple::ScopedCFTypeRef<LSSharedFileListItemRef> item =
login_items.GetLoginItemForApp(app_bundle_url); login_items.GetLoginItemForApp(app_bundle_url);
if (!item.get()) { if (!item.get()) {
return; return;
@ -250,7 +251,7 @@ bool WasLaunchedAsLoginItemRestoreState() {
CFStringRef app = CFSTR("com.apple.loginwindow"); CFStringRef app = CFSTR("com.apple.loginwindow");
CFStringRef save_state = CFSTR("TALLogoutSavesState"); CFStringRef save_state = CFSTR("TALLogoutSavesState");
ScopedCFTypeRef<CFPropertyListRef> plist( apple::ScopedCFTypeRef<CFPropertyListRef> plist(
CFPreferencesCopyAppValue(save_state, app)); CFPreferencesCopyAppValue(save_state, app));
// According to documentation, com.apple.loginwindow.plist does not exist on a // According to documentation, com.apple.loginwindow.plist does not exist on a
// fresh installation until the user changes a login window setting. The // fresh installation until the user changes a login window setting. The
@ -278,7 +279,7 @@ bool WasLaunchedAsHiddenLoginItem() {
return false; return false;
} }
base::ScopedCFTypeRef<LSSharedFileListItemRef> item( apple::ScopedCFTypeRef<LSSharedFileListItemRef> item(
login_items.GetLoginItemForMainApp()); login_items.GetLoginItemForMainApp());
if (!item.get()) { if (!item.get()) {
// The OS itself can launch items, usually for the resume feature. // The OS itself can launch items, usually for the resume feature.
@ -407,7 +408,7 @@ std::string GetModelIdentifier() {
ScopedIOObject<io_service_t> platform_expert(IOServiceGetMatchingService( ScopedIOObject<io_service_t> platform_expert(IOServiceGetMatchingService(
kIOMasterPortDefault, IOServiceMatching("IOPlatformExpertDevice"))); kIOMasterPortDefault, IOServiceMatching("IOPlatformExpertDevice")));
if (platform_expert) { if (platform_expert) {
ScopedCFTypeRef<CFDataRef> model_data( apple::ScopedCFTypeRef<CFDataRef> model_data(
static_cast<CFDataRef>(IORegistryEntryCreateCFProperty( static_cast<CFDataRef>(IORegistryEntryCreateCFProperty(
platform_expert, CFSTR("model"), kCFAllocatorDefault, 0))); platform_expert, CFSTR("model"), kCFAllocatorDefault, 0)));
if (model_data) { if (model_data) {
@ -462,7 +463,7 @@ std::string GetPlatformSerialNumber() {
return std::string(); return std::string();
} }
base::ScopedCFTypeRef<CFTypeRef> serial_number( apple::ScopedCFTypeRef<CFTypeRef> serial_number(
IORegistryEntryCreateCFProperty(expert_device, IORegistryEntryCreateCFProperty(expert_device,
CFSTR(kIOPlatformSerialNumberKey), CFSTR(kIOPlatformSerialNumberKey),
kCFAllocatorDefault, 0)); kCFAllocatorDefault, 0));

@ -27,7 +27,8 @@ struct ScopedIOObjectTraits {
// Just like ScopedCFTypeRef but for io_object_t and subclasses. // Just like ScopedCFTypeRef but for io_object_t and subclasses.
template <typename IOT> template <typename IOT>
using ScopedIOObject = ScopedTypeRef<IOT, internal::ScopedIOObjectTraits<IOT>>; using ScopedIOObject =
apple::ScopedTypeRef<IOT, internal::ScopedIOObjectTraits<IOT>>;
} // namespace base::mac } // namespace base::mac

@ -29,7 +29,7 @@ struct ScopedIOPluginInterfaceTraits {
// (IOUSBInterfaceStruct and IOUSBDeviceStruct320 in particular). // (IOUSBInterfaceStruct and IOUSBDeviceStruct320 in particular).
template <typename T> template <typename T>
using ScopedIOPluginInterface = using ScopedIOPluginInterface =
ScopedTypeRef<T**, internal::ScopedIOPluginInterfaceTraits<T**>>; apple::ScopedTypeRef<T**, internal::ScopedIOPluginInterfaceTraits<T**>>;
} // namespace base::mac } // namespace base::mac

@ -219,20 +219,20 @@ class BASE_EXPORT MessagePumpCFRunLoopBase : public MessagePump {
void PushWorkItemScope(); void PushWorkItemScope();
// The thread's run loop. // The thread's run loop.
base::ScopedCFTypeRef<CFRunLoopRef> run_loop_; apple::ScopedCFTypeRef<CFRunLoopRef> run_loop_;
// The enabled modes. Posted tasks may run in any non-null entry. // The enabled modes. Posted tasks may run in any non-null entry.
std::unique_ptr<ScopedModeEnabler> enabled_modes_[kNumModes]; std::unique_ptr<ScopedModeEnabler> enabled_modes_[kNumModes];
// The timer, sources, and observers are described above alongside their // The timer, sources, and observers are described above alongside their
// callbacks. // callbacks.
base::ScopedCFTypeRef<CFRunLoopTimerRef> delayed_work_timer_; apple::ScopedCFTypeRef<CFRunLoopTimerRef> delayed_work_timer_;
base::ScopedCFTypeRef<CFRunLoopSourceRef> work_source_; apple::ScopedCFTypeRef<CFRunLoopSourceRef> work_source_;
base::ScopedCFTypeRef<CFRunLoopSourceRef> nesting_deferred_work_source_; apple::ScopedCFTypeRef<CFRunLoopSourceRef> nesting_deferred_work_source_;
base::ScopedCFTypeRef<CFRunLoopObserverRef> pre_wait_observer_; apple::ScopedCFTypeRef<CFRunLoopObserverRef> pre_wait_observer_;
base::ScopedCFTypeRef<CFRunLoopObserverRef> after_wait_observer_; apple::ScopedCFTypeRef<CFRunLoopObserverRef> after_wait_observer_;
base::ScopedCFTypeRef<CFRunLoopObserverRef> pre_source_observer_; apple::ScopedCFTypeRef<CFRunLoopObserverRef> pre_source_observer_;
base::ScopedCFTypeRef<CFRunLoopObserverRef> enter_exit_observer_; apple::ScopedCFTypeRef<CFRunLoopObserverRef> enter_exit_observer_;
// (weak) Delegate passed as an argument to the innermost Run call. // (weak) Delegate passed as an argument to the innermost Run call.
raw_ptr<Delegate> delegate_ = nullptr; raw_ptr<Delegate> delegate_ = nullptr;
@ -310,7 +310,7 @@ class BASE_EXPORT MessagePumpNSRunLoop : public MessagePumpCFRunLoopBase {
// A source that doesn't do anything but provide something signalable // A source that doesn't do anything but provide something signalable
// attached to the run loop. This source will be signalled when Quit // attached to the run loop. This source will be signalled when Quit
// is called, to cause the loop to wake up so that it can stop. // is called, to cause the loop to wake up so that it can stop.
base::ScopedCFTypeRef<CFRunLoopSourceRef> quit_source_; apple::ScopedCFTypeRef<CFRunLoopSourceRef> quit_source_;
}; };
#if BUILDFLAG(IS_IOS) #if BUILDFLAG(IS_IOS)

@ -91,9 +91,9 @@ bool MessagePumpIOSForIO::WatchFileDescriptor(int fd,
CFFileDescriptorRef fdref = controller->fdref_.get(); CFFileDescriptorRef fdref = controller->fdref_.get();
if (fdref == NULL) { if (fdref == NULL) {
base::ScopedCFTypeRef<CFFileDescriptorRef> scoped_fdref( apple::ScopedCFTypeRef<CFFileDescriptorRef> scoped_fdref(
CFFileDescriptorCreate( CFFileDescriptorCreate(kCFAllocatorDefault, fd, false, HandleFdIOEvent,
kCFAllocatorDefault, fd, false, HandleFdIOEvent, &source_context)); &source_context));
if (scoped_fdref == NULL) { if (scoped_fdref == NULL) {
NOTREACHED() << "CFFileDescriptorCreate failed"; NOTREACHED() << "CFFileDescriptorCreate failed";
return false; return false;
@ -102,9 +102,9 @@ bool MessagePumpIOSForIO::WatchFileDescriptor(int fd,
CFFileDescriptorEnableCallBacks(scoped_fdref, callback_types); CFFileDescriptorEnableCallBacks(scoped_fdref, callback_types);
// TODO(wtc): what should the 'order' argument be? // TODO(wtc): what should the 'order' argument be?
base::ScopedCFTypeRef<CFRunLoopSourceRef> scoped_fd_source( apple::ScopedCFTypeRef<CFRunLoopSourceRef> scoped_fd_source(
CFFileDescriptorCreateRunLoopSource( CFFileDescriptorCreateRunLoopSource(kCFAllocatorDefault, scoped_fdref,
kCFAllocatorDefault, scoped_fdref, 0)); 0));
if (scoped_fd_source == NULL) { if (scoped_fd_source == NULL) {
NOTREACHED() << "CFFileDescriptorCreateRunLoopSource failed"; NOTREACHED() << "CFFileDescriptorCreateRunLoopSource failed";
return false; return false;
@ -154,7 +154,7 @@ void MessagePumpIOSForIO::HandleFdIOEvent(CFFileDescriptorRef fdref,
// Ensure that |fdref| will remain live for the duration of this function // Ensure that |fdref| will remain live for the duration of this function
// call even if |controller| is deleted or |StopWatchingFileDescriptor()| is // call even if |controller| is deleted or |StopWatchingFileDescriptor()| is
// called, either of which will cause |fdref| to be released. // called, either of which will cause |fdref| to be released.
ScopedCFTypeRef<CFFileDescriptorRef> scoped_fdref( apple::ScopedCFTypeRef<CFFileDescriptorRef> scoped_fdref(
fdref, base::scoped_policy::RETAIN); fdref, base::scoped_policy::RETAIN);
int fd = CFFileDescriptorGetNativeDescriptor(fdref); int fd = CFFileDescriptorGetNativeDescriptor(fdref);

@ -53,10 +53,10 @@ class BASE_EXPORT MessagePumpIOSForIO : public MessagePumpNSRunLoop,
void OnFileCanWriteWithoutBlocking(int fd, MessagePumpIOSForIO* pump); void OnFileCanWriteWithoutBlocking(int fd, MessagePumpIOSForIO* pump);
bool is_persistent_ = false; // false if this event is one-shot. bool is_persistent_ = false; // false if this event is one-shot.
base::apple::ScopedCFFileDescriptorRef fdref_; apple::ScopedCFFileDescriptorRef fdref_;
CFOptionFlags callback_types_ = 0; CFOptionFlags callback_types_ = 0;
base::ScopedCFTypeRef<CFRunLoopSourceRef> fd_source_; apple::ScopedCFTypeRef<CFRunLoopSourceRef> fd_source_;
base::WeakPtr<MessagePumpIOSForIO> pump_; WeakPtr<MessagePumpIOSForIO> pump_;
FdWatcher* watcher_ = nullptr; FdWatcher* watcher_ = nullptr;
}; };

@ -64,7 +64,7 @@ NativeLibrary LoadNativeLibraryWithOptions(const FilePath& library_path,
native_lib->objc_status = OBJC_UNKNOWN; native_lib->objc_status = OBJC_UNKNOWN;
return native_lib; return native_lib;
} }
ScopedCFTypeRef<CFURLRef> url(CFURLCreateFromFileSystemRepresentation( apple::ScopedCFTypeRef<CFURLRef> url(CFURLCreateFromFileSystemRepresentation(
kCFAllocatorDefault, (const UInt8*)library_path.value().c_str(), kCFAllocatorDefault, (const UInt8*)library_path.value().c_str(),
checked_cast<CFIndex>(library_path.value().length()), true)); checked_cast<CFIndex>(library_path.value().length()), true));
if (!url) if (!url)
@ -103,7 +103,7 @@ void* GetFunctionPointerFromNativeLibrary(NativeLibrary library,
// Get the function pointer using the right API for the type. // Get the function pointer using the right API for the type.
if (library->type == BUNDLE) { if (library->type == BUNDLE) {
ScopedCFTypeRef<CFStringRef> symbol_name(CFStringCreateWithCString( apple::ScopedCFTypeRef<CFStringRef> symbol_name(CFStringCreateWithCString(
kCFAllocatorDefault, name, kCFStringEncodingUTF8)); kCFAllocatorDefault, name, kCFStringEncodingUTF8));
function_pointer = function_pointer =
CFBundleGetFunctionPointerForName(library->bundle, symbol_name); CFBundleGetFunctionPointerForName(library->bundle, symbol_name);

@ -71,7 +71,7 @@ BatteryLevelProviderMac::GetBatteryStateImpl() {
return MakeBatteryState(/* battery_details=*/{}); return MakeBatteryState(/* battery_details=*/{});
} }
base::ScopedCFTypeRef<CFMutableDictionaryRef> dict; apple::ScopedCFTypeRef<CFMutableDictionaryRef> dict;
kern_return_t result = kern_return_t result =
IORegistryEntryCreateCFProperties(service.get(), dict.InitializeInto(), IORegistryEntryCreateCFProperties(service.get(), dict.InitializeInto(),
/*allocator=*/nullptr, /*options=*/0); /*allocator=*/nullptr, /*options=*/0);

@ -111,7 +111,7 @@ ThermalStateObserverMac::GetCurrentThermalState() {
} }
int ThermalStateObserverMac::GetCurrentSpeedLimit() { int ThermalStateObserverMac::GetCurrentSpeedLimit() {
base::ScopedCFTypeRef<CFDictionaryRef> dictionary; apple::ScopedCFTypeRef<CFDictionaryRef> dictionary;
IOReturn result = IOPMCopyCPUPowerStatus(dictionary.InitializeInto()); IOReturn result = IOPMCopyCPUPowerStatus(dictionary.InitializeInto());
if (result != kIOReturnSuccess) { if (result != kIOReturnSuccess) {
DVLOG(1) << __func__ DVLOG(1) << __func__

@ -63,10 +63,10 @@ namespace base {
// Converts between strings and CFStringRefs/NSStrings. // Converts between strings and CFStringRefs/NSStrings.
// Converts a string to a CFStringRef. Returns null on failure. // Converts a string to a CFStringRef. Returns null on failure.
[[nodiscard]] BASE_EXPORT ScopedCFTypeRef<CFStringRef> SysUTF8ToCFStringRef( [[nodiscard]] BASE_EXPORT apple::ScopedCFTypeRef<CFStringRef>
StringPiece utf8); SysUTF8ToCFStringRef(StringPiece utf8);
[[nodiscard]] BASE_EXPORT ScopedCFTypeRef<CFStringRef> SysUTF16ToCFStringRef( [[nodiscard]] BASE_EXPORT apple::ScopedCFTypeRef<CFStringRef>
StringPiece16 utf16); SysUTF16ToCFStringRef(StringPiece16 utf16);
// Converts a CFStringRef to a string. Returns an empty string on failure. It is // Converts a CFStringRef to a string. Returns an empty string on failure. It is
// not valid to call these with a null `ref`. // not valid to call these with a null `ref`.

@ -81,7 +81,7 @@ OutStringType StringToStringWithEncodingsT(const InStringType& in,
return OutStringType(); return OutStringType();
} }
base::ScopedCFTypeRef<CFStringRef> cfstring(CFStringCreateWithBytesNoCopy( apple::ScopedCFTypeRef<CFStringRef> cfstring(CFStringCreateWithBytesNoCopy(
kCFAllocatorDefault, reinterpret_cast<const UInt8*>(in.data()), kCFAllocatorDefault, reinterpret_cast<const UInt8*>(in.data()),
checked_cast<CFIndex>(in_length * checked_cast<CFIndex>(in_length *
sizeof(typename InStringType::value_type)), sizeof(typename InStringType::value_type)),
@ -97,15 +97,16 @@ OutStringType StringToStringWithEncodingsT(const InStringType& in,
// Given a StringPiece `in` with an encoding specified by `in_encoding`, returns // Given a StringPiece `in` with an encoding specified by `in_encoding`, returns
// it as a CFStringRef. Returns null on failure. // it as a CFStringRef. Returns null on failure.
template <typename CharT> template <typename CharT>
ScopedCFTypeRef<CFStringRef> StringPieceToCFStringWithEncodingsT( apple::ScopedCFTypeRef<CFStringRef> StringPieceToCFStringWithEncodingsT(
BasicStringPiece<CharT> in, BasicStringPiece<CharT> in,
CFStringEncoding in_encoding) { CFStringEncoding in_encoding) {
const auto in_length = in.length(); const auto in_length = in.length();
if (in_length == 0) { if (in_length == 0) {
return ScopedCFTypeRef<CFStringRef>(CFSTR(""), base::scoped_policy::RETAIN); return apple::ScopedCFTypeRef<CFStringRef>(CFSTR(""),
base::scoped_policy::RETAIN);
} }
return ScopedCFTypeRef<CFStringRef>(CFStringCreateWithBytes( return apple::ScopedCFTypeRef<CFStringRef>(CFStringCreateWithBytes(
kCFAllocatorDefault, reinterpret_cast<const UInt8*>(in.data()), kCFAllocatorDefault, reinterpret_cast<const UInt8*>(in.data()),
checked_cast<CFIndex>(in_length * sizeof(CharT)), in_encoding, false)); checked_cast<CFIndex>(in_length * sizeof(CharT)), in_encoding, false));
} }
@ -136,11 +137,11 @@ std::wstring SysNativeMBToWide(StringPiece native_mb) {
return SysUTF8ToWide(native_mb); return SysUTF8ToWide(native_mb);
} }
ScopedCFTypeRef<CFStringRef> SysUTF8ToCFStringRef(StringPiece utf8) { apple::ScopedCFTypeRef<CFStringRef> SysUTF8ToCFStringRef(StringPiece utf8) {
return StringPieceToCFStringWithEncodingsT(utf8, kCFStringEncodingUTF8); return StringPieceToCFStringWithEncodingsT(utf8, kCFStringEncodingUTF8);
} }
ScopedCFTypeRef<CFStringRef> SysUTF16ToCFStringRef(StringPiece16 utf16) { apple::ScopedCFTypeRef<CFStringRef> SysUTF16ToCFStringRef(StringPiece16 utf16) {
return StringPieceToCFStringWithEncodingsT(utf16, kCFStringEncodingUTF16LE); return StringPieceToCFStringWithEncodingsT(utf16, kCFStringEncodingUTF16LE);
} }

@ -26,11 +26,11 @@ namespace base {
// static // static
bool Time::FromExploded(bool is_local, const Exploded& exploded, Time* time) { bool Time::FromExploded(bool is_local, const Exploded& exploded, Time* time) {
base::ScopedCFTypeRef<CFTimeZoneRef> time_zone( ScopedCFTypeRef<CFTimeZoneRef> time_zone(
is_local is_local
? CFTimeZoneCopySystem() ? CFTimeZoneCopySystem()
: CFTimeZoneCreateWithTimeIntervalFromGMT(kCFAllocatorDefault, 0)); : CFTimeZoneCreateWithTimeIntervalFromGMT(kCFAllocatorDefault, 0));
base::ScopedCFTypeRef<CFCalendarRef> gregorian(CFCalendarCreateWithIdentifier( ScopedCFTypeRef<CFCalendarRef> gregorian(CFCalendarCreateWithIdentifier(
kCFAllocatorDefault, kCFGregorianCalendar)); kCFAllocatorDefault, kCFGregorianCalendar));
CFCalendarSetTimeZone(gregorian, time_zone); CFCalendarSetTimeZone(gregorian, time_zone);
CFAbsoluteTime absolute_time; CFAbsoluteTime absolute_time;
@ -83,11 +83,11 @@ void Time::Explode(bool is_local, Exploded* exploded) const {
kMicrosecondsPerSecond) - kMicrosecondsPerSecond) -
kCFAbsoluteTimeIntervalSince1970; kCFAbsoluteTimeIntervalSince1970;
base::ScopedCFTypeRef<CFTimeZoneRef> time_zone( ScopedCFTypeRef<CFTimeZoneRef> time_zone(
is_local is_local
? CFTimeZoneCopySystem() ? CFTimeZoneCopySystem()
: CFTimeZoneCreateWithTimeIntervalFromGMT(kCFAllocatorDefault, 0)); : CFTimeZoneCreateWithTimeIntervalFromGMT(kCFAllocatorDefault, 0));
base::ScopedCFTypeRef<CFCalendarRef> gregorian(CFCalendarCreateWithIdentifier( ScopedCFTypeRef<CFCalendarRef> gregorian(CFCalendarCreateWithIdentifier(
kCFAllocatorDefault, kCFGregorianCalendar)); kCFAllocatorDefault, kCFGregorianCalendar));
CFCalendarSetTimeZone(gregorian, time_zone); CFCalendarSetTimeZone(gregorian, time_zone);
int second, day_of_week; int second, day_of_week;

@ -17,7 +17,7 @@
bool ChromeCrashReporterClient::ReportingIsEnforcedByPolicy( bool ChromeCrashReporterClient::ReportingIsEnforcedByPolicy(
bool* breakpad_enabled) { bool* breakpad_enabled) {
base::ScopedCFTypeRef<CFStringRef> key = base::apple::ScopedCFTypeRef<CFStringRef> key =
base::SysUTF8ToCFStringRef(policy::key::kMetricsReportingEnabled); base::SysUTF8ToCFStringRef(policy::key::kMetricsReportingEnabled);
Boolean key_valid; Boolean key_valid;
Boolean metrics_reporting_enabled = CFPreferencesGetAppBooleanValue(key, Boolean metrics_reporting_enabled = CFPreferencesGetAppBooleanValue(key,

@ -271,7 +271,7 @@ void RecordLastRunAppBundlePath() {
.DirName() .DirName()
.DirName() .DirName()
.DirName(); .DirName();
base::ScopedCFTypeRef<CFStringRef> app_bundle_path_cfstring = base::apple::ScopedCFTypeRef<CFStringRef> app_bundle_path_cfstring =
base::SysUTF8ToCFStringRef(app_bundle_path.value()); base::SysUTF8ToCFStringRef(app_bundle_path.value());
CFPreferencesSetAppValue( CFPreferencesSetAppValue(
base::apple::NSToCFPtrCast(app_mode::kLastRunAppBundlePathPrefsKey), base::apple::NSToCFPtrCast(app_mode::kLastRunAppBundlePathPrefsKey),

@ -28,7 +28,7 @@ AppShimHostBootstrap::Client* g_client = nullptr;
// TODO(https://crbug.com/1052131): Remove NSLog logging, and move to an // TODO(https://crbug.com/1052131): Remove NSLog logging, and move to an
// internal debugging URL. // internal debugging URL.
void LogToNSLog(std::string format, ...) { void LogToNSLog(std::string format, ...) {
base::ScopedCFTypeRef<CFStringRef> cf_format( base::apple::ScopedCFTypeRef<CFStringRef> cf_format(
base::SysUTF8ToCFStringRef(format)); base::SysUTF8ToCFStringRef(format));
va_list arguments; va_list arguments;

@ -109,14 +109,14 @@ void DumpError(std::string error_details) {
// * "has_value() == true" app shim validation should occur. // * "has_value() == true" app shim validation should occur.
// * "has_value() == false" app shim validation should be skipped. // * "has_value() == false" app shim validation should be skipped.
// * "has_value() == true && value() == null" validation should always fail. // * "has_value() == true && value() == null" validation should always fail.
absl::optional<base::ScopedCFTypeRef<SecRequirementRef>> absl::optional<base::apple::ScopedCFTypeRef<SecRequirementRef>>
CreateAppShimRequirement() { CreateAppShimRequirement() {
// Note: Don't validate |framework_code|: We don't need to waste time // Note: Don't validate |framework_code|: We don't need to waste time
// validating. We are only interested in discovering if the framework bundle // validating. We are only interested in discovering if the framework bundle
// is code-signed, and if so what the designated requirement is. // is code-signed, and if so what the designated requirement is.
base::ScopedCFTypeRef<CFURLRef> framework_url = base::apple::ScopedCFTypeRef<CFURLRef> framework_url =
base::apple::FilePathToCFURL(base::apple::FrameworkBundlePath()); base::apple::FilePathToCFURL(base::apple::FrameworkBundlePath());
base::ScopedCFTypeRef<SecStaticCodeRef> framework_code; base::apple::ScopedCFTypeRef<SecStaticCodeRef> framework_code;
OSStatus status = SecStaticCodeCreateWithPath( OSStatus status = SecStaticCodeCreateWithPath(
framework_url, kSecCSDefaultFlags, framework_code.InitializeInto()); framework_url, kSecCSDefaultFlags, framework_code.InitializeInto());
@ -132,18 +132,18 @@ CreateAppShimRequirement() {
if (status != errSecSuccess) { if (status != errSecSuccess) {
DumpOSStatusError(status, "SecStaticCodeCreateWithPath"); DumpOSStatusError(status, "SecStaticCodeCreateWithPath");
// has_value() == true // has_value() == true
return base::ScopedCFTypeRef<SecRequirementRef>(nullptr); return base::apple::ScopedCFTypeRef<SecRequirementRef>(nullptr);
} }
// Copy the signing info from the SecStaticCodeRef. // Copy the signing info from the SecStaticCodeRef.
base::ScopedCFTypeRef<CFDictionaryRef> framework_signing_info; base::apple::ScopedCFTypeRef<CFDictionaryRef> framework_signing_info;
status = SecCodeCopySigningInformation( status = SecCodeCopySigningInformation(
framework_code.get(), kSecCSSigningInformation, framework_code.get(), kSecCSSigningInformation,
framework_signing_info.InitializeInto()); framework_signing_info.InitializeInto());
if (status != errSecSuccess) { if (status != errSecSuccess) {
DumpOSStatusError(status, "SecCodeCopySigningInformation"); DumpOSStatusError(status, "SecCodeCopySigningInformation");
// has_value() == true // has_value() == true
return base::ScopedCFTypeRef<SecRequirementRef>(nullptr); return base::apple::ScopedCFTypeRef<SecRequirementRef>(nullptr);
} }
// Look up the code signing flags. If the flags are absent treat this as // Look up the code signing flags. If the flags are absent treat this as
@ -168,7 +168,7 @@ CreateAppShimRequirement() {
&flags)) { &flags)) {
DumpError("CFNumberGetValue"); DumpError("CFNumberGetValue");
// has_value() == true // has_value() == true
return base::ScopedCFTypeRef<SecRequirementRef>(nullptr); return base::apple::ScopedCFTypeRef<SecRequirementRef>(nullptr);
} }
if (static_cast<uint32_t>(flags) & kSecCodeSignatureAdhoc) { if (static_cast<uint32_t>(flags) & kSecCodeSignatureAdhoc) {
return absl::nullopt; // has_value() == false return absl::nullopt; // has_value() == false
@ -178,24 +178,24 @@ CreateAppShimRequirement() {
// validate the app shim's code signature. First let's get the framework // validate the app shim's code signature. First let's get the framework
// bundle requirement. We will build a suitable requirement for the app shim // bundle requirement. We will build a suitable requirement for the app shim
// based off that. // based off that.
base::ScopedCFTypeRef<SecRequirementRef> framework_requirement; base::apple::ScopedCFTypeRef<SecRequirementRef> framework_requirement;
status = status =
SecCodeCopyDesignatedRequirement(framework_code, kSecCSDefaultFlags, SecCodeCopyDesignatedRequirement(framework_code, kSecCSDefaultFlags,
framework_requirement.InitializeInto()); framework_requirement.InitializeInto());
if (status != errSecSuccess) { if (status != errSecSuccess) {
DumpOSStatusError(status, "SecCodeCopyDesignatedRequirement"); DumpOSStatusError(status, "SecCodeCopyDesignatedRequirement");
// has_value() == true // has_value() == true
return base::ScopedCFTypeRef<SecRequirementRef>(nullptr); return base::apple::ScopedCFTypeRef<SecRequirementRef>(nullptr);
} }
base::ScopedCFTypeRef<CFStringRef> framework_requirement_string; base::apple::ScopedCFTypeRef<CFStringRef> framework_requirement_string;
status = status =
SecRequirementCopyString(framework_requirement, kSecCSDefaultFlags, SecRequirementCopyString(framework_requirement, kSecCSDefaultFlags,
framework_requirement_string.InitializeInto()); framework_requirement_string.InitializeInto());
if (status != errSecSuccess) { if (status != errSecSuccess) {
DumpOSStatusError(status, "SecRequirementCopyString"); DumpOSStatusError(status, "SecRequirementCopyString");
// has_value() == true // has_value() == true
return base::ScopedCFTypeRef<SecRequirementRef>(nullptr); return base::apple::ScopedCFTypeRef<SecRequirementRef>(nullptr);
} }
// Always returns has_value() == true. // Always returns has_value() == true.
@ -212,7 +212,7 @@ CreateAppShimRequirement() {
// requirement). // requirement).
bool IsAcceptablyCodeSignedInternal(pid_t app_shim_pid) { bool IsAcceptablyCodeSignedInternal(pid_t app_shim_pid) {
static base::NoDestructor< static base::NoDestructor<
absl::optional<base::ScopedCFTypeRef<SecRequirementRef>>> absl::optional<base::apple::ScopedCFTypeRef<SecRequirementRef>>>
app_shim_requirement(CreateAppShimRequirement()); app_shim_requirement(CreateAppShimRequirement());
if (!app_shim_requirement->has_value()) { if (!app_shim_requirement->has_value()) {
// App shim validation is not required because framework bundle is not // App shim validation is not required because framework bundle is not
@ -229,15 +229,16 @@ bool IsAcceptablyCodeSignedInternal(pid_t app_shim_pid) {
} }
// Verify the app shim. // Verify the app shim.
base::ScopedCFTypeRef<CFNumberRef> app_shim_pid_cf( base::apple::ScopedCFTypeRef<CFNumberRef> app_shim_pid_cf(
CFNumberCreate(nullptr, kCFNumberIntType, &app_shim_pid)); CFNumberCreate(nullptr, kCFNumberIntType, &app_shim_pid));
const void* app_shim_attribute_keys[] = {kSecGuestAttributePid}; const void* app_shim_attribute_keys[] = {kSecGuestAttributePid};
const void* app_shim_attribute_values[] = {app_shim_pid_cf}; const void* app_shim_attribute_values[] = {app_shim_pid_cf};
base::ScopedCFTypeRef<CFDictionaryRef> app_shim_attributes(CFDictionaryCreate( base::apple::ScopedCFTypeRef<CFDictionaryRef> app_shim_attributes(
nullptr, app_shim_attribute_keys, app_shim_attribute_values, CFDictionaryCreate(
std::size(app_shim_attribute_keys), &kCFTypeDictionaryKeyCallBacks, nullptr, app_shim_attribute_keys, app_shim_attribute_values,
&kCFTypeDictionaryValueCallBacks)); std::size(app_shim_attribute_keys), &kCFTypeDictionaryKeyCallBacks,
base::ScopedCFTypeRef<SecCodeRef> app_shim_code; &kCFTypeDictionaryValueCallBacks));
base::apple::ScopedCFTypeRef<SecCodeRef> app_shim_code;
OSStatus status = SecCodeCopyGuestWithAttributes( OSStatus status = SecCodeCopyGuestWithAttributes(
nullptr, app_shim_attributes, kSecCSDefaultFlags, nullptr, app_shim_attributes, kSecCSDefaultFlags,
app_shim_code.InitializeInto()); app_shim_code.InitializeInto());
@ -1667,7 +1668,7 @@ bool AppShimManager::LoadAndLaunchAppParams::HasFilesOrURLs() const {
return !files.empty() || !urls.empty() || !override_url.is_empty(); return !files.empty() || !urls.empty() || !override_url.is_empty();
} }
base::ScopedCFTypeRef<SecRequirementRef> base::apple::ScopedCFTypeRef<SecRequirementRef>
AppShimManager::BuildAppShimRequirementFromFrameworkRequirementString( AppShimManager::BuildAppShimRequirementFromFrameworkRequirementString(
CFStringRef framwork_requirement) { CFStringRef framwork_requirement) {
// Make sure the framework bundle requirement is in the expected format. // Make sure the framework bundle requirement is in the expected format.
@ -1676,13 +1677,13 @@ AppShimManager::BuildAppShimRequirementFromFrameworkRequirementString(
// we can swap in the desired app shim identifier leaving rest of the // we can swap in the desired app shim identifier leaving rest of the
// requirement unmodified. // requirement unmodified.
CFIndex len = CFStringGetLength(framwork_requirement); CFIndex len = CFStringGetLength(framwork_requirement);
base::ScopedCFTypeRef<CFArrayRef> quote_ranges( base::apple::ScopedCFTypeRef<CFArrayRef> quote_ranges(
CFStringCreateArrayWithFindResults(nullptr, framwork_requirement, CFStringCreateArrayWithFindResults(nullptr, framwork_requirement,
CFSTR("\""), CFRangeMake(0, len), 0)); CFSTR("\""), CFRangeMake(0, len), 0));
if (!CFStringHasPrefix(framwork_requirement, CFSTR("identifier \"")) || if (!CFStringHasPrefix(framwork_requirement, CFSTR("identifier \"")) ||
!quote_ranges || CFArrayGetCount(quote_ranges) < 2) { !quote_ranges || CFArrayGetCount(quote_ranges) < 2) {
DumpError("Framework bundle requirement is malformed."); DumpError("Framework bundle requirement is malformed.");
return base::ScopedCFTypeRef<SecRequirementRef>(nullptr); return base::apple::ScopedCFTypeRef<SecRequirementRef>(nullptr);
} }
// Get the index of the second quote. // Get the index of the second quote.
@ -1693,22 +1694,22 @@ AppShimManager::BuildAppShimRequirementFromFrameworkRequirementString(
// Make sure there is something to read after the second quote. // Make sure there is something to read after the second quote.
if (second_quote_index + 1 >= len) { if (second_quote_index + 1 >= len) {
DumpError("Framework bundle requirement is too short"); DumpError("Framework bundle requirement is too short");
return base::ScopedCFTypeRef<SecRequirementRef>(nullptr); return base::apple::ScopedCFTypeRef<SecRequirementRef>(nullptr);
} }
// Build the app shim requirement. Keep the data from the framework bundle // Build the app shim requirement. Keep the data from the framework bundle
// requirement starting after second quote. // requirement starting after second quote.
base::ScopedCFTypeRef<CFStringRef> right_of_second_quote( base::apple::ScopedCFTypeRef<CFStringRef> right_of_second_quote(
CFStringCreateWithSubstring( CFStringCreateWithSubstring(
nullptr, framwork_requirement, nullptr, framwork_requirement,
CFRangeMake(second_quote_index + 1, len - second_quote_index - 1))); CFRangeMake(second_quote_index + 1, len - second_quote_index - 1)));
base::ScopedCFTypeRef<CFMutableStringRef> shim_requirement_string( base::apple::ScopedCFTypeRef<CFMutableStringRef> shim_requirement_string(
CFStringCreateMutableCopy(nullptr, 0, CFStringCreateMutableCopy(nullptr, 0,
CFSTR("identifier \"app_mode_loader\""))); CFSTR("identifier \"app_mode_loader\"")));
CFStringAppend(shim_requirement_string, right_of_second_quote); CFStringAppend(shim_requirement_string, right_of_second_quote);
// Parse the requirement. // Parse the requirement.
base::ScopedCFTypeRef<SecRequirementRef> shim_requirement; base::apple::ScopedCFTypeRef<SecRequirementRef> shim_requirement;
OSStatus status = SecRequirementCreateWithString( OSStatus status = SecRequirementCreateWithString(
shim_requirement_string, kSecCSDefaultFlags, shim_requirement_string, kSecCSDefaultFlags,
shim_requirement.InitializeInto()); shim_requirement.InitializeInto());
@ -1716,7 +1717,7 @@ AppShimManager::BuildAppShimRequirementFromFrameworkRequirementString(
DumpOSStatusError(status, DumpOSStatusError(status,
std::string("SecRequirementCreateWithString: ") + std::string("SecRequirementCreateWithString: ") +
base::SysCFStringRefToUTF8(shim_requirement_string)); base::SysCFStringRefToUTF8(shim_requirement_string));
return base::ScopedCFTypeRef<SecRequirementRef>(nullptr); return base::apple::ScopedCFTypeRef<SecRequirementRef>(nullptr);
} }
return shim_requirement; return shim_requirement;
} }

@ -231,7 +231,7 @@ class AppShimManager
// AvatarMenuObserver: // AvatarMenuObserver:
void OnAvatarMenuChanged(AvatarMenu* menu) override; void OnAvatarMenuChanged(AvatarMenu* menu) override;
static base::ScopedCFTypeRef<SecRequirementRef> static base::apple::ScopedCFTypeRef<SecRequirementRef>
BuildAppShimRequirementFromFrameworkRequirementString(CFStringRef); BuildAppShimRequirementFromFrameworkRequirementString(CFStringRef);
class AppShimObserver { class AppShimObserver {

@ -1790,11 +1790,11 @@ TEST_F(AppShimManagerTest,
"apple generic and certificate 1[field.1.2.840.113635.100.6.2.6] /* " "apple generic and certificate 1[field.1.2.840.113635.100.6.2.6] /* "
"exists */ and certificate leaf[field.1.2.840.113635.100.6.1.13] " "exists */ and certificate leaf[field.1.2.840.113635.100.6.1.13] "
"/* exists */ and certificate leaf[subject.OU] = EQHXZ8M8AV"); "/* exists */ and certificate leaf[subject.OU] = EQHXZ8M8AV");
base::ScopedCFTypeRef<SecRequirementRef> got_req( base::apple::ScopedCFTypeRef<SecRequirementRef> got_req(
manager_->BuildAppShimRequirementFromFrameworkRequirementString( manager_->BuildAppShimRequirementFromFrameworkRequirementString(
framework_req_string)); framework_req_string));
ASSERT_TRUE(got_req); ASSERT_TRUE(got_req);
base::ScopedCFTypeRef<CFStringRef> got_req_string; base::apple::ScopedCFTypeRef<CFStringRef> got_req_string;
ASSERT_EQ(SecRequirementCopyString(got_req, kSecCSDefaultFlags, ASSERT_EQ(SecRequirementCopyString(got_req, kSecCSDefaultFlags,
got_req_string.InitializeInto()), got_req_string.InitializeInto()),
errSecSuccess); errSecSuccess);

@ -24,11 +24,11 @@ class MockSecureEnclaveClient : public SecureEnclaveClient {
MockSecureEnclaveClient(); MockSecureEnclaveClient();
~MockSecureEnclaveClient() override; ~MockSecureEnclaveClient() override;
MOCK_METHOD(base::ScopedCFTypeRef<SecKeyRef>, MOCK_METHOD(base::apple::ScopedCFTypeRef<SecKeyRef>,
CreatePermanentKey, CreatePermanentKey,
(), (),
(override)); (override));
MOCK_METHOD(base::ScopedCFTypeRef<SecKeyRef>, MOCK_METHOD(base::apple::ScopedCFTypeRef<SecKeyRef>,
CopyStoredKey, CopyStoredKey,
(KeyType), (KeyType),
(override)); (override));

@ -21,11 +21,11 @@ class MockSecureEnclaveHelper : public SecureEnclaveHelper {
MockSecureEnclaveHelper(); MockSecureEnclaveHelper();
~MockSecureEnclaveHelper() override; ~MockSecureEnclaveHelper() override;
MOCK_METHOD(base::ScopedCFTypeRef<SecKeyRef>, MOCK_METHOD(base::apple::ScopedCFTypeRef<SecKeyRef>,
CreateSecureKey, CreateSecureKey,
(CFDictionaryRef, OSStatus*), (CFDictionaryRef, OSStatus*),
(override)); (override));
MOCK_METHOD(base::ScopedCFTypeRef<SecKeyRef>, MOCK_METHOD(base::apple::ScopedCFTypeRef<SecKeyRef>,
CopyKey, CopyKey,
(CFDictionaryRef, OSStatus*), (CFDictionaryRef, OSStatus*),
(override)); (override));

@ -43,11 +43,12 @@ class SecureEnclaveClient {
base::span<const uint8_t> wrapped_key_label); base::span<const uint8_t> wrapped_key_label);
// Creates a new Secure Enclave private key with a permanent key label. // Creates a new Secure Enclave private key with a permanent key label.
virtual base::ScopedCFTypeRef<SecKeyRef> CreatePermanentKey() = 0; virtual base::apple::ScopedCFTypeRef<SecKeyRef> CreatePermanentKey() = 0;
// Queries for the secure key using its label determined by the key `type`. // Queries for the secure key using its label determined by the key `type`.
// Returns the secure key reference or a nullptr if no key was found. // Returns the secure key reference or a nullptr if no key was found.
virtual base::ScopedCFTypeRef<SecKeyRef> CopyStoredKey(KeyType type) = 0; virtual base::apple::ScopedCFTypeRef<SecKeyRef> CopyStoredKey(
KeyType type) = 0;
// Deletes any key stored in `new_key_type` and updates the private key // Deletes any key stored in `new_key_type` and updates the private key
// storage in `current_key_type` to `new_key_type` and modifies the key label // storage in `current_key_type` to `new_key_type` and modifies the key label

@ -27,8 +27,8 @@ class SecureEnclaveClientImpl : public SecureEnclaveClient {
~SecureEnclaveClientImpl() override; ~SecureEnclaveClientImpl() override;
// SecureEnclaveClient: // SecureEnclaveClient:
base::ScopedCFTypeRef<SecKeyRef> CreatePermanentKey() override; base::apple::ScopedCFTypeRef<SecKeyRef> CreatePermanentKey() override;
base::ScopedCFTypeRef<SecKeyRef> CopyStoredKey(KeyType type) override; base::apple::ScopedCFTypeRef<SecKeyRef> CopyStoredKey(KeyType type) override;
bool UpdateStoredKeyLabel(KeyType current_key_type, bool UpdateStoredKeyLabel(KeyType current_key_type,
KeyType new_key_type) override; KeyType new_key_type) override;
bool DeleteKey(KeyType type) override; bool DeleteKey(KeyType type) override;

@ -56,8 +56,8 @@ base::StringPiece GetLabelFromKeyType(SecureEnclaveClient::KeyType type) {
// Creates and returns the secure enclave private key attributes used // Creates and returns the secure enclave private key attributes used
// for key creation. These key attributes represent the key created in // for key creation. These key attributes represent the key created in
// the permanent key location. // the permanent key location.
base::ScopedCFTypeRef<CFMutableDictionaryRef> CreateAttributesForKey() { base::apple::ScopedCFTypeRef<CFMutableDictionaryRef> CreateAttributesForKey() {
base::ScopedCFTypeRef<CFMutableDictionaryRef> attributes( base::apple::ScopedCFTypeRef<CFMutableDictionaryRef> attributes(
CFDictionaryCreateMutable(kCFAllocatorDefault, 0, CFDictionaryCreateMutable(kCFAllocatorDefault, 0,
&kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks)); &kCFTypeDictionaryValueCallBacks));
@ -75,13 +75,13 @@ base::ScopedCFTypeRef<CFMutableDictionaryRef> CreateAttributesForKey() {
attributes, kSecAttrLabel, attributes, kSecAttrLabel,
base::SysUTF8ToCFStringRef(constants::kDeviceTrustSigningKeyLabel)); base::SysUTF8ToCFStringRef(constants::kDeviceTrustSigningKeyLabel));
base::ScopedCFTypeRef<CFMutableDictionaryRef> private_key_params( base::apple::ScopedCFTypeRef<CFMutableDictionaryRef> private_key_params(
CFDictionaryCreateMutable(kCFAllocatorDefault, 0, CFDictionaryCreateMutable(kCFAllocatorDefault, 0,
&kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks)); &kCFTypeDictionaryValueCallBacks));
CFDictionarySetValue(attributes, kSecPrivateKeyAttrs, private_key_params); CFDictionarySetValue(attributes, kSecPrivateKeyAttrs, private_key_params);
CFDictionarySetValue(private_key_params, kSecAttrIsPermanent, kCFBooleanTrue); CFDictionarySetValue(private_key_params, kSecAttrIsPermanent, kCFBooleanTrue);
base::ScopedCFTypeRef<SecAccessControlRef> access_control( base::apple::ScopedCFTypeRef<SecAccessControlRef> access_control(
SecAccessControlCreateWithFlags( SecAccessControlCreateWithFlags(
kCFAllocatorDefault, kCFAllocatorDefault,
// Private key can only be used when the device is unlocked. // Private key can only be used when the device is unlocked.
@ -95,11 +95,12 @@ base::ScopedCFTypeRef<CFMutableDictionaryRef> CreateAttributesForKey() {
// Creates the query used for querying the keychain for the secure key // Creates the query used for querying the keychain for the secure key
// reference. // reference.
base::ScopedCFTypeRef<CFMutableDictionaryRef> CreateQueryForKey( base::apple::ScopedCFTypeRef<CFMutableDictionaryRef> CreateQueryForKey(
SecureEnclaveClient::KeyType type) { SecureEnclaveClient::KeyType type) {
base::ScopedCFTypeRef<CFMutableDictionaryRef> query(CFDictionaryCreateMutable( base::apple::ScopedCFTypeRef<CFMutableDictionaryRef> query(
kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, CFDictionaryCreateMutable(kCFAllocatorDefault, 0,
&kCFTypeDictionaryValueCallBacks)); &kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks));
CFDictionarySetValue(query, kSecClass, kSecClassKey); CFDictionarySetValue(query, kSecClass, kSecClassKey);
CFDictionarySetValue(query, kSecAttrKeyType, kSecAttrKeyTypeECSECPrimeRandom); CFDictionarySetValue(query, kSecAttrKeyType, kSecAttrKeyTypeECSECPrimeRandom);
CFDictionarySetValue(query, kSecAttrLabel, CFDictionarySetValue(query, kSecAttrLabel,
@ -118,10 +119,11 @@ SecureEnclaveClientImpl::SecureEnclaveClientImpl()
SecureEnclaveClientImpl::~SecureEnclaveClientImpl() = default; SecureEnclaveClientImpl::~SecureEnclaveClientImpl() = default;
base::ScopedCFTypeRef<SecKeyRef> SecureEnclaveClientImpl::CreatePermanentKey() { base::apple::ScopedCFTypeRef<SecKeyRef>
SecureEnclaveClientImpl::CreatePermanentKey() {
auto attributes = CreateAttributesForKey(); auto attributes = CreateAttributesForKey();
if (!attributes) if (!attributes)
return base::ScopedCFTypeRef<SecKeyRef>(); return base::apple::ScopedCFTypeRef<SecKeyRef>();
// Deletes a permanent Secure Enclave key if it exists from a previous // Deletes a permanent Secure Enclave key if it exists from a previous
// key rotation. // key rotation.
@ -137,7 +139,7 @@ base::ScopedCFTypeRef<SecKeyRef> SecureEnclaveClientImpl::CreatePermanentKey() {
return key; return key;
} }
base::ScopedCFTypeRef<SecKeyRef> SecureEnclaveClientImpl::CopyStoredKey( base::apple::ScopedCFTypeRef<SecKeyRef> SecureEnclaveClientImpl::CopyStoredKey(
KeyType type) { KeyType type) {
OSStatus status; OSStatus status;
auto key_ref = helper_->CopyKey(CreateQueryForKey(type), &status); auto key_ref = helper_->CopyKey(CreateQueryForKey(type), &status);
@ -153,7 +155,7 @@ bool SecureEnclaveClientImpl::UpdateStoredKeyLabel(KeyType current_key_type,
// Deletes the `new_key_type` label if it exists in the keychain. // Deletes the `new_key_type` label if it exists in the keychain.
DeleteKey(new_key_type); DeleteKey(new_key_type);
base::ScopedCFTypeRef<CFMutableDictionaryRef> attributes_to_update( base::apple::ScopedCFTypeRef<CFMutableDictionaryRef> attributes_to_update(
CFDictionaryCreateMutable(kCFAllocatorDefault, 0, CFDictionaryCreateMutable(kCFAllocatorDefault, 0,
&kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks)); &kCFTypeDictionaryValueCallBacks));
@ -202,10 +204,10 @@ bool SecureEnclaveClientImpl::GetStoredKeyLabel(KeyType type,
bool SecureEnclaveClientImpl::ExportPublicKey(SecKeyRef key, bool SecureEnclaveClientImpl::ExportPublicKey(SecKeyRef key,
std::vector<uint8_t>& output) { std::vector<uint8_t>& output) {
base::ScopedCFTypeRef<SecKeyRef> public_key = base::apple::ScopedCFTypeRef<SecKeyRef> public_key =
base::ScopedCFTypeRef<SecKeyRef>(SecKeyCopyPublicKey(key)); base::apple::ScopedCFTypeRef<SecKeyRef>(SecKeyCopyPublicKey(key));
base::ScopedCFTypeRef<CFErrorRef> error; base::apple::ScopedCFTypeRef<CFErrorRef> error;
base::ScopedCFTypeRef<CFDataRef> data_ref( base::apple::ScopedCFTypeRef<CFDataRef> data_ref(
SecKeyCopyExternalRepresentation(public_key, error.InitializeInto())); SecKeyCopyExternalRepresentation(public_key, error.InitializeInto()));
if (!data_ref) if (!data_ref)
@ -244,12 +246,12 @@ bool SecureEnclaveClientImpl::ExportPublicKey(SecKeyRef key,
bool SecureEnclaveClientImpl::SignDataWithKey(SecKeyRef key, bool SecureEnclaveClientImpl::SignDataWithKey(SecKeyRef key,
base::span<const uint8_t> data, base::span<const uint8_t> data,
std::vector<uint8_t>& output) { std::vector<uint8_t>& output) {
base::ScopedCFTypeRef<CFDataRef> data_ref( base::apple::ScopedCFTypeRef<CFDataRef> data_ref(
CFDataCreate(kCFAllocatorDefault, data.data(), CFDataCreate(kCFAllocatorDefault, data.data(),
base::checked_cast<CFIndex>(data.size()))); base::checked_cast<CFIndex>(data.size())));
base::ScopedCFTypeRef<CFErrorRef> error; base::apple::ScopedCFTypeRef<CFErrorRef> error;
base::ScopedCFTypeRef<CFDataRef> signature(SecKeyCreateSignature( base::apple::ScopedCFTypeRef<CFDataRef> signature(SecKeyCreateSignature(
key, kSecKeyAlgorithmECDSASignatureMessageX962SHA256, data_ref, key, kSecKeyAlgorithmECDSASignatureMessageX962SHA256, data_ref,
error.InitializeInto())); error.InitializeInto()));

@ -65,7 +65,7 @@ class SecureEnclaveClientTest : public testing::Test {
// Creates a test key. // Creates a test key.
void CreateAndSetTestKey() { void CreateAndSetTestKey() {
base::ScopedCFTypeRef<CFMutableDictionaryRef> test_attributes( base::apple::ScopedCFTypeRef<CFMutableDictionaryRef> test_attributes(
CFDictionaryCreateMutable(kCFAllocatorDefault, 0, CFDictionaryCreateMutable(kCFAllocatorDefault, 0,
&kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks)); &kCFTypeDictionaryValueCallBacks));
@ -75,7 +75,7 @@ class SecureEnclaveClientTest : public testing::Test {
kSecAttrKeyTypeECSECPrimeRandom); kSecAttrKeyTypeECSECPrimeRandom);
CFDictionarySetValue(test_attributes, kSecAttrKeySizeInBits, CFDictionarySetValue(test_attributes, kSecAttrKeySizeInBits,
base::apple::NSToCFPtrCast(@256)); base::apple::NSToCFPtrCast(@256));
base::ScopedCFTypeRef<CFMutableDictionaryRef> private_key_params( base::apple::ScopedCFTypeRef<CFMutableDictionaryRef> private_key_params(
CFDictionaryCreateMutable(kCFAllocatorDefault, 0, CFDictionaryCreateMutable(kCFAllocatorDefault, 0,
&kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks)); &kCFTypeDictionaryValueCallBacks));
@ -83,7 +83,7 @@ class SecureEnclaveClientTest : public testing::Test {
kCFBooleanFalse); kCFBooleanFalse);
CFDictionarySetValue(test_attributes, kSecPrivateKeyAttrs, CFDictionarySetValue(test_attributes, kSecPrivateKeyAttrs,
private_key_params); private_key_params);
test_key_ = base::ScopedCFTypeRef<SecKeyRef>( test_key_ = base::apple::ScopedCFTypeRef<SecKeyRef>(
SecKeyCreateRandomKey(test_attributes, nullptr)); SecKeyCreateRandomKey(test_attributes, nullptr));
} }
@ -99,7 +99,7 @@ class SecureEnclaveClientTest : public testing::Test {
raw_ptr<MockSecureEnclaveHelper, DanglingUntriaged> raw_ptr<MockSecureEnclaveHelper, DanglingUntriaged>
mock_secure_enclave_helper_ = nullptr; mock_secure_enclave_helper_ = nullptr;
std::unique_ptr<SecureEnclaveClient> secure_enclave_client_; std::unique_ptr<SecureEnclaveClient> secure_enclave_client_;
base::ScopedCFTypeRef<SecKeyRef> test_key_; base::apple::ScopedCFTypeRef<SecKeyRef> test_key_;
}; };
// Tests that the CreatePermanentKey method invokes both the SE helper's // Tests that the CreatePermanentKey method invokes both the SE helper's
@ -165,7 +165,7 @@ TEST_F(SecureEnclaveClientTest, CreateKey_Failure) {
.Times(1) .Times(1)
.WillOnce([](CFDictionaryRef attributes, OSStatus* status) { .WillOnce([](CFDictionaryRef attributes, OSStatus* status) {
*status = errSecItemNotFound; *status = errSecItemNotFound;
return base::ScopedCFTypeRef<SecKeyRef>(); return base::apple::ScopedCFTypeRef<SecKeyRef>();
}); });
EXPECT_FALSE(secure_enclave_client_->CreatePermanentKey()); EXPECT_FALSE(secure_enclave_client_->CreatePermanentKey());
@ -214,7 +214,7 @@ TEST_F(SecureEnclaveClientTest, CopyStoredKey_KeyNotFound) {
.Times(2) .Times(2)
.WillRepeatedly([](CFDictionaryRef query, OSStatus* status) { .WillRepeatedly([](CFDictionaryRef query, OSStatus* status) {
*status = errSecItemNotFound; *status = errSecItemNotFound;
return base::ScopedCFTypeRef<SecKeyRef>(); return base::apple::ScopedCFTypeRef<SecKeyRef>();
}); });
EXPECT_FALSE(secure_enclave_client_->CopyStoredKey( EXPECT_FALSE(secure_enclave_client_->CopyStoredKey(
SecureEnclaveClient::KeyType::kPermanent)); SecureEnclaveClient::KeyType::kPermanent));
@ -506,7 +506,7 @@ TEST_F(SecureEnclaveClientTest, GetStoredKeyLabel_TemporaryKeyNotFound) {
.Times(1) .Times(1)
.WillOnce([](CFDictionaryRef query, OSStatus* status) { .WillOnce([](CFDictionaryRef query, OSStatus* status) {
*status = errSecItemNotFound; *status = errSecItemNotFound;
return base::ScopedCFTypeRef<SecKeyRef>(); return base::apple::ScopedCFTypeRef<SecKeyRef>();
}); });
EXPECT_FALSE(secure_enclave_client_->GetStoredKeyLabel( EXPECT_FALSE(secure_enclave_client_->GetStoredKeyLabel(
SecureEnclaveClient::KeyType::kTemporary, output)); SecureEnclaveClient::KeyType::kTemporary, output));
@ -565,7 +565,7 @@ TEST_F(SecureEnclaveClientTest, GetStoredKeyLabel_PermanentKeyNotFound) {
.Times(1) .Times(1)
.WillOnce([](CFDictionaryRef query, OSStatus* status) { .WillOnce([](CFDictionaryRef query, OSStatus* status) {
*status = errSecItemNotFound; *status = errSecItemNotFound;
return base::ScopedCFTypeRef<SecKeyRef>(); return base::apple::ScopedCFTypeRef<SecKeyRef>();
}); });
EXPECT_FALSE(secure_enclave_client_->GetStoredKeyLabel( EXPECT_FALSE(secure_enclave_client_->GetStoredKeyLabel(
SecureEnclaveClient::KeyType::kPermanent, output)); SecureEnclaveClient::KeyType::kPermanent, output));

@ -29,7 +29,7 @@ class SecureEnclaveHelper {
// `attributes`. Returns the key or a nullptr on failure. If an `error` // `attributes`. Returns the key or a nullptr on failure. If an `error`
// pointer is given, its value will be set to the OSStatus returned by the // pointer is given, its value will be set to the OSStatus returned by the
// Keychain API call. // Keychain API call.
virtual base::ScopedCFTypeRef<SecKeyRef> CreateSecureKey( virtual base::apple::ScopedCFTypeRef<SecKeyRef> CreateSecureKey(
CFDictionaryRef attributes, CFDictionaryRef attributes,
OSStatus* error) = 0; OSStatus* error) = 0;
@ -38,8 +38,8 @@ class SecureEnclaveHelper {
// if the key is not found. If an `error` pointer // if the key is not found. If an `error` pointer
// is given, its value will be set to the OSStatus returned by the Keychain // is given, its value will be set to the OSStatus returned by the Keychain
// API call. // API call.
virtual base::ScopedCFTypeRef<SecKeyRef> CopyKey(CFDictionaryRef query, virtual base::apple::ScopedCFTypeRef<SecKeyRef> CopyKey(CFDictionaryRef query,
OSStatus* error) = 0; OSStatus* error) = 0;
// Uses the SecItemUpdate API to update the the key retrieved with the // Uses the SecItemUpdate API to update the the key retrieved with the
// `query` with its `attributes_to_update`. Returns the OSStatus value // `query` with its `attributes_to_update`. Returns the OSStatus value

@ -20,10 +20,11 @@ class SecureEnclaveHelperImpl : public SecureEnclaveHelper {
~SecureEnclaveHelperImpl() override; ~SecureEnclaveHelperImpl() override;
// SecureEnclaveHelper: // SecureEnclaveHelper:
base::ScopedCFTypeRef<SecKeyRef> CreateSecureKey(CFDictionaryRef attributes, base::apple::ScopedCFTypeRef<SecKeyRef> CreateSecureKey(
OSStatus* error) override; CFDictionaryRef attributes,
base::ScopedCFTypeRef<SecKeyRef> CopyKey(CFDictionaryRef query, OSStatus* error) override;
OSStatus* error) override; base::apple::ScopedCFTypeRef<SecKeyRef> CopyKey(CFDictionaryRef query,
OSStatus* error) override;
OSStatus Update(CFDictionaryRef query, OSStatus Update(CFDictionaryRef query,
CFDictionaryRef attributes_to_update) override; CFDictionaryRef attributes_to_update) override;
OSStatus Delete(CFDictionaryRef query) override; OSStatus Delete(CFDictionaryRef query) override;

@ -17,11 +17,11 @@ namespace enterprise_connectors {
SecureEnclaveHelperImpl::~SecureEnclaveHelperImpl() = default; SecureEnclaveHelperImpl::~SecureEnclaveHelperImpl() = default;
base::ScopedCFTypeRef<SecKeyRef> SecureEnclaveHelperImpl::CreateSecureKey( base::apple::ScopedCFTypeRef<SecKeyRef>
CFDictionaryRef attributes, SecureEnclaveHelperImpl::CreateSecureKey(CFDictionaryRef attributes,
OSStatus* error) { OSStatus* error) {
base::ScopedCFTypeRef<CFErrorRef> error_ref; base::apple::ScopedCFTypeRef<CFErrorRef> error_ref;
base::ScopedCFTypeRef<SecKeyRef> key( base::apple::ScopedCFTypeRef<SecKeyRef> key(
SecKeyCreateRandomKey(attributes, error_ref.InitializeInto())); SecKeyCreateRandomKey(attributes, error_ref.InitializeInto()));
if (error && error_ref) { if (error && error_ref) {
@ -31,10 +31,10 @@ base::ScopedCFTypeRef<SecKeyRef> SecureEnclaveHelperImpl::CreateSecureKey(
return key; return key;
} }
base::ScopedCFTypeRef<SecKeyRef> SecureEnclaveHelperImpl::CopyKey( base::apple::ScopedCFTypeRef<SecKeyRef> SecureEnclaveHelperImpl::CopyKey(
CFDictionaryRef query, CFDictionaryRef query,
OSStatus* error) { OSStatus* error) {
base::ScopedCFTypeRef<SecKeyRef> key; base::apple::ScopedCFTypeRef<SecKeyRef> key;
OSStatus status = SecItemCopyMatching( OSStatus status = SecItemCopyMatching(
query, const_cast<CFTypeRef*>( query, const_cast<CFTypeRef*>(
reinterpret_cast<const CFTypeRef*>(key.InitializeInto()))); reinterpret_cast<const CFTypeRef*>(key.InitializeInto())));

@ -23,7 +23,7 @@ namespace {
// An implementation of crypto::UnexportableSigningKey. // An implementation of crypto::UnexportableSigningKey.
class SecureEnclaveSigningKey : public crypto::UnexportableSigningKey { class SecureEnclaveSigningKey : public crypto::UnexportableSigningKey {
public: public:
SecureEnclaveSigningKey(base::ScopedCFTypeRef<SecKeyRef> key, SecureEnclaveSigningKey(base::apple::ScopedCFTypeRef<SecKeyRef> key,
std::unique_ptr<SecureEnclaveClient> client, std::unique_ptr<SecureEnclaveClient> client,
SecureEnclaveClient::KeyType type); SecureEnclaveClient::KeyType type);
~SecureEnclaveSigningKey() override; ~SecureEnclaveSigningKey() override;
@ -36,13 +36,13 @@ class SecureEnclaveSigningKey : public crypto::UnexportableSigningKey {
base::span<const uint8_t> data) override; base::span<const uint8_t> data) override;
private: private:
base::ScopedCFTypeRef<SecKeyRef> key_; base::apple::ScopedCFTypeRef<SecKeyRef> key_;
std::unique_ptr<SecureEnclaveClient> client_; std::unique_ptr<SecureEnclaveClient> client_;
SecureEnclaveClient::KeyType key_type_; SecureEnclaveClient::KeyType key_type_;
}; };
SecureEnclaveSigningKey::SecureEnclaveSigningKey( SecureEnclaveSigningKey::SecureEnclaveSigningKey(
base::ScopedCFTypeRef<SecKeyRef> key, base::apple::ScopedCFTypeRef<SecKeyRef> key,
std::unique_ptr<SecureEnclaveClient> client, std::unique_ptr<SecureEnclaveClient> client,
SecureEnclaveClient::KeyType type) SecureEnclaveClient::KeyType type)
: key_(std::move(key)), client_(std::move(client)), key_type_(type) { : key_(std::move(key)), client_(std::move(client)), key_type_(type) {

@ -43,7 +43,7 @@ class SecureEnclaveSigningKeyTest : public testing::Test {
protected: protected:
// Creates a test key. // Creates a test key.
void CreateTestKey() { void CreateTestKey() {
base::ScopedCFTypeRef<CFMutableDictionaryRef> test_attributes( base::apple::ScopedCFTypeRef<CFMutableDictionaryRef> test_attributes(
CFDictionaryCreateMutable(kCFAllocatorDefault, 0, CFDictionaryCreateMutable(kCFAllocatorDefault, 0,
&kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks)); &kCFTypeDictionaryValueCallBacks));
@ -52,7 +52,7 @@ class SecureEnclaveSigningKeyTest : public testing::Test {
kSecAttrKeyTypeECSECPrimeRandom); kSecAttrKeyTypeECSECPrimeRandom);
CFDictionarySetValue(test_attributes, kSecAttrKeySizeInBits, CFDictionarySetValue(test_attributes, kSecAttrKeySizeInBits,
base::apple::NSToCFPtrCast(@256)); base::apple::NSToCFPtrCast(@256));
base::ScopedCFTypeRef<CFMutableDictionaryRef> private_key_params( base::apple::ScopedCFTypeRef<CFMutableDictionaryRef> private_key_params(
CFDictionaryCreateMutable(kCFAllocatorDefault, 0, CFDictionaryCreateMutable(kCFAllocatorDefault, 0,
&kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks)); &kCFTypeDictionaryValueCallBacks));
@ -60,7 +60,7 @@ class SecureEnclaveSigningKeyTest : public testing::Test {
kCFBooleanFalse); kCFBooleanFalse);
CFDictionarySetValue(test_attributes, kSecPrivateKeyAttrs, CFDictionarySetValue(test_attributes, kSecPrivateKeyAttrs,
private_key_params); private_key_params);
test_key_ = base::ScopedCFTypeRef<SecKeyRef>( test_key_ = base::apple::ScopedCFTypeRef<SecKeyRef>(
SecKeyCreateRandomKey(test_attributes, nullptr)); SecKeyCreateRandomKey(test_attributes, nullptr));
} }
@ -78,7 +78,7 @@ class SecureEnclaveSigningKeyTest : public testing::Test {
raw_ptr<MockSecureEnclaveClient, DanglingUntriaged> raw_ptr<MockSecureEnclaveClient, DanglingUntriaged>
mock_secure_enclave_client_ = nullptr; mock_secure_enclave_client_ = nullptr;
std::unique_ptr<crypto::UnexportableSigningKey> key_; std::unique_ptr<crypto::UnexportableSigningKey> key_;
base::ScopedCFTypeRef<SecKeyRef> test_key_; base::apple::ScopedCFTypeRef<SecKeyRef> test_key_;
}; };
// Tests that the GenerateSigningKeySlowly method invokes the SE client's // Tests that the GenerateSigningKeySlowly method invokes the SE client's

@ -53,8 +53,8 @@ class MacKeyPersistenceDelegateTest : public testing::Test {
} }
// Creates a test key. // Creates a test key.
base::ScopedCFTypeRef<SecKeyRef> CreateTestKey() { base::apple::ScopedCFTypeRef<SecKeyRef> CreateTestKey() {
base::ScopedCFTypeRef<CFMutableDictionaryRef> test_attributes( base::apple::ScopedCFTypeRef<CFMutableDictionaryRef> test_attributes(
CFDictionaryCreateMutable(kCFAllocatorDefault, 0, CFDictionaryCreateMutable(kCFAllocatorDefault, 0,
&kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks)); &kCFTypeDictionaryValueCallBacks));
@ -63,7 +63,7 @@ class MacKeyPersistenceDelegateTest : public testing::Test {
kSecAttrKeyTypeECSECPrimeRandom); kSecAttrKeyTypeECSECPrimeRandom);
CFDictionarySetValue(test_attributes, kSecAttrKeySizeInBits, CFDictionarySetValue(test_attributes, kSecAttrKeySizeInBits,
base::apple::NSToCFPtrCast(@256)); base::apple::NSToCFPtrCast(@256));
base::ScopedCFTypeRef<CFMutableDictionaryRef> private_key_params( base::apple::ScopedCFTypeRef<CFMutableDictionaryRef> private_key_params(
CFDictionaryCreateMutable(kCFAllocatorDefault, 0, CFDictionaryCreateMutable(kCFAllocatorDefault, 0,
&kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks)); &kCFTypeDictionaryValueCallBacks));
@ -71,7 +71,7 @@ class MacKeyPersistenceDelegateTest : public testing::Test {
kCFBooleanFalse); kCFBooleanFalse);
CFDictionarySetValue(test_attributes, kSecPrivateKeyAttrs, CFDictionarySetValue(test_attributes, kSecPrivateKeyAttrs,
private_key_params); private_key_params);
return base::ScopedCFTypeRef<SecKeyRef>( return base::apple::ScopedCFTypeRef<SecKeyRef>(
SecKeyCreateRandomKey(test_attributes, nullptr)); SecKeyCreateRandomKey(test_attributes, nullptr));
} }
@ -227,7 +227,7 @@ TEST_F(MacKeyPersistenceDelegateTest, CreateKeyPair__EmptySigningKey) {
SetMockClient(); SetMockClient();
EXPECT_CALL(*mock_secure_enclave_client_, CreatePermanentKey()) EXPECT_CALL(*mock_secure_enclave_client_, CreatePermanentKey())
.WillOnce([]() { return base::ScopedCFTypeRef<SecKeyRef>(); }); .WillOnce([]() { return base::apple::ScopedCFTypeRef<SecKeyRef>(); });
EXPECT_FALSE(persistence_delegate_->CreateKeyPair()); EXPECT_FALSE(persistence_delegate_->CreateKeyPair());
} }

@ -170,7 +170,7 @@ int32_t ReadEncryptedSecret(std::string* password, bool force_recreate) {
crypto::AppleKeychain keychain; crypto::AppleKeychain keychain;
UInt32 password_length = 0; UInt32 password_length = 0;
void* password_data = nullptr; void* password_data = nullptr;
base::ScopedCFTypeRef<SecKeychainItemRef> item_ref; base::apple::ScopedCFTypeRef<SecKeychainItemRef> item_ref;
status = keychain.FindGenericPassword( status = keychain.FindGenericPassword(
strlen(kServiceName), kServiceName, strlen(kAccountName), kAccountName, strlen(kServiceName), kServiceName, strlen(kAccountName), kAccountName,
&password_length, &password_data, item_ref.InitializeInto()); &password_length, &password_data, item_ref.InitializeInto());

@ -30,7 +30,7 @@ OSStatus CreateTargetAccess(CFStringRef service_name,
return status; return status;
} }
base::ScopedCFTypeRef<CFArrayRef> acl_list; base::apple::ScopedCFTypeRef<CFArrayRef> acl_list;
status = SecAccessCopyACLList(*access_ref, acl_list.InitializeInto()); status = SecAccessCopyACLList(*access_ref, acl_list.InitializeInto());
if (status != noErr) { if (status != noErr) {
return status; return status;
@ -39,8 +39,8 @@ OSStatus CreateTargetAccess(CFStringRef service_name,
for (CFIndex i = 0; i < CFArrayGetCount(acl_list); ++i) { for (CFIndex i = 0; i < CFArrayGetCount(acl_list); ++i) {
SecACLRef acl = (SecACLRef)CFArrayGetValueAtIndex(acl_list, i); SecACLRef acl = (SecACLRef)CFArrayGetValueAtIndex(acl_list, i);
base::ScopedCFTypeRef<CFArrayRef> app_list; base::apple::ScopedCFTypeRef<CFArrayRef> app_list;
base::ScopedCFTypeRef<CFStringRef> description; base::apple::ScopedCFTypeRef<CFStringRef> description;
SecKeychainPromptSelector dummy_prompt_selector; SecKeychainPromptSelector dummy_prompt_selector;
status = SecACLCopyContents(acl, app_list.InitializeInto(), status = SecACLCopyContents(acl, app_list.InitializeInto(),
description.InitializeInto(), description.InitializeInto(),
@ -93,7 +93,7 @@ OSStatus WriteKeychainItem(const std::string& service_name,
const_cast<char*>(account_name.data())}}; const_cast<char*>(account_name.data())}};
SecKeychainAttributeList attribute_list = {std::size(attributes), attributes}; SecKeychainAttributeList attribute_list = {std::size(attributes), attributes};
base::ScopedCFTypeRef<SecAccessRef> access_ref; base::apple::ScopedCFTypeRef<SecAccessRef> access_ref;
OSStatus status = CreateTargetAccess(base::SysUTF8ToCFStringRef(service_name), OSStatus status = CreateTargetAccess(base::SysUTF8ToCFStringRef(service_name),
access_ref.InitializeInto()); access_ref.InitializeInto());
if (status != noErr) { if (status != noErr) {
@ -107,7 +107,7 @@ OSStatus WriteKeychainItem(const std::string& service_name,
OSStatus VerifyKeychainForItemUnlocked(SecKeychainItemRef item_ref, OSStatus VerifyKeychainForItemUnlocked(SecKeychainItemRef item_ref,
bool* unlocked) { bool* unlocked) {
base::ScopedCFTypeRef<SecKeychainRef> keychain; base::apple::ScopedCFTypeRef<SecKeychainRef> keychain;
OSStatus status = OSStatus status =
SecKeychainItemCopyKeychain(item_ref, keychain.InitializeInto()); SecKeychainItemCopyKeychain(item_ref, keychain.InitializeInto());
if (status != noErr) { if (status != noErr) {
@ -118,7 +118,7 @@ OSStatus VerifyKeychainForItemUnlocked(SecKeychainItemRef item_ref,
} }
OSStatus VerifyDefaultKeychainUnlocked(bool* unlocked) { OSStatus VerifyDefaultKeychainUnlocked(bool* unlocked) {
base::ScopedCFTypeRef<SecKeychainRef> keychain; base::apple::ScopedCFTypeRef<SecKeychainRef> keychain;
OSStatus status = SecKeychainCopyDefault(keychain.InitializeInto()); OSStatus status = SecKeychainCopyDefault(keychain.InitializeInto());
if (status != noErr) { if (status != noErr) {
return status; return status;

@ -27,7 +27,7 @@ RemovableStorageProvider::PopulateDeviceList() {
base::ScopedBlockingCall scoped_blocking_call(FROM_HERE, base::ScopedBlockingCall scoped_blocking_call(FROM_HERE,
base::BlockingType::MAY_BLOCK); base::BlockingType::MAY_BLOCK);
// Match only writable whole-disks. // Match only writable whole-disks.
base::ScopedCFTypeRef<CFMutableDictionaryRef> matching( base::apple::ScopedCFTypeRef<CFMutableDictionaryRef> matching(
IOServiceMatching(kIOMediaClass)); IOServiceMatching(kIOMediaClass));
CFDictionaryAddValue(matching, CFSTR(kIOMediaWholeKey), kCFBooleanTrue); CFDictionaryAddValue(matching, CFSTR(kIOMediaWholeKey), kCFBooleanTrue);
CFDictionaryAddValue(matching, CFSTR(kIOMediaWritableKey), kCFBooleanTrue); CFDictionaryAddValue(matching, CFSTR(kIOMediaWritableKey), kCFBooleanTrue);
@ -54,7 +54,7 @@ RemovableStorageProvider::PopulateDeviceList() {
if (!is_suitable) if (!is_suitable)
continue; continue;
base::ScopedCFTypeRef<CFMutableDictionaryRef> dict; base::apple::ScopedCFTypeRef<CFMutableDictionaryRef> dict;
if (IORegistryEntryCreateCFProperties(disk_obj, dict.InitializeInto(), if (IORegistryEntryCreateCFProperties(disk_obj, dict.InitializeInto(),
kCFAllocatorDefault, kCFAllocatorDefault,
0) != KERN_SUCCESS) { 0) != KERN_SUCCESS) {
@ -62,12 +62,10 @@ RemovableStorageProvider::PopulateDeviceList() {
continue; continue;
} }
base::ScopedCFTypeRef<CFDictionaryRef> characteristics( base::apple::ScopedCFTypeRef<CFDictionaryRef> characteristics(
static_cast<CFDictionaryRef>(IORegistryEntrySearchCFProperty( static_cast<CFDictionaryRef>(IORegistryEntrySearchCFProperty(
disk_obj, disk_obj, kIOServicePlane,
kIOServicePlane, CFSTR(kIOPropertyDeviceCharacteristicsKey), kCFAllocatorDefault,
CFSTR(kIOPropertyDeviceCharacteristicsKey),
kCFAllocatorDefault,
kIORegistryIterateParents | kIORegistryIterateRecursively))); kIORegistryIterateParents | kIORegistryIterateRecursively)));
if (!characteristics) { if (!characteristics) {

@ -62,9 +62,9 @@ IconLoader::IconGroup IconLoader::GroupForFilepath(
// Remove the leading dot. // Remove the leading dot.
extension_string.erase(extension_string.begin()); extension_string.erase(extension_string.begin());
base::ScopedCFTypeRef<CFStringRef> extension_cf = base::apple::ScopedCFTypeRef<CFStringRef> extension_cf =
base::SysUTF8ToCFStringRef(extension_string); base::SysUTF8ToCFStringRef(extension_string);
base::ScopedCFTypeRef<CFStringRef> cftype( base::apple::ScopedCFTypeRef<CFStringRef> cftype(
UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension,
extension_cf, extension_cf,
/*inConformingToUTI=*/nullptr)); /*inConformingToUTI=*/nullptr));

@ -16,7 +16,7 @@
namespace bluetooth_utility { namespace bluetooth_utility {
BluetoothAvailability GetBluetoothAvailability() { BluetoothAvailability GetBluetoothAvailability() {
base::ScopedCFTypeRef<CFMutableDictionaryRef> matching_dict( base::apple::ScopedCFTypeRef<CFMutableDictionaryRef> matching_dict(
IOServiceMatching("IOBluetoothHCIController")); IOServiceMatching("IOBluetoothHCIController"));
if (!matching_dict) if (!matching_dict)
return BLUETOOTH_AVAILABILITY_ERROR; return BLUETOOTH_AVAILABILITY_ERROR;
@ -34,7 +34,7 @@ BluetoothAvailability GetBluetoothAvailability() {
while (device.reset(IOIteratorNext(scoped_iter.get())), device) { while (device.reset(IOIteratorNext(scoped_iter.get())), device) {
bluetooth_available = true; bluetooth_available = true;
base::ScopedCFTypeRef<CFMutableDictionaryRef> dict; base::apple::ScopedCFTypeRef<CFMutableDictionaryRef> dict;
kr = IORegistryEntryCreateCFProperties(device, dict.InitializeInto(), kr = IORegistryEntryCreateCFProperties(device, dict.InitializeInto(),
kCFAllocatorDefault, kNilOptions); kCFAllocatorDefault, kNilOptions);
if (kr != KERN_SUCCESS) if (kr != KERN_SUCCESS)

@ -50,7 +50,7 @@ NSString* const kDockPersistentAppsKey = @"persistent-apps";
// A wrapper around _CFURLCopyPropertyListRepresentation that operates on // A wrapper around _CFURLCopyPropertyListRepresentation that operates on
// Foundation data types and returns an autoreleased NSDictionary. // Foundation data types and returns an autoreleased NSDictionary.
NSDictionary* DockFileDataDictionaryForURL(NSURL* url) { NSDictionary* DockFileDataDictionaryForURL(NSURL* url) {
base::ScopedCFTypeRef<CFPropertyListRef> property_list( base::apple::ScopedCFTypeRef<CFPropertyListRef> property_list(
_CFURLCopyPropertyListRepresentation(base::apple::NSToCFPtrCast(url))); _CFURLCopyPropertyListRepresentation(base::apple::NSToCFPtrCast(url)));
CFDictionaryRef dictionary = CFDictionaryRef dictionary =
base::apple::CFCast<CFDictionaryRef>(property_list); base::apple::CFCast<CFDictionaryRef>(property_list);
@ -64,7 +64,7 @@ NSDictionary* DockFileDataDictionaryForURL(NSURL* url) {
// A wrapper around _CFURLCreateFromPropertyListRepresentation that operates // A wrapper around _CFURLCreateFromPropertyListRepresentation that operates
// on Foundation data types and returns an autoreleased NSURL. // on Foundation data types and returns an autoreleased NSURL.
NSURL* URLFromDockFileDataDictionary(NSDictionary* dictionary) { NSURL* URLFromDockFileDataDictionary(NSDictionary* dictionary) {
base::ScopedCFTypeRef<CFURLRef> url( base::apple::ScopedCFTypeRef<CFURLRef> url(
_CFURLCreateFromPropertyListRepresentation( _CFURLCreateFromPropertyListRepresentation(
kCFAllocatorDefault, base::apple::NSToCFPtrCast(dictionary))); kCFAllocatorDefault, base::apple::NSToCFPtrCast(dictionary)));
if (!url) if (!url)

@ -125,7 +125,7 @@ bool MediaResidesOnDiskImage(base::mac::ScopedIOObject<io_service_t> media,
GetDiskImageAncestorForMedia("AppleDiskImageDevice", media); GetDiskImageAncestorForMedia("AppleDiskImageDevice", media);
if (di_device) { if (di_device) {
if (image_path) { if (image_path) {
base::ScopedCFTypeRef<CFTypeRef> disk_image_url_cftyperef( base::apple::ScopedCFTypeRef<CFTypeRef> disk_image_url_cftyperef(
IORegistryEntryCreateCFProperty(di_device, CFSTR("DiskImageURL"), IORegistryEntryCreateCFProperty(di_device, CFSTR("DiskImageURL"),
/*allocator=*/nullptr, /*allocator=*/nullptr,
/*options=*/0)); /*options=*/0));
@ -138,21 +138,23 @@ bool MediaResidesOnDiskImage(base::mac::ScopedIOObject<io_service_t> media,
CFStringRef disk_image_url_string = CFStringRef disk_image_url_string =
base::apple::CFCast<CFStringRef>(disk_image_url_cftyperef.get()); base::apple::CFCast<CFStringRef>(disk_image_url_cftyperef.get());
if (!disk_image_url_string) { if (!disk_image_url_string) {
base::ScopedCFTypeRef<CFStringRef> observed_type_cf( base::apple::ScopedCFTypeRef<CFStringRef> observed_type_cf(
CFCopyTypeIDDescription(CFGetTypeID(disk_image_url_cftyperef))); CFCopyTypeIDDescription(CFGetTypeID(disk_image_url_cftyperef)));
LOG(ERROR) << "DiskImageURL: expected CFString, observed " LOG(ERROR) << "DiskImageURL: expected CFString, observed "
<< base::SysCFStringRefToUTF8(observed_type_cf); << base::SysCFStringRefToUTF8(observed_type_cf);
return true; return true;
} }
base::ScopedCFTypeRef<CFURLRef> disk_image_url(CFURLCreateWithString( base::apple::ScopedCFTypeRef<CFURLRef> disk_image_url(
/*allocator=*/nullptr, disk_image_url_string, /*baseURL=*/nullptr)); CFURLCreateWithString(
/*allocator=*/nullptr, disk_image_url_string,
/*baseURL=*/nullptr));
if (!disk_image_url) { if (!disk_image_url) {
LOG(ERROR) << "CFURLCreateWithString failed"; LOG(ERROR) << "CFURLCreateWithString failed";
return true; return true;
} }
base::ScopedCFTypeRef<CFStringRef> disk_image_path( base::apple::ScopedCFTypeRef<CFStringRef> disk_image_path(
CFURLCopyFileSystemPath(disk_image_url, kCFURLPOSIXPathStyle)); CFURLCopyFileSystemPath(disk_image_url, kCFURLPOSIXPathStyle));
if (!disk_image_path) { if (!disk_image_path) {
LOG(ERROR) << "CFURLCopyFileSystemPath failed"; LOG(ERROR) << "CFURLCopyFileSystemPath failed";
@ -173,7 +175,7 @@ bool MediaResidesOnDiskImage(base::mac::ScopedIOObject<io_service_t> media,
GetDiskImageAncestorForMedia("IOHDIXHDDrive", media); GetDiskImageAncestorForMedia("IOHDIXHDDrive", media);
if (hdix_drive) { if (hdix_drive) {
if (image_path) { if (image_path) {
base::ScopedCFTypeRef<CFTypeRef> image_path_cftyperef( base::apple::ScopedCFTypeRef<CFTypeRef> image_path_cftyperef(
IORegistryEntryCreateCFProperty(hdix_drive, CFSTR("image-path"), IORegistryEntryCreateCFProperty(hdix_drive, CFSTR("image-path"),
/*allocator=*/nullptr, /*allocator=*/nullptr,
/*options=*/0)); /*options=*/0));
@ -185,7 +187,7 @@ bool MediaResidesOnDiskImage(base::mac::ScopedIOObject<io_service_t> media,
CFDataRef image_path_data = CFDataRef image_path_data =
base::apple::CFCast<CFDataRef>(image_path_cftyperef.get()); base::apple::CFCast<CFDataRef>(image_path_cftyperef.get());
if (!image_path_data) { if (!image_path_data) {
base::ScopedCFTypeRef<CFStringRef> observed_type_cf( base::apple::ScopedCFTypeRef<CFStringRef> observed_type_cf(
CFCopyTypeIDDescription(CFGetTypeID(image_path_cftyperef))); CFCopyTypeIDDescription(CFGetTypeID(image_path_cftyperef)));
LOG(ERROR) << "image-path: expected CFData, observed " LOG(ERROR) << "image-path: expected CFData, observed "
<< base::SysCFStringRefToUTF8(observed_type_cf); << base::SysCFStringRefToUTF8(observed_type_cf);
@ -244,8 +246,9 @@ DiskImageStatus IsPathOnReadOnlyDiskImage(
out_dmg_bsd_device_name->assign(dmg_bsd_device_name); out_dmg_bsd_device_name->assign(dmg_bsd_device_name);
} }
base::ScopedCFTypeRef<CFMutableDictionaryRef> match_dict(IOBSDNameMatching( base::apple::ScopedCFTypeRef<CFMutableDictionaryRef> match_dict(
kIOMasterPortDefault, /*options=*/0, dmg_bsd_device_name)); IOBSDNameMatching(kIOMasterPortDefault, /*options=*/0,
dmg_bsd_device_name));
if (!match_dict) { if (!match_dict) {
LOG(ERROR) << "IOBSDNameMatching " << dmg_bsd_device_name; LOG(ERROR) << "IOBSDNameMatching " << dmg_bsd_device_name;
return DiskImageStatusFailure; return DiskImageStatusFailure;
@ -554,7 +557,7 @@ class ScopedDASessionScheduleWithRunLoop {
// A small structure used to ferry data between SynchronousDAOperation and // A small structure used to ferry data between SynchronousDAOperation and
// SynchronousDACallbackAdapter. // SynchronousDACallbackAdapter.
struct SynchronousDACallbackData { struct SynchronousDACallbackData {
base::ScopedCFTypeRef<DADissenterRef> dissenter; base::apple::ScopedCFTypeRef<DADissenterRef> dissenter;
bool callback_called = false; bool callback_called = false;
bool run_loop_running = false; bool run_loop_running = false;
bool can_log = true; bool can_log = true;
@ -645,14 +648,14 @@ bool SynchronousDADiskEject(DADiskRef disk, DADiskEjectOptions options) {
} // namespace } // namespace
void EjectAndTrashDiskImage(const std::string& dmg_bsd_device_name) { void EjectAndTrashDiskImage(const std::string& dmg_bsd_device_name) {
base::ScopedCFTypeRef<DASessionRef> session( base::apple::ScopedCFTypeRef<DASessionRef> session(
DASessionCreate(/*allocator=*/nullptr)); DASessionCreate(/*allocator=*/nullptr));
if (!session.get()) { if (!session.get()) {
LOG(ERROR) << "DASessionCreate"; LOG(ERROR) << "DASessionCreate";
return; return;
} }
base::ScopedCFTypeRef<DADiskRef> disk(DADiskCreateFromBSDName( base::apple::ScopedCFTypeRef<DADiskRef> disk(DADiskCreateFromBSDName(
/*allocator=*/nullptr, session, dmg_bsd_device_name.c_str())); /*allocator=*/nullptr, session, dmg_bsd_device_name.c_str()));
if (!disk.get()) { if (!disk.get()) {
LOG(ERROR) << "DADiskCreateFromBSDName"; LOG(ERROR) << "DADiskCreateFromBSDName";

@ -16,9 +16,9 @@ gfx::ImageSkia GetWindowIcon(content::DesktopMediaID id) {
CGWindowID ids[1]; CGWindowID ids[1];
ids[0] = id.id; ids[0] = id.id;
base::ScopedCFTypeRef<CFArrayRef> window_id_array(CFArrayCreate( base::apple::ScopedCFTypeRef<CFArrayRef> window_id_array(CFArrayCreate(
nullptr, reinterpret_cast<const void**>(&ids), std::size(ids), nullptr)); nullptr, reinterpret_cast<const void**>(&ids), std::size(ids), nullptr));
base::ScopedCFTypeRef<CFArrayRef> window_array( base::apple::ScopedCFTypeRef<CFArrayRef> window_array(
CGWindowListCreateDescriptionFromArray(window_id_array)); CGWindowListCreateDescriptionFromArray(window_id_array));
if (!window_array || 0 == CFArrayGetCount(window_array)) { if (!window_array || 0 == CFArrayGetCount(window_array)) {
return gfx::ImageSkia(); return gfx::ImageSkia();
@ -59,7 +59,8 @@ gfx::ImageSkia GetWindowIcon(content::DesktopMediaID id) {
} }
CGDataProviderRef provider = CGImageGetDataProvider(cg_icon_image); CGDataProviderRef provider = CGImageGetDataProvider(cg_icon_image);
base::ScopedCFTypeRef<CFDataRef> cf_data(CGDataProviderCopyData(provider)); base::apple::ScopedCFTypeRef<CFDataRef> cf_data(
CGDataProviderCopyData(provider));
int width = CGImageGetWidth(cg_icon_image); int width = CGImageGetWidth(cg_icon_image);
int height = CGImageGetHeight(cg_icon_image); int height = CGImageGetHeight(cg_icon_image);

@ -70,7 +70,7 @@ bool AuthenticateUser(std::u16string prompt_string) {
AuthorizationItem right_items[] = {{rightName.UTF8String, 0, nullptr, 0}}; AuthorizationItem right_items[] = {{rightName.UTF8String, 0, nullptr, 0}};
AuthorizationRights rights = {std::size(right_items), right_items}; AuthorizationRights rights = {std::size(right_items), right_items};
base::ScopedCFTypeRef<CFStringRef> prompt = base::apple::ScopedCFTypeRef<CFStringRef> prompt =
base::SysUTF16ToCFStringRef(prompt_string); base::SysUTF16ToCFStringRef(prompt_string);
// Pass kAuthorizationFlagDestroyRights to prevent the OS from saving the // Pass kAuthorizationFlagDestroyRights to prevent the OS from saving the

@ -106,7 +106,7 @@ bool DeleteDMTokenFromAppDataDir(const std::string& client_id) {
bool GetEnrollmentTokenFromPolicy(std::string* enrollment_token) { bool GetEnrollmentTokenFromPolicy(std::string* enrollment_token) {
// Since the configuration management infrastructure is not initialized when // Since the configuration management infrastructure is not initialized when
// this code runs, read the policy preference directly. // this code runs, read the policy preference directly.
base::ScopedCFTypeRef<CFPropertyListRef> value( base::apple::ScopedCFTypeRef<CFPropertyListRef> value(
CFPreferencesCopyAppValue(kEnrollmentTokenPolicyName, kBundleId)); CFPreferencesCopyAppValue(kEnrollmentTokenPolicyName, kBundleId));
// Read the enrollment token from the new location. If that fails, try the old // Read the enrollment token from the new location. If that fails, try the old
@ -138,8 +138,9 @@ bool GetEnrollmentTokenFromFile(std::string* enrollment_token) {
} }
absl::optional<bool> IsEnrollmentMandatoryByPolicy() { absl::optional<bool> IsEnrollmentMandatoryByPolicy() {
base::ScopedCFTypeRef<CFPropertyListRef> value(CFPreferencesCopyAppValue( base::apple::ScopedCFTypeRef<CFPropertyListRef> value(
kEnrollmentMandatoryOptionPolicyName, kBundleId)); CFPreferencesCopyAppValue(kEnrollmentMandatoryOptionPolicyName,
kBundleId));
if (!value || !CFPreferencesAppValueIsForced( if (!value || !CFPreferencesAppValueIsForced(
kEnrollmentMandatoryOptionPolicyName, kBundleId)) { kEnrollmentMandatoryOptionPolicyName, kBundleId)) {

@ -323,7 +323,7 @@ ChromeBrowserPolicyConnector::CreatePlatformProvider() {
// policies. // policies.
CFStringRef bundle_id = CFSTR("com.google.Chrome"); CFStringRef bundle_id = CFSTR("com.google.Chrome");
#else #else
base::ScopedCFTypeRef<CFStringRef> bundle_id( base::apple::ScopedCFTypeRef<CFStringRef> bundle_id(
base::SysUTF8ToCFStringRef(base::apple::BaseBundleID())); base::SysUTF8ToCFStringRef(base::apple::BaseBundleID()));
#endif #endif
auto loader = std::make_unique<PolicyLoaderMac>( auto loader = std::make_unique<PolicyLoaderMac>(

@ -76,9 +76,9 @@ base::FilePath::StringType ExpandPathVariables(
position = result.find(kMachineNamePolicyVarName); position = result.find(kMachineNamePolicyVarName);
if (position != std::string::npos) { if (position != std::string::npos) {
SCDynamicStoreContext context = {0, nullptr, nullptr, nullptr}; SCDynamicStoreContext context = {0, nullptr, nullptr, nullptr};
base::ScopedCFTypeRef<SCDynamicStoreRef> store(SCDynamicStoreCreate( base::apple::ScopedCFTypeRef<SCDynamicStoreRef> store(SCDynamicStoreCreate(
kCFAllocatorDefault, CFSTR("policy_subsystem"), nullptr, &context)); kCFAllocatorDefault, CFSTR("policy_subsystem"), nullptr, &context));
base::ScopedCFTypeRef<CFStringRef> machine_name( base::apple::ScopedCFTypeRef<CFStringRef> machine_name(
SCDynamicStoreCopyLocalHostName(store)); SCDynamicStoreCopyLocalHostName(store));
if (machine_name) { if (machine_name) {
result.replace(position, strlen(kMachineNamePolicyVarName), result.replace(position, strlen(kMachineNamePolicyVarName),
@ -103,13 +103,13 @@ void CheckUserDataDirPolicy(base::FilePath* user_data_dir) {
// policies. // policies.
CFStringRef bundle_id = CFSTR("com.google.Chrome"); CFStringRef bundle_id = CFSTR("com.google.Chrome");
#else #else
base::ScopedCFTypeRef<CFStringRef> bundle_id( base::apple::ScopedCFTypeRef<CFStringRef> bundle_id(
base::SysUTF8ToCFStringRef(base::apple::BaseBundleID())); base::SysUTF8ToCFStringRef(base::apple::BaseBundleID()));
#endif #endif
base::ScopedCFTypeRef<CFStringRef> key( base::apple::ScopedCFTypeRef<CFStringRef> key(
base::SysUTF8ToCFStringRef(policy::key::kUserDataDir)); base::SysUTF8ToCFStringRef(policy::key::kUserDataDir));
base::ScopedCFTypeRef<CFPropertyListRef> value( base::apple::ScopedCFTypeRef<CFPropertyListRef> value(
CFPreferencesCopyAppValue(key, bundle_id)); CFPreferencesCopyAppValue(key, bundle_id));
if (!value || !CFPreferencesAppValueIsForced(key, bundle_id)) if (!value || !CFPreferencesAppValueIsForced(key, bundle_id))

@ -146,8 +146,9 @@ class ChromeRenderWidgetHostViewMacHistorySwiperTest
// Creates a mock scroll wheel event that is backed by a real CGEvent. // Creates a mock scroll wheel event that is backed by a real CGEvent.
id MockScrollWheelEvent(NSPoint delta, NSEventType type) { id MockScrollWheelEvent(NSPoint delta, NSEventType type) {
base::ScopedCFTypeRef<CGEventRef> cg_event(CGEventCreateScrollWheelEvent( base::apple::ScopedCFTypeRef<CGEventRef> cg_event(
nullptr, kCGScrollEventUnitLine, 2, 0, 0)); CGEventCreateScrollWheelEvent(nullptr, kCGScrollEventUnitLine, 2, 0,
0));
CGEventSetIntegerValueField(cg_event, kCGScrollWheelEventIsContinuous, 1); CGEventSetIntegerValueField(cg_event, kCGScrollWheelEventIsContinuous, 1);
CGEventSetIntegerValueField( CGEventSetIntegerValueField(
cg_event, kCGScrollWheelEventPointDeltaAxis2, delta.x); cg_event, kCGScrollWheelEventPointDeltaAxis2, delta.x);

@ -106,7 +106,7 @@ TEST_F(BinaryIntegrityAnalyzerMacTest, GetCriticalPathsAndRequirements) {
EXPECT_EQ(paths_and_requirements[i].requirement, EXPECT_EQ(paths_and_requirements[i].requirement,
paths_and_requirements_expected[i].requirement); paths_and_requirements_expected[i].requirement);
base::ScopedCFTypeRef<SecRequirementRef> requirement; base::apple::ScopedCFTypeRef<SecRequirementRef> requirement;
EXPECT_EQ( EXPECT_EQ(
errSecSuccess, errSecSuccess,
SecRequirementCreateWithString( SecRequirementCreateWithString(

@ -59,10 +59,10 @@ class MacSignatureEvaluator {
bool has_requirement_; bool has_requirement_;
// The static code object constructed from the code object on disk. // The static code object constructed from the code object on disk.
base::ScopedCFTypeRef<SecStaticCodeRef> code_; base::apple::ScopedCFTypeRef<SecStaticCodeRef> code_;
// The requirement object constructed from the requirement string. // The requirement object constructed from the requirement string.
base::ScopedCFTypeRef<SecRequirementRef> requirement_; base::apple::ScopedCFTypeRef<SecRequirementRef> requirement_;
}; };
} // namespace safe_browsing } // namespace safe_browsing

@ -176,7 +176,7 @@ bool MacSignatureEvaluator::GetRelativePathComponent(
} }
bool MacSignatureEvaluator::Initialize() { bool MacSignatureEvaluator::Initialize() {
base::ScopedCFTypeRef<CFURLRef> code_url = base::apple::ScopedCFTypeRef<CFURLRef> code_url =
base::apple::FilePathToCFURL(path_); base::apple::FilePathToCFURL(path_);
if (!code_url) if (!code_url)
return false; return false;
@ -199,7 +199,7 @@ bool MacSignatureEvaluator::Initialize() {
bool MacSignatureEvaluator::PerformEvaluation( bool MacSignatureEvaluator::PerformEvaluation(
ClientIncidentReport_IncidentData_BinaryIntegrityIncident* incident) { ClientIncidentReport_IncidentData_BinaryIntegrityIncident* incident) {
DCHECK(incident->contained_file_size() == 0); DCHECK(incident->contained_file_size() == 0);
base::ScopedCFTypeRef<CFErrorRef> errors; base::apple::ScopedCFTypeRef<CFErrorRef> errors;
OSStatus err = SecStaticCodeCheckValidityWithErrors( OSStatus err = SecStaticCodeCheckValidityWithErrors(
code_, kSecCSCheckAllArchitectures, requirement_, code_, kSecCSCheckAllArchitectures, requirement_,
errors.InitializeInto()); errors.InitializeInto());
@ -210,7 +210,7 @@ bool MacSignatureEvaluator::PerformEvaluation(
incident->set_sec_error(err); incident->set_sec_error(err);
// We heuristically detect if we are in a bundle or not by checking if // We heuristically detect if we are in a bundle or not by checking if
// the main executable is different from the path_. // the main executable is different from the path_.
base::ScopedCFTypeRef<CFDictionaryRef> info_dict; base::apple::ScopedCFTypeRef<CFDictionaryRef> info_dict;
base::FilePath exec_path; base::FilePath exec_path;
if (SecCodeCopySigningInformation(code_, kSecCSDefaultFlags, if (SecCodeCopySigningInformation(code_, kSecCSDefaultFlags,
info_dict.InitializeInto()) == info_dict.InitializeInto()) ==
@ -232,7 +232,8 @@ bool MacSignatureEvaluator::PerformEvaluation(
} }
if (errors) { if (errors) {
base::ScopedCFTypeRef<CFDictionaryRef> info(CFErrorCopyUserInfo(errors)); base::apple::ScopedCFTypeRef<CFDictionaryRef> info(
CFErrorCopyUserInfo(errors));
static const CFStringRef keys[] = { static const CFStringRef keys[] = {
kSecCFErrorResourceAltered, kSecCFErrorResourceMissing, kSecCFErrorResourceAltered, kSecCFErrorResourceMissing,
}; };

@ -74,7 +74,7 @@ const CGFloat kShieldHeightCompletionAdjust = 10;
[super setFrameSize:newSize]; [super setFrameSize:newSize];
if (!_shapeLayer.path || !NSEqualSizes(oldSize, newSize)) { if (!_shapeLayer.path || !NSEqualSizes(oldSize, newSize)) {
base::ScopedCFTypeRef<CGMutablePathRef> oval(CGPathCreateMutable()); base::apple::ScopedCFTypeRef<CGMutablePathRef> oval(CGPathCreateMutable());
CGRect ovalRect = CGRectMake(0, 0, newSize.width, newSize.height); CGRect ovalRect = CGRectMake(0, 0, newSize.width, newSize.height);
CGPathAddEllipseInRect(oval, nullptr, ovalRect); CGPathAddEllipseInRect(oval, nullptr, ovalRect);
_shapeLayer.path = oval; _shapeLayer.path = oval;
@ -84,7 +84,7 @@ const CGFloat kShieldHeightCompletionAdjust = 10;
- (void)setShieldAlpha:(CGFloat)shieldAlpha { - (void)setShieldAlpha:(CGFloat)shieldAlpha {
if (shieldAlpha != _shieldAlpha) { if (shieldAlpha != _shieldAlpha) {
_shieldAlpha = shieldAlpha; _shieldAlpha = shieldAlpha;
base::ScopedCFTypeRef<CGColorRef> fillColor( base::apple::ScopedCFTypeRef<CGColorRef> fillColor(
CGColorCreateGenericGray(0, shieldAlpha)); CGColorCreateGenericGray(0, shieldAlpha));
_shapeLayer.fillColor = fillColor; _shapeLayer.fillColor = fillColor;
} }

@ -275,12 +275,13 @@ void SetupSystemUpdater() {
return; return;
} }
base::ScopedCFTypeRef<CFErrorRef> error; base::apple::ScopedCFTypeRef<CFErrorRef> error;
Boolean result = SMJobBless(kSMDomainSystemLaunchd, Boolean result = SMJobBless(kSMDomainSystemLaunchd,
base::SysUTF8ToCFStringRef(kPrivilegedHelperName), base::SysUTF8ToCFStringRef(kPrivilegedHelperName),
authorization, error.InitializeInto()); authorization, error.InitializeInto());
if (!result) { if (!result) {
base::ScopedCFTypeRef<CFStringRef> desc(CFErrorCopyDescription(error)); base::apple::ScopedCFTypeRef<CFStringRef> desc(
CFErrorCopyDescription(error));
VLOG(0) << "Could not bless the privileged helper. Resulting error: " VLOG(0) << "Could not bless the privileged helper. Resulting error: "
<< base::SysCFStringRefToUTF8(desc); << base::SysCFStringRefToUTF8(desc);
} }

@ -111,16 +111,17 @@ TEST(IcnsEncoderTest, RoundTrip) {
EXPECT_TRUE(encoder.WriteToFile(icon_path)); EXPECT_TRUE(encoder.WriteToFile(icon_path));
// Now use Image I/O methods to load the .icns file back in. // Now use Image I/O methods to load the .icns file back in.
base::ScopedCFTypeRef<CFDictionaryRef> empty_dict( base::apple::ScopedCFTypeRef<CFDictionaryRef> empty_dict(
CFDictionaryCreate(nullptr, nullptr, nullptr, 0, nullptr, nullptr)); CFDictionaryCreate(nullptr, nullptr, nullptr, 0, nullptr, nullptr));
base::ScopedCFTypeRef<CFURLRef> url = base::apple::FilePathToCFURL(icon_path); base::apple::ScopedCFTypeRef<CFURLRef> url =
base::ScopedCFTypeRef<CGImageSourceRef> source( base::apple::FilePathToCFURL(icon_path);
base::apple::ScopedCFTypeRef<CGImageSourceRef> source(
CGImageSourceCreateWithURL(url, nullptr)); CGImageSourceCreateWithURL(url, nullptr));
// And make sure we got back the same images that were written to the file. // And make sure we got back the same images that were written to the file.
EXPECT_EQ(3u, CGImageSourceGetCount(source)); EXPECT_EQ(3u, CGImageSourceGetCount(source));
for (size_t i = 0; i < CGImageSourceGetCount(source); ++i) { for (size_t i = 0; i < CGImageSourceGetCount(source); ++i) {
base::ScopedCFTypeRef<CGImageRef> cg_image( base::apple::ScopedCFTypeRef<CGImageRef> cg_image(
CGImageSourceCreateImageAtIndex(source, i, empty_dict)); CGImageSourceCreateImageAtIndex(source, i, empty_dict));
SkBitmap bitmap = skia::CGImageToSkBitmap(cg_image); SkBitmap bitmap = skia::CGImageToSkBitmap(cg_image);
EXPECT_EQ(bitmap.width(), bitmap.height()); EXPECT_EQ(bitmap.width(), bitmap.height());

@ -785,16 +785,17 @@ SkColor OsIntegrationTestOverrideImpl::GetIconTopLeftColorFromShortcutFile(
#if BUILDFLAG(IS_MAC) #if BUILDFLAG(IS_MAC)
base::FilePath icon_path = base::FilePath icon_path =
shortcut_path.AppendASCII("Contents/Resources/app.icns"); shortcut_path.AppendASCII("Contents/Resources/app.icns");
base::ScopedCFTypeRef<CFDictionaryRef> empty_dict( base::apple::ScopedCFTypeRef<CFDictionaryRef> empty_dict(
CFDictionaryCreate(nullptr, nullptr, nullptr, 0, nullptr, nullptr)); CFDictionaryCreate(nullptr, nullptr, nullptr, 0, nullptr, nullptr));
base::ScopedCFTypeRef<CFURLRef> url = base::apple::FilePathToCFURL(icon_path); base::apple::ScopedCFTypeRef<CFURLRef> url =
base::ScopedCFTypeRef<CGImageSourceRef> source( base::apple::FilePathToCFURL(icon_path);
base::apple::ScopedCFTypeRef<CGImageSourceRef> source(
CGImageSourceCreateWithURL(url, nullptr)); CGImageSourceCreateWithURL(url, nullptr));
if (!source) { if (!source) {
return 0; return 0;
} }
// Get the first icon in the .icns file (index 0) // Get the first icon in the .icns file (index 0)
base::ScopedCFTypeRef<CGImageRef> cg_image( base::apple::ScopedCFTypeRef<CGImageRef> cg_image(
CGImageSourceCreateImageAtIndex(source, 0, empty_dict)); CGImageSourceCreateImageAtIndex(source, 0, empty_dict));
if (!cg_image) { if (!cg_image) {
return 0; return 0;

@ -30,7 +30,7 @@ bool IsUsbDevice(io_object_t disk_obj) {
current_obj = parent_obj; current_obj = parent_obj;
parent_obj_ref.reset(parent_obj); parent_obj_ref.reset(parent_obj);
base::ScopedCFTypeRef<CFStringRef> class_name( base::apple::ScopedCFTypeRef<CFStringRef> class_name(
IOObjectCopyClass(current_obj)); IOObjectCopyClass(current_obj));
if (!class_name) { if (!class_name) {
LOG(ERROR) << "Could not get object class of IO Registry Entry."; LOG(ERROR) << "Could not get object class of IO Registry Entry.";
@ -52,7 +52,7 @@ bool IsSuitableRemovableStorageDevice(io_object_t disk_obj,
std::string* out_bsd_name, std::string* out_bsd_name,
uint64_t* out_size_in_bytes, uint64_t* out_size_in_bytes,
bool* out_removable) { bool* out_removable) {
base::ScopedCFTypeRef<CFMutableDictionaryRef> dict; base::apple::ScopedCFTypeRef<CFMutableDictionaryRef> dict;
kern_return_t result = IORegistryEntryCreateCFProperties( kern_return_t result = IORegistryEntryCreateCFProperties(
disk_obj, dict.InitializeInto(), kCFAllocatorDefault, 0); disk_obj, dict.InitializeInto(), kCFAllocatorDefault, 0);
if (result != KERN_SUCCESS) { if (result != KERN_SUCCESS) {

@ -79,9 +79,10 @@ bool ClearKeyEventModifiers() {
for (const auto& known_modifier : kKnownModifiers) { for (const auto& known_modifier : kKnownModifiers) {
if (known_modifier.flag_mask & event_flags) { if (known_modifier.flag_mask & event_flags) {
had_modifier = true; had_modifier = true;
CGEventPost(kCGSessionEventTap, CGEventPost(
base::ScopedCFTypeRef<CGEventRef>(CGEventCreateKeyboardEvent( kCGSessionEventTap,
nullptr, known_modifier.key_code, false))); base::apple::ScopedCFTypeRef<CGEventRef>(CGEventCreateKeyboardEvent(
nullptr, known_modifier.key_code, false)));
LOG(ERROR) << "Modifier " << known_modifier.name LOG(ERROR) << "Modifier " << known_modifier.name
<< " is hanging down, and may cause problems for any " << " is hanging down, and may cause problems for any "
"subsequent test."; "subsequent test.";

@ -19,7 +19,7 @@ UniChar GetCharacter(UInt16 mac_key_code, UInt32 modifier_key_state) {
UInt32 dead_key_state = 0; UInt32 dead_key_state = 0;
base::AutoLock lock(tis_lock_); base::AutoLock lock(tis_lock_);
base::ScopedCFTypeRef<TISInputSourceRef> input_source( base::apple::ScopedCFTypeRef<TISInputSourceRef> input_source(
TISCopyCurrentKeyboardLayoutInputSource()); TISCopyCurrentKeyboardLayoutInputSource());
return ui::TranslatedUnicodeCharFromKeyCode( return ui::TranslatedUnicodeCharFromKeyCode(
input_source.get(), mac_key_code, kUCKeyActionDown, modifier_key_state, input_source.get(), mac_key_code, kUCKeyActionDown, modifier_key_state,

@ -30,7 +30,7 @@ const CFStringRef kBrowserBundleId =
CFSTR(MAC_BROWSER_BUNDLE_IDENTIFIER_STRING); CFSTR(MAC_BROWSER_BUNDLE_IDENTIFIER_STRING);
bool LoadEnrollmentTokenFromPolicy(std::string* enrollment_token) { bool LoadEnrollmentTokenFromPolicy(std::string* enrollment_token) {
base::ScopedCFTypeRef<CFPropertyListRef> token_value( base::apple::ScopedCFTypeRef<CFPropertyListRef> token_value(
CFPreferencesCopyAppValue(kEnrollmentTokenKey, kBrowserBundleId)); CFPreferencesCopyAppValue(kEnrollmentTokenKey, kBrowserBundleId));
if (!token_value || CFGetTypeID(token_value) != CFStringGetTypeID() || if (!token_value || CFGetTypeID(token_value) != CFStringGetTypeID() ||
!CFPreferencesAppValueIsForced(kEnrollmentTokenKey, kBrowserBundleId)) { !CFPreferencesAppValueIsForced(kEnrollmentTokenKey, kBrowserBundleId)) {

@ -189,9 +189,9 @@ int InstallUpdater(const base::FilePath& browser_path) {
} // namespace } // namespace
bool VerifyUpdaterSignature(const base::FilePath& updater_app_bundle) { bool VerifyUpdaterSignature(const base::FilePath& updater_app_bundle) {
base::ScopedCFTypeRef<SecRequirementRef> requirement; base::apple::ScopedCFTypeRef<SecRequirementRef> requirement;
base::ScopedCFTypeRef<SecStaticCodeRef> code; base::apple::ScopedCFTypeRef<SecStaticCodeRef> code;
base::ScopedCFTypeRef<CFErrorRef> errors; base::apple::ScopedCFTypeRef<CFErrorRef> errors;
if (SecStaticCodeCreateWithPath( if (SecStaticCodeCreateWithPath(
base::apple::FilePathToCFURL(updater_app_bundle), kSecCSDefaultFlags, base::apple::FilePathToCFURL(updater_app_bundle), kSecCSDefaultFlags,
code.InitializeInto()) != errSecSuccess) { code.InitializeInto()) != errSecSuccess) {

@ -206,9 +206,10 @@ ManagedPreferencePolicyManager::GetAppsWithPolicy() const {
} }
NSDictionary* ReadManagedPreferencePolicyDictionary() { NSDictionary* ReadManagedPreferencePolicyDictionary() {
base::ScopedCFTypeRef<CFPropertyListRef> policies(CFPreferencesCopyAppValue( base::apple::ScopedCFTypeRef<CFPropertyListRef> policies(
base::apple::NSToCFPtrCast(kManagedPreferencesUpdatePolicies), CFPreferencesCopyAppValue(
base::apple::NSToCFPtrCast(kKeystoneSharedPreferenceSuite))); base::apple::NSToCFPtrCast(kManagedPreferencesUpdatePolicies),
base::apple::NSToCFPtrCast(kKeystoneSharedPreferenceSuite)));
if (!policies) if (!policies)
return nil; return nil;

@ -58,8 +58,8 @@ class DiskUnmounterMac {
base::OnceClosure success_continuation_; base::OnceClosure success_continuation_;
base::OnceClosure failure_continuation_; base::OnceClosure failure_continuation_;
base::ScopedCFTypeRef<DADiskRef> disk_; base::apple::ScopedCFTypeRef<DADiskRef> disk_;
base::ScopedCFTypeRef<DASessionRef> session_; base::apple::ScopedCFTypeRef<DASessionRef> session_;
// Thread is last to ensure it is stopped before the data members are // Thread is last to ensure it is stopped before the data members are
// destroyed. // destroyed.

@ -33,9 +33,9 @@ namespace image_writer {
static const char kAuthOpenPath[] = "/usr/libexec/authopen"; static const char kAuthOpenPath[] = "/usr/libexec/authopen";
bool ImageWriter::IsValidDevice() { bool ImageWriter::IsValidDevice() {
base::ScopedCFTypeRef<CFStringRef> cf_bsd_name( base::apple::ScopedCFTypeRef<CFStringRef> cf_bsd_name(
base::SysUTF8ToCFStringRef(device_path_.value())); base::SysUTF8ToCFStringRef(device_path_.value()));
base::ScopedCFTypeRef<CFMutableDictionaryRef> matching( base::apple::ScopedCFTypeRef<CFMutableDictionaryRef> matching(
IOServiceMatching(kIOMediaClass)); IOServiceMatching(kIOMediaClass));
CFDictionaryAddValue(matching, CFSTR(kIOMediaWholeKey), kCFBooleanTrue); CFDictionaryAddValue(matching, CFSTR(kIOMediaWholeKey), kCFBooleanTrue);
CFDictionaryAddValue(matching, CFSTR(kIOMediaWritableKey), kCFBooleanTrue); CFDictionaryAddValue(matching, CFSTR(kIOMediaWritableKey), kCFBooleanTrue);

@ -457,7 +457,7 @@ bool UDIFParser::ParseBlkx() {
return false; return false;
} }
base::ScopedCFTypeRef<CFDataRef> plist_data( base::apple::ScopedCFTypeRef<CFDataRef> plist_data(
CFDataCreateWithBytesNoCopy(kCFAllocatorDefault, plist_bytes.data(), CFDataCreateWithBytesNoCopy(kCFAllocatorDefault, plist_bytes.data(),
plist_bytes.size(), kCFAllocatorNull)); plist_bytes.size(), kCFAllocatorNull));
if (!plist_data) { if (!plist_data) {
@ -466,15 +466,15 @@ bool UDIFParser::ParseBlkx() {
} }
CFErrorRef error = nullptr; CFErrorRef error = nullptr;
base::ScopedCFTypeRef<CFPropertyListRef> plist( base::apple::ScopedCFTypeRef<CFPropertyListRef> plist(
CFPropertyListCreateWithData(kCFAllocatorDefault, plist_data, CFPropertyListCreateWithData(kCFAllocatorDefault, plist_data,
kCFPropertyListImmutable, nullptr, &error)); kCFPropertyListImmutable, nullptr, &error));
CFDictionaryRef plist_dict = CFDictionaryRef plist_dict =
base::apple::CFCast<CFDictionaryRef>(plist.get()); base::apple::CFCast<CFDictionaryRef>(plist.get());
base::ScopedCFTypeRef<CFErrorRef> error_ref(error); base::apple::ScopedCFTypeRef<CFErrorRef> error_ref(error);
if (error) { if (error) {
base::ScopedCFTypeRef<CFStringRef> error_string( base::apple::ScopedCFTypeRef<CFStringRef> error_string(
CFErrorCopyDescription(error)); CFErrorCopyDescription(error));
DLOG(ERROR) << "Failed to parse XML plist: " DLOG(ERROR) << "Failed to parse XML plist: "
<< base::SysCFStringRefToUTF8(error_string); << base::SysCFStringRefToUTF8(error_string);

@ -157,7 +157,7 @@ int GetCurrentCountryID() {
#elif BUILDFLAG(IS_APPLE) #elif BUILDFLAG(IS_APPLE)
int GetCurrentCountryID() { int GetCurrentCountryID() {
base::ScopedCFTypeRef<CFLocaleRef> locale(CFLocaleCopyCurrent()); base::apple::ScopedCFTypeRef<CFLocaleRef> locale(CFLocaleCopyCurrent());
CFStringRef country = CFStringRef country =
(CFStringRef)CFLocaleGetValue(locale.get(), kCFLocaleCountryCode); (CFStringRef)CFLocaleGetValue(locale.get(), kCFLocaleCountryCode);
if (!country) if (!country)

@ -92,16 +92,16 @@ MacPlatformDelegate::GetSigningCertificatesPublicKeys(
const base::FilePath& file_path) { const base::FilePath& file_path) {
SigningCertificatesPublicKeys public_keys; SigningCertificatesPublicKeys public_keys;
base::ScopedCFTypeRef<CFURLRef> file_url = base::apple::ScopedCFTypeRef<CFURLRef> file_url =
base::apple::FilePathToCFURL(file_path); base::apple::FilePathToCFURL(file_path);
base::ScopedCFTypeRef<SecStaticCodeRef> file_code; base::apple::ScopedCFTypeRef<SecStaticCodeRef> file_code;
if (SecStaticCodeCreateWithPath(file_url, kSecCSDefaultFlags, if (SecStaticCodeCreateWithPath(file_url, kSecCSDefaultFlags,
file_code.InitializeInto()) != file_code.InitializeInto()) !=
errSecSuccess) { errSecSuccess) {
return public_keys; return public_keys;
} }
base::ScopedCFTypeRef<CFDictionaryRef> signing_information; base::apple::ScopedCFTypeRef<CFDictionaryRef> signing_information;
if (SecCodeCopySigningInformation(file_code, kSecCSSigningInformation, if (SecCodeCopySigningInformation(file_code, kSecCSSigningInformation,
signing_information.InitializeInto()) != signing_information.InitializeInto()) !=
errSecSuccess) { errSecSuccess) {
@ -123,7 +123,8 @@ MacPlatformDelegate::GetSigningCertificatesPublicKeys(
SecCertificateRef leaf_cert = reinterpret_cast<SecCertificateRef>( SecCertificateRef leaf_cert = reinterpret_cast<SecCertificateRef>(
const_cast<void*>(CFArrayGetValueAtIndex(cert_chain, 0))); const_cast<void*>(CFArrayGetValueAtIndex(cert_chain, 0)));
base::ScopedCFTypeRef<CFDataRef> der_data(SecCertificateCopyData(leaf_cert)); base::apple::ScopedCFTypeRef<CFDataRef> der_data(
SecCertificateCopyData(leaf_cert));
if (!der_data) { if (!der_data) {
return public_keys; return public_keys;
} }

@ -225,7 +225,7 @@ id<MTLRenderPipelineState> CreateRenderPipelineState(id<MTLDevice> device) {
self.opaque = NO; self.opaque = NO;
self.presentsWithTransaction = YES; self.presentsWithTransaction = YES;
self.pixelFormat = MTLPixelFormatRGBA16Float; self.pixelFormat = MTLPixelFormatRGBA16Float;
base::ScopedCFTypeRef<CGColorSpaceRef> colorSpace( base::apple::ScopedCFTypeRef<CGColorSpaceRef> colorSpace(
CGColorSpaceCreateWithName(kCGColorSpaceExtendedLinearSRGB)); CGColorSpaceCreateWithName(kCGColorSpaceExtendedLinearSRGB));
self.colorspace = colorSpace; self.colorspace = colorSpace;
} }
@ -251,9 +251,9 @@ id<MTLRenderPipelineState> CreateRenderPipelineState(id<MTLDevice> device) {
CAEDRMetadata* edrMetadata = nil; CAEDRMetadata* edrMetadata = nil;
switch (colorSpace.GetTransferID()) { switch (colorSpace.GetTransferID()) {
case gfx::ColorSpace::TransferID::PQ: { case gfx::ColorSpace::TransferID::PQ: {
base::ScopedCFTypeRef<CFDataRef> display_info = base::apple::ScopedCFTypeRef<CFDataRef> display_info =
gfx::GenerateMasteringDisplayColorVolume(hdrMetadata); gfx::GenerateMasteringDisplayColorVolume(hdrMetadata);
base::ScopedCFTypeRef<CFDataRef> content_info = base::apple::ScopedCFTypeRef<CFDataRef> content_info =
gfx::GenerateContentLightLevelInfo(hdrMetadata); gfx::GenerateContentLightLevelInfo(hdrMetadata);
edrMetadata = [CAEDRMetadata edrMetadata = [CAEDRMetadata
HDR10MetadataWithDisplayInfo:base::apple::CFToNSPtrCast( HDR10MetadataWithDisplayInfo:base::apple::CFToNSPtrCast(

@ -35,18 +35,18 @@ bool DriveMetricsProvider::HasSeekPenalty(const base::FilePath& path,
std::string bsd_name("/dev/"); std::string bsd_name("/dev/");
bsd_name.append(dev_name); bsd_name.append(dev_name);
base::ScopedCFTypeRef<DASessionRef> session( base::apple::ScopedCFTypeRef<DASessionRef> session(
DASessionCreate(kCFAllocatorDefault)); DASessionCreate(kCFAllocatorDefault));
if (!session) if (!session)
return false; return false;
base::ScopedCFTypeRef<DADiskRef> disk( base::apple::ScopedCFTypeRef<DADiskRef> disk(
DADiskCreateFromBSDName(kCFAllocatorDefault, session, bsd_name.c_str())); DADiskCreateFromBSDName(kCFAllocatorDefault, session, bsd_name.c_str()));
if (!disk) if (!disk)
return false; return false;
base::mac::ScopedIOObject<io_object_t> io_media(DADiskCopyIOMedia(disk)); base::mac::ScopedIOObject<io_object_t> io_media(DADiskCopyIOMedia(disk));
base::ScopedCFTypeRef<CFDictionaryRef> characteristics( base::apple::ScopedCFTypeRef<CFDictionaryRef> characteristics(
static_cast<CFDictionaryRef>(IORegistryEntrySearchCFProperty( static_cast<CFDictionaryRef>(IORegistryEntrySearchCFProperty(
io_media, kIOServicePlane, CFSTR(kIOPropertyDeviceCharacteristicsKey), io_media, kIOServicePlane, CFSTR(kIOPropertyDeviceCharacteristicsKey),
kCFAllocatorDefault, kCFAllocatorDefault,

@ -21,7 +21,7 @@
#include "components/password_manager/core/common/passwords_directory_util_ios.h" #include "components/password_manager/core/common/passwords_directory_util_ios.h"
#include "sql/statement.h" #include "sql/statement.h"
using base::ScopedCFTypeRef; using base::apple::ScopedCFTypeRef;
namespace password_manager { namespace password_manager {

@ -26,8 +26,8 @@
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h" #include "testing/platform_test.h"
using base::ScopedCFTypeRef;
using base::UTF16ToUTF8; using base::UTF16ToUTF8;
using base::apple::ScopedCFTypeRef;
namespace password_manager { namespace password_manager {

@ -93,15 +93,15 @@ std::string GetMachineName() {
#elif BUILDFLAG(IS_MAC) #elif BUILDFLAG(IS_MAC)
// Do not use NSHost currentHost, as it's very slow. http://crbug.com/138570 // Do not use NSHost currentHost, as it's very slow. http://crbug.com/138570
SCDynamicStoreContext context = {0, NULL, NULL, NULL}; SCDynamicStoreContext context = {0, NULL, NULL, NULL};
base::ScopedCFTypeRef<SCDynamicStoreRef> store(SCDynamicStoreCreate( base::apple::ScopedCFTypeRef<SCDynamicStoreRef> store(SCDynamicStoreCreate(
kCFAllocatorDefault, CFSTR("chrome_sync"), NULL, &context)); kCFAllocatorDefault, CFSTR("chrome_sync"), NULL, &context));
base::ScopedCFTypeRef<CFStringRef> machine_name( base::apple::ScopedCFTypeRef<CFStringRef> machine_name(
SCDynamicStoreCopyLocalHostName(store.get())); SCDynamicStoreCopyLocalHostName(store.get()));
if (machine_name.get()) if (machine_name.get())
return base::SysCFStringRefToUTF8(machine_name.get()); return base::SysCFStringRefToUTF8(machine_name.get());
// Fall back to get computer name. // Fall back to get computer name.
base::ScopedCFTypeRef<CFStringRef> computer_name( base::apple::ScopedCFTypeRef<CFStringRef> computer_name(
SCDynamicStoreCopyComputerName(store.get(), NULL)); SCDynamicStoreCopyComputerName(store.get(), NULL));
if (computer_name.get()) if (computer_name.get())
return base::SysCFStringRefToUTF8(computer_name.get()); return base::SysCFStringRefToUTF8(computer_name.get());

@ -61,7 +61,8 @@ TEST(PolicyMacUtilTest, ValueToPropertyRoundTrip) {
const base::Value root_val(std::move(root)); const base::Value root_val(std::move(root));
// base::Value -> property list -> base::Value. // base::Value -> property list -> base::Value.
base::ScopedCFTypeRef<CFPropertyListRef> property(ValueToProperty(root_val)); base::apple::ScopedCFTypeRef<CFPropertyListRef> property(
ValueToProperty(root_val));
ASSERT_TRUE(property); ASSERT_TRUE(property);
std::unique_ptr<base::Value> value = PropertyToValue(property); std::unique_ptr<base::Value> value = PropertyToValue(property);
ASSERT_TRUE(value); ASSERT_TRUE(value);

@ -132,7 +132,7 @@ void TestHarness::InstallStringListPolicy(
const std::string& policy_name, const std::string& policy_name,
const base::Value::List& policy_value) { const base::Value::List& policy_value) {
NSString* key = base::SysUTF8ToNSString(policy_name); NSString* key = base::SysUTF8ToNSString(policy_name);
base::ScopedCFTypeRef<CFPropertyListRef> value( base::apple::ScopedCFTypeRef<CFPropertyListRef> value(
ValueToProperty(base::Value(policy_value.Clone()))); ValueToProperty(base::Value(policy_value.Clone())));
if (encode_complex_data_as_json_) { if (encode_complex_data_as_json_) {
@ -160,7 +160,7 @@ void TestHarness::InstallDictionaryPolicy(
AddPolicies(@{key : base::SysUTF8ToNSString(json_string)}); AddPolicies(@{key : base::SysUTF8ToNSString(json_string)});
} else { } else {
base::ScopedCFTypeRef<CFPropertyListRef> value( base::apple::ScopedCFTypeRef<CFPropertyListRef> value(
ValueToProperty(base::Value(policy_value.Clone()))); ValueToProperty(base::Value(policy_value.Clone())));
AddPolicies(@{key : (__bridge NSDictionary*)(value.get())}); AddPolicies(@{key : (__bridge NSDictionary*)(value.get())});
} }

@ -86,7 +86,7 @@ class POLICY_EXPORT PolicyLoaderMac : public AsyncPolicyLoader {
base::FilePathWatcher watcher_; base::FilePathWatcher watcher_;
// Application ID to pass into Mac's Preference Utilities API. // Application ID to pass into Mac's Preference Utilities API.
base::ScopedCFTypeRef<CFStringRef> application_id_; base::apple::ScopedCFTypeRef<CFStringRef> application_id_;
}; };
} // namespace policy } // namespace policy

@ -111,9 +111,9 @@ PolicyBundle PolicyLoaderMac::Load() {
schema_map()->GetSchema(PolicyNamespace(POLICY_DOMAIN_CHROME, "")); schema_map()->GetSchema(PolicyNamespace(POLICY_DOMAIN_CHROME, ""));
for (Schema::Iterator it = schema->GetPropertiesIterator(); !it.IsAtEnd(); for (Schema::Iterator it = schema->GetPropertiesIterator(); !it.IsAtEnd();
it.Advance()) { it.Advance()) {
base::ScopedCFTypeRef<CFStringRef> name( base::apple::ScopedCFTypeRef<CFStringRef> name(
base::SysUTF8ToCFStringRef(it.key())); base::SysUTF8ToCFStringRef(it.key()));
base::ScopedCFTypeRef<CFPropertyListRef> value( base::apple::ScopedCFTypeRef<CFPropertyListRef> value(
preferences_->CopyAppValue(name, application_id_)); preferences_->CopyAppValue(name, application_id_));
if (!value) if (!value)
continue; continue;
@ -204,15 +204,15 @@ void PolicyLoaderMac::LoadPolicyForComponent(
if (!schema.valid()) if (!schema.valid())
return; return;
base::ScopedCFTypeRef<CFStringRef> bundle_id = base::apple::ScopedCFTypeRef<CFStringRef> bundle_id =
base::SysUTF8ToCFStringRef(bundle_id_string); base::SysUTF8ToCFStringRef(bundle_id_string);
preferences_->AppSynchronize(bundle_id); preferences_->AppSynchronize(bundle_id);
for (Schema::Iterator it = schema.GetPropertiesIterator(); !it.IsAtEnd(); for (Schema::Iterator it = schema.GetPropertiesIterator(); !it.IsAtEnd();
it.Advance()) { it.Advance()) {
base::ScopedCFTypeRef<CFStringRef> pref_name = base::apple::ScopedCFTypeRef<CFStringRef> pref_name =
base::SysUTF8ToCFStringRef(it.key()); base::SysUTF8ToCFStringRef(it.key());
base::ScopedCFTypeRef<CFPropertyListRef> value( base::apple::ScopedCFTypeRef<CFPropertyListRef> value(
preferences_->CopyAppValue(pref_name, bundle_id)); preferences_->CopyAppValue(pref_name, bundle_id));
if (!value) if (!value)
continue; continue;

@ -27,7 +27,7 @@
#include "components/policy/core/common/preferences_mock_mac.h" #include "components/policy/core/common/preferences_mock_mac.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
using base::ScopedCFTypeRef; using base::apple::ScopedCFTypeRef;
namespace policy { namespace policy {

@ -91,9 +91,9 @@ CFPropertyListRef ValueToProperty(const base::Value& value) {
for (const auto key_value_pair : value_dict) { for (const auto key_value_pair : value_dict) {
// CFDictionaryAddValue() retains both |key| and |value|, so make sure // CFDictionaryAddValue() retains both |key| and |value|, so make sure
// the references are balanced. // the references are balanced.
base::ScopedCFTypeRef<CFStringRef> key( base::apple::ScopedCFTypeRef<CFStringRef> key(
base::SysUTF8ToCFStringRef(key_value_pair.first)); base::SysUTF8ToCFStringRef(key_value_pair.first));
base::ScopedCFTypeRef<CFPropertyListRef> cf_value( base::apple::ScopedCFTypeRef<CFPropertyListRef> cf_value(
ValueToProperty(key_value_pair.second)); ValueToProperty(key_value_pair.second));
if (cf_value) if (cf_value)
CFDictionaryAddValue(dict, key, cf_value); CFDictionaryAddValue(dict, key, cf_value);
@ -108,7 +108,7 @@ CFPropertyListRef ValueToProperty(const base::Value& value) {
for (const base::Value& entry : list) { for (const base::Value& entry : list) {
// CFArrayAppendValue() retains |cf_value|, so make sure the reference // CFArrayAppendValue() retains |cf_value|, so make sure the reference
// created by ValueToProperty() is released. // created by ValueToProperty() is released.
base::ScopedCFTypeRef<CFPropertyListRef> cf_value( base::apple::ScopedCFTypeRef<CFPropertyListRef> cf_value(
ValueToProperty(entry)); ValueToProperty(entry));
if (cf_value) if (cf_value)
CFArrayAppendValue(array, cf_value); CFArrayAppendValue(array, cf_value);

@ -30,9 +30,9 @@ class POLICY_EXPORT MockPreferences : public MacPreferences {
bool is_machine); bool is_machine);
private: private:
base::ScopedCFTypeRef<CFMutableDictionaryRef> values_; base::apple::ScopedCFTypeRef<CFMutableDictionaryRef> values_;
base::ScopedCFTypeRef<CFMutableSetRef> forced_; base::apple::ScopedCFTypeRef<CFMutableSetRef> forced_;
base::ScopedCFTypeRef<CFMutableSetRef> machine_; base::apple::ScopedCFTypeRef<CFMutableSetRef> machine_;
}; };
#endif // COMPONENTS_POLICY_CORE_COMMON_PREFERENCES_MOCK_MAC_H_ #endif // COMPONENTS_POLICY_CORE_COMMON_PREFERENCES_MOCK_MAC_H_

@ -182,7 +182,7 @@ absl::optional<std::string> GetBoardIdForThisMachine() {
// This is what libpmenergy is observed to do in order to retrieve the correct // This is what libpmenergy is observed to do in order to retrieve the correct
// coefficients file for the local computer. // coefficients file for the local computer.
base::ScopedCFTypeRef<CFDataRef> board_id_data( base::apple::ScopedCFTypeRef<CFDataRef> board_id_data(
base::apple::CFCast<CFDataRef>(IORegistryEntryCreateCFProperty( base::apple::CFCast<CFDataRef>(IORegistryEntryCreateCFProperty(
platform_expert, CFSTR("board-id"), kCFAllocatorDefault, 0))); platform_expert, CFSTR("board-id"), kCFAllocatorDefault, 0)));

@ -38,10 +38,10 @@ class M1SensorsReader {
protected: protected:
explicit M1SensorsReader( explicit M1SensorsReader(
base::ScopedCFTypeRef<IOHIDEventSystemClientRef> system); base::apple::ScopedCFTypeRef<IOHIDEventSystemClientRef> system);
private: private:
base::ScopedCFTypeRef<IOHIDEventSystemClientRef> system_; base::apple::ScopedCFTypeRef<IOHIDEventSystemClientRef> system_;
}; };
} // namespace power_metrics } // namespace power_metrics

@ -34,7 +34,7 @@ namespace {
absl::optional<double> GetEventFloatValue(IOHIDServiceClientRef service, absl::optional<double> GetEventFloatValue(IOHIDServiceClientRef service,
int64_t event_type) { int64_t event_type) {
base::ScopedCFTypeRef<CFTypeRef> event( base::apple::ScopedCFTypeRef<CFTypeRef> event(
IOHIDServiceClientCopyEvent(service, event_type, 0, 0)); IOHIDServiceClientCopyEvent(service, event_type, 0, 0));
if (!event) if (!event)
return absl::nullopt; return absl::nullopt;
@ -52,7 +52,7 @@ M1SensorsReader::~M1SensorsReader() = default;
// static // static
std::unique_ptr<M1SensorsReader> M1SensorsReader::Create() { std::unique_ptr<M1SensorsReader> M1SensorsReader::Create() {
base::ScopedCFTypeRef<IOHIDEventSystemClientRef> system( base::apple::ScopedCFTypeRef<IOHIDEventSystemClientRef> system(
IOHIDEventSystemClientCreate(kCFAllocatorDefault)); IOHIDEventSystemClientCreate(kCFAllocatorDefault));
if (system == nil) if (system == nil)
@ -68,7 +68,7 @@ std::unique_ptr<M1SensorsReader> M1SensorsReader::Create() {
} }
M1SensorsReader::TemperaturesCelsius M1SensorsReader::ReadTemperatures() { M1SensorsReader::TemperaturesCelsius M1SensorsReader::ReadTemperatures() {
base::ScopedCFTypeRef<CFArrayRef> services( base::apple::ScopedCFTypeRef<CFArrayRef> services(
IOHIDEventSystemClientCopyServices(system_.get())); IOHIDEventSystemClientCopyServices(system_.get()));
// There are multiple temperature sensors on P-Cores and E-Cores. Count and // There are multiple temperature sensors on P-Cores and E-Cores. Count and
@ -82,8 +82,9 @@ M1SensorsReader::TemperaturesCelsius M1SensorsReader::ReadTemperatures() {
IOHIDServiceClientRef service = IOHIDServiceClientRef service =
(IOHIDServiceClientRef)CFArrayGetValueAtIndex(services, i); (IOHIDServiceClientRef)CFArrayGetValueAtIndex(services, i);
base::ScopedCFTypeRef<CFStringRef> product(base::apple::CFCast<CFStringRef>( base::apple::ScopedCFTypeRef<CFStringRef> product(
IOHIDServiceClientCopyProperty(service, CFSTR(kIOHIDProductKey)))); base::apple::CFCast<CFStringRef>(
IOHIDServiceClientCopyProperty(service, CFSTR(kIOHIDProductKey))));
if (product == nil) { if (product == nil) {
continue; continue;
} }
@ -117,7 +118,7 @@ M1SensorsReader::TemperaturesCelsius M1SensorsReader::ReadTemperatures() {
} }
M1SensorsReader::M1SensorsReader( M1SensorsReader::M1SensorsReader(
base::ScopedCFTypeRef<IOHIDEventSystemClientRef> system) base::apple::ScopedCFTypeRef<IOHIDEventSystemClientRef> system)
: system_(std::move(system)) {} : system_(std::move(system)) {}
} // namespace power_metrics } // namespace power_metrics

@ -38,7 +38,7 @@ void ShowCertificateViewerForWindow(NSWindow* owning_window,
// the certificate viewer UI from displaying which certificate is revoked. // the certificate viewer UI from displaying which certificate is revoked.
// This is acceptable, as certificate revocation will still be shown in // This is acceptable, as certificate revocation will still be shown in
// the page info bubble if a certificate in the chain is actually revoked. // the page info bubble if a certificate in the chain is actually revoked.
base::ScopedCFTypeRef<CFMutableArrayRef> policies( base::apple::ScopedCFTypeRef<CFMutableArrayRef> policies(
CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks)); CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks));
if (!policies.get()) { if (!policies.get()) {
NOTREACHED(); NOTREACHED();
@ -46,7 +46,8 @@ void ShowCertificateViewerForWindow(NSWindow* owning_window,
} }
// Add a basic X.509 policy, in order to match the behaviour of // Add a basic X.509 policy, in order to match the behaviour of
// SFCertificatePanel when no policies are specified. // SFCertificatePanel when no policies are specified.
base::ScopedCFTypeRef<SecPolicyRef> basic_policy(SecPolicyCreateBasicX509()); base::apple::ScopedCFTypeRef<SecPolicyRef> basic_policy(
SecPolicyCreateBasicX509());
if (!basic_policy) { if (!basic_policy) {
NOTREACHED(); NOTREACHED();
return; return;

@ -29,7 +29,8 @@ const int kFileTypePopupTag = 1234;
// TODO(macOS 11): Remove this. // TODO(macOS 11): Remove this.
CFStringRef CreateUTIFromExtension(const base::FilePath::StringType& ext) { CFStringRef CreateUTIFromExtension(const base::FilePath::StringType& ext) {
base::ScopedCFTypeRef<CFStringRef> ext_cf(base::SysUTF8ToCFStringRef(ext)); base::apple::ScopedCFTypeRef<CFStringRef> ext_cf(
base::SysUTF8ToCFStringRef(ext));
return UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, return UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension,
ext_cf.get(), nullptr); ext_cf.get(), nullptr);
} }
@ -44,7 +45,7 @@ NSString* GetDescriptionFromExtension(const base::FilePath::StringType& ext) {
return description; return description;
} }
} else { } else {
base::ScopedCFTypeRef<CFStringRef> uti(CreateUTIFromExtension(ext)); base::apple::ScopedCFTypeRef<CFStringRef> uti(CreateUTIFromExtension(ext));
NSString* description = NSString* description =
base::apple::CFToNSOwnershipCast(UTTypeCopyDescription(uti.get())); base::apple::CFToNSOwnershipCast(UTTypeCopyDescription(uti.get()));

@ -61,7 +61,7 @@ bool AddOriginMetadataToFile(const base::FilePath& file,
return false; return false;
} }
base::ScopedCFTypeRef<MDItemRef> md_item( base::apple::ScopedCFTypeRef<MDItemRef> md_item(
MDItemCreate(kCFAllocatorDefault, base::apple::NSToCFPtrCast(file_path))); MDItemCreate(kCFAllocatorDefault, base::apple::NSToCFPtrCast(file_path)));
if (!md_item) { if (!md_item) {
LOG(WARNING) << "MDItemCreate failed for path " << file.value(); LOG(WARNING) << "MDItemCreate failed for path " << file.value();

@ -164,7 +164,7 @@ TEST_F(QuarantineMacTest, NoWhereFromsKeyIfNoURLs) {
NSString* file_path = base::apple::FilePathToNSString(test_file_); NSString* file_path = base::apple::FilePathToNSString(test_file_);
ASSERT_NE(nullptr, file_path); ASSERT_NE(nullptr, file_path);
base::ScopedCFTypeRef<MDItemRef> md_item( base::apple::ScopedCFTypeRef<MDItemRef> md_item(
MDItemCreate(kCFAllocatorDefault, base::apple::NSToCFPtrCast(file_path))); MDItemCreate(kCFAllocatorDefault, base::apple::NSToCFPtrCast(file_path)));
if (!md_item) { if (!md_item) {
// The quarantine code ignores it if adding origin metadata fails. If for // The quarantine code ignores it if adding origin metadata fails. If for
@ -173,7 +173,7 @@ TEST_F(QuarantineMacTest, NoWhereFromsKeyIfNoURLs) {
return; return;
} }
base::ScopedCFTypeRef<CFTypeRef> attr( base::apple::ScopedCFTypeRef<CFTypeRef> attr(
MDItemCopyAttribute(md_item, kMDItemWhereFroms)); MDItemCopyAttribute(md_item, kMDItemWhereFroms));
EXPECT_FALSE(attr); EXPECT_FALSE(attr);
} }

@ -61,7 +61,7 @@ class StorageMonitorMac : public StorageMonitor,
bool FindDiskWithMountPoint(const base::FilePath& mount_point, bool FindDiskWithMountPoint(const base::FilePath& mount_point,
StorageInfo* info) const; StorageInfo* info) const;
base::ScopedCFTypeRef<DASessionRef> session_; base::apple::ScopedCFTypeRef<DASessionRef> session_;
// Maps disk bsd names to disk info objects. This map tracks all mountable // Maps disk bsd names to disk info objects. This map tracks all mountable
// devices on the system, though only notifications for removable devices are // devices on the system, though only notifications for removable devices are
// posted. // posted.

@ -87,7 +87,7 @@ StorageInfo BuildStorageInfo(
dict, kDADiskDescriptionVolumeUUIDKey); dict, kDADiskDescriptionVolumeUUIDKey);
std::string unique_id; std::string unique_id;
if (uuid) { if (uuid) {
base::ScopedCFTypeRef<CFStringRef> uuid_string( base::apple::ScopedCFTypeRef<CFStringRef> uuid_string(
CFUUIDCreateString(nullptr, uuid)); CFUUIDCreateString(nullptr, uuid));
if (uuid_string.get()) if (uuid_string.get())
unique_id = base::SysCFStringRefToUTF8(uuid_string); unique_id = base::SysCFStringRefToUTF8(uuid_string);
@ -119,7 +119,7 @@ StorageInfo BuildStorageInfo(
struct EjectDiskOptions { struct EjectDiskOptions {
std::string bsd_name; std::string bsd_name;
base::OnceCallback<void(StorageMonitor::EjectStatus)> callback; base::OnceCallback<void(StorageMonitor::EjectStatus)> callback;
base::ScopedCFTypeRef<DADiskRef> disk; base::apple::ScopedCFTypeRef<DADiskRef> disk;
}; };
void PostEjectCallback(DADiskRef disk, void PostEjectCallback(DADiskRef disk,
@ -291,7 +291,7 @@ void StorageMonitorMac::EjectDevice(
receiver()->ProcessDetach(device_id); receiver()->ProcessDetach(device_id);
base::ScopedCFTypeRef<DADiskRef> disk( base::apple::ScopedCFTypeRef<DADiskRef> disk(
DADiskCreateFromBSDName(nullptr, session_, bsd_name.c_str())); DADiskCreateFromBSDName(nullptr, session_, bsd_name.c_str()));
if (!disk.get()) { if (!disk.get()) {
std::move(callback).Run(StorageMonitor::EJECT_FAILURE); std::move(callback).Run(StorageMonitor::EJECT_FAILURE);
@ -339,7 +339,8 @@ void StorageMonitorMac::GetDiskInfoAndUpdate(
pending_disk_updates_++; pending_disk_updates_++;
base::ScopedCFTypeRef<CFDictionaryRef> dict(DADiskCopyDescription(disk)); base::apple::ScopedCFTypeRef<CFDictionaryRef> dict(
DADiskCopyDescription(disk));
std::string* bsd_name = new std::string; std::string* bsd_name = new std::string;
base::ThreadPool::PostTaskAndReplyWithResult( base::ThreadPool::PostTaskAndReplyWithResult(
FROM_HERE, {base::MayBlock(), base::TaskPriority::BEST_EFFORT}, FROM_HERE, {base::MayBlock(), base::TaskPriority::BEST_EFFORT},

@ -21,17 +21,17 @@ namespace syncer {
std::string GetPersonalizableDeviceNameInternal() { std::string GetPersonalizableDeviceNameInternal() {
// Do not use NSHost currentHost, as it's very slow. http://crbug.com/138570 // Do not use NSHost currentHost, as it's very slow. http://crbug.com/138570
SCDynamicStoreContext context = {0}; SCDynamicStoreContext context = {0};
base::ScopedCFTypeRef<SCDynamicStoreRef> store( base::apple::ScopedCFTypeRef<SCDynamicStoreRef> store(
SCDynamicStoreCreate(kCFAllocatorDefault, CFSTR("chrome_sync"), SCDynamicStoreCreate(kCFAllocatorDefault, CFSTR("chrome_sync"),
/*callout=*/nullptr, &context)); /*callout=*/nullptr, &context));
base::ScopedCFTypeRef<CFStringRef> machine_name( base::apple::ScopedCFTypeRef<CFStringRef> machine_name(
SCDynamicStoreCopyLocalHostName(store)); SCDynamicStoreCopyLocalHostName(store));
if (machine_name) { if (machine_name) {
return base::SysCFStringRefToUTF8(machine_name); return base::SysCFStringRefToUTF8(machine_name);
} }
// Fall back to get computer name. // Fall back to get computer name.
base::ScopedCFTypeRef<CFStringRef> computer_name( base::apple::ScopedCFTypeRef<CFStringRef> computer_name(
SCDynamicStoreCopyComputerName(store, /*nameEncoding=*/nullptr)); SCDynamicStoreCopyComputerName(store, /*nameEncoding=*/nullptr));
if (computer_name) { if (computer_name) {
return base::SysCFStringRefToUTF8(computer_name); return base::SysCFStringRefToUTF8(computer_name);

@ -52,7 +52,7 @@ class VIZ_SERVICE_EXPORT SoftwareOutputDeviceMac : public SoftwareOutputDevice {
struct Buffer { struct Buffer {
Buffer(); Buffer();
~Buffer(); ~Buffer();
base::ScopedCFTypeRef<IOSurfaceRef> io_surface; base::apple::ScopedCFTypeRef<IOSurfaceRef> io_surface;
// The damage of all BeginPaints since this buffer was the back buffer. // The damage of all BeginPaints since this buffer was the back buffer.
SkRegion accumulated_damage; SkRegion accumulated_damage;
}; };

@ -443,7 +443,7 @@ std::string WiFiServiceMac::GetNetworkConnectionState(
local_wifi_address.sin_len = sizeof(local_wifi_address); local_wifi_address.sin_len = sizeof(local_wifi_address);
local_wifi_address.sin_family = AF_INET; local_wifi_address.sin_family = AF_INET;
local_wifi_address.sin_addr.s_addr = htonl(IN_LINKLOCALNETNUM); local_wifi_address.sin_addr.s_addr = htonl(IN_LINKLOCALNETNUM);
base::ScopedCFTypeRef<SCNetworkReachabilityRef> reachability( base::apple::ScopedCFTypeRef<SCNetworkReachabilityRef> reachability(
SCNetworkReachabilityCreateWithAddress( SCNetworkReachabilityCreateWithAddress(
kCFAllocatorDefault, kCFAllocatorDefault,
reinterpret_cast<const struct sockaddr*>(&local_wifi_address))); reinterpret_cast<const struct sockaddr*>(&local_wifi_address)));

@ -137,7 +137,7 @@
[UTType typeWithMIMEType:base::SysUTF8ToNSString(mimeType)]; [UTType typeWithMIMEType:base::SysUTF8ToNSString(mimeType)];
_fileUTType = type.identifier; _fileUTType = type.identifier;
} else { } else {
base::ScopedCFTypeRef<CFStringRef> mimeTypeCF( base::apple::ScopedCFTypeRef<CFStringRef> mimeTypeCF(
base::SysUTF8ToCFStringRef(mimeType)); base::SysUTF8ToCFStringRef(mimeType));
_fileUTType = base::apple::CFToNSOwnershipCast( _fileUTType = base::apple::CFToNSOwnershipCast(
UTTypeCreatePreferredIdentifierForTag(kUTTagClassMIMEType, UTTypeCreatePreferredIdentifierForTag(kUTTagClassMIMEType,

@ -40,10 +40,10 @@ class CONTENT_EXPORT FontEnumerationDataSourceMac
// Font attributes for a font. Set post-validation. Used only during // Font attributes for a font. Set post-validation. Used only during
// enumeration. // enumeration.
base::ScopedCFTypeRef<CFStringRef> cf_postscript_name_; base::apple::ScopedCFTypeRef<CFStringRef> cf_postscript_name_;
base::ScopedCFTypeRef<CFStringRef> cf_full_name_; base::apple::ScopedCFTypeRef<CFStringRef> cf_full_name_;
base::ScopedCFTypeRef<CFStringRef> cf_family_; base::apple::ScopedCFTypeRef<CFStringRef> cf_family_;
base::ScopedCFTypeRef<CFStringRef> cf_style_; base::apple::ScopedCFTypeRef<CFStringRef> cf_style_;
}; };
} // namespace content } // namespace content

@ -20,17 +20,19 @@ namespace content {
namespace { namespace {
base::ScopedCFTypeRef<CFStringRef> GetLocalizedString(CTFontDescriptorRef fd, base::apple::ScopedCFTypeRef<CFStringRef> GetLocalizedString(
CFStringRef attribute) { CTFontDescriptorRef fd,
return base::ScopedCFTypeRef<CFStringRef>( CFStringRef attribute) {
return base::apple::ScopedCFTypeRef<CFStringRef>(
base::apple::CFCast<CFStringRef>(CTFontDescriptorCopyLocalizedAttribute( base::apple::CFCast<CFStringRef>(CTFontDescriptorCopyLocalizedAttribute(
fd, attribute, /*language=*/nullptr))); fd, attribute, /*language=*/nullptr)));
} }
base::ScopedCFTypeRef<CFStringRef> GetString(CTFontDescriptorRef fd, base::apple::ScopedCFTypeRef<CFStringRef> GetString(CTFontDescriptorRef fd,
CFStringRef attribute) { CFStringRef attribute) {
return base::ScopedCFTypeRef<CFStringRef>(base::apple::CFCast<CFStringRef>( return base::apple::ScopedCFTypeRef<CFStringRef>(
CTFontDescriptorCopyAttribute(fd, attribute))); base::apple::CFCast<CFStringRef>(
CTFontDescriptorCopyAttribute(fd, attribute)));
} }
} // namespace } // namespace
@ -45,13 +47,13 @@ FontEnumerationDataSourceMac::~FontEnumerationDataSourceMac() {
bool FontEnumerationDataSourceMac::IsValidFontMac( bool FontEnumerationDataSourceMac::IsValidFontMac(
const CTFontDescriptorRef& fd) { const CTFontDescriptorRef& fd) {
base::ScopedCFTypeRef<CFStringRef> cf_postscript_name = base::apple::ScopedCFTypeRef<CFStringRef> cf_postscript_name =
GetString(fd, kCTFontNameAttribute); GetString(fd, kCTFontNameAttribute);
base::ScopedCFTypeRef<CFStringRef> cf_full_name = base::apple::ScopedCFTypeRef<CFStringRef> cf_full_name =
GetLocalizedString(fd, kCTFontDisplayNameAttribute); GetLocalizedString(fd, kCTFontDisplayNameAttribute);
base::ScopedCFTypeRef<CFStringRef> cf_family = base::apple::ScopedCFTypeRef<CFStringRef> cf_family =
GetString(fd, kCTFontFamilyNameAttribute); GetString(fd, kCTFontFamilyNameAttribute);
base::ScopedCFTypeRef<CFStringRef> cf_style = base::apple::ScopedCFTypeRef<CFStringRef> cf_style =
GetString(fd, kCTFontStyleNameAttribute); GetString(fd, kCTFontStyleNameAttribute);
if (!cf_postscript_name || !cf_full_name || !cf_family || !cf_style) { if (!cf_postscript_name || !cf_full_name || !cf_family || !cf_style) {
@ -77,11 +79,11 @@ blink::FontEnumerationTable FontEnumerationDataSourceMac::GetFonts(
base::apple::CFToNSPtrCast(kCTFontCollectionRemoveDuplicatesOption) : @YES base::apple::CFToNSPtrCast(kCTFontCollectionRemoveDuplicatesOption) : @YES
}; };
base::ScopedCFTypeRef<CTFontCollectionRef> collection( base::apple::ScopedCFTypeRef<CTFontCollectionRef> collection(
CTFontCollectionCreateFromAvailableFonts( CTFontCollectionCreateFromAvailableFonts(
base::apple::NSToCFPtrCast(options))); base::apple::NSToCFPtrCast(options)));
base::ScopedCFTypeRef<CFArrayRef> font_descs( base::apple::ScopedCFTypeRef<CFArrayRef> font_descs(
CTFontCollectionCreateMatchingFontDescriptors(collection)); CTFontCollectionCreateMatchingFontDescriptors(collection));
// Used to filter duplicates. // Used to filter duplicates.

@ -51,7 +51,7 @@ class DesktopCaptureDeviceMac : public IOSurfaceCaptureDeviceBase {
}; };
// Retrieve the source display's size. // Retrieve the source display's size.
base::ScopedCFTypeRef<CGDisplayModeRef> mode( base::apple::ScopedCFTypeRef<CGDisplayModeRef> mode(
CGDisplayCopyDisplayMode(display_id_)); CGDisplayCopyDisplayMode(display_id_));
const gfx::Size source_size = mode ? gfx::Size(CGDisplayModeGetWidth(mode), const gfx::Size source_size = mode ? gfx::Size(CGDisplayModeGetWidth(mode),
CGDisplayModeGetHeight(mode)) CGDisplayModeGetHeight(mode))
@ -62,14 +62,14 @@ class DesktopCaptureDeviceMac : public IOSurfaceCaptureDeviceBase {
ComputeFrameSizeAndDestRect(source_size, requested_format_.frame_size, ComputeFrameSizeAndDestRect(source_size, requested_format_.frame_size,
dest_rect_in_frame); dest_rect_in_frame);
base::ScopedCFTypeRef<CFDictionaryRef> properties; base::apple::ScopedCFTypeRef<CFDictionaryRef> properties;
{ {
float max_frame_time = 1.f / requested_format_.frame_rate; float max_frame_time = 1.f / requested_format_.frame_rate;
base::ScopedCFTypeRef<CFNumberRef> cf_max_frame_time( base::apple::ScopedCFTypeRef<CFNumberRef> cf_max_frame_time(
CFNumberCreate(nullptr, kCFNumberFloat32Type, &max_frame_time)); CFNumberCreate(nullptr, kCFNumberFloat32Type, &max_frame_time));
base::ScopedCFTypeRef<CGColorSpaceRef> cg_color_space( base::apple::ScopedCFTypeRef<CGColorSpaceRef> cg_color_space(
CGColorSpaceCreateWithName(kCGColorSpaceSRGB)); CGColorSpaceCreateWithName(kCGColorSpaceSRGB));
base::ScopedCFTypeRef<CFDictionaryRef> dest_rect_in_frame_dict( base::apple::ScopedCFTypeRef<CFDictionaryRef> dest_rect_in_frame_dict(
CGRectCreateDictionaryRepresentation(dest_rect_in_frame.ToCGRect())); CGRectCreateDictionaryRepresentation(dest_rect_in_frame.ToCGRect()));
const size_t kNumKeys = 5; const size_t kNumKeys = 5;
@ -138,7 +138,7 @@ class DesktopCaptureDeviceMac : public IOSurfaceCaptureDeviceBase {
const CGDirectDisplayID display_id_; const CGDirectDisplayID display_id_;
const scoped_refptr<base::SingleThreadTaskRunner> device_task_runner_; const scoped_refptr<base::SingleThreadTaskRunner> device_task_runner_;
base::ScopedCFTypeRef<CGDisplayStreamRef> display_stream_; base::apple::ScopedCFTypeRef<CGDisplayStreamRef> display_stream_;
media::VideoCaptureFormat requested_format_; media::VideoCaptureFormat requested_format_;
base::WeakPtrFactory<DesktopCaptureDeviceMac> weak_factory_; base::WeakPtrFactory<DesktopCaptureDeviceMac> weak_factory_;
}; };

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