Skip to content

Commit

Permalink
Create base/apple and move bridging.h to it
Browse files Browse the repository at this point in the history
Bug: none
Change-Id: Idb8ff1c781ef5c9767f19e94d212ef9cdba91d2c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4521459
Owners-Override: Daniel Cheng <dcheng@chromium.org>
Code-Coverage: Findit <findit-for-me@appspot.gserviceaccount.com>
Auto-Submit: Avi Drissman <avi@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Owners-Override: Avi Drissman <avi@chromium.org>
Commit-Queue: Daniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1142818}
  • Loading branch information
Avi Drissman authored and Chromium LUCI CQ committed May 11, 2023
1 parent b03beb8 commit cfa6125
Show file tree
Hide file tree
Showing 45 changed files with 132 additions and 125 deletions.
2 changes: 1 addition & 1 deletion base/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -2046,6 +2046,7 @@ component("base") {
# Mac or iOS.
if (is_apple) {
sources += [
"apple/bridging.h",
"file_version_info_mac.h",
"file_version_info_mac.mm",
"files/file_util_mac.mm",
Expand Down Expand Up @@ -2141,7 +2142,6 @@ component("base") {
"ios/ns_range.h",
"ios/scoped_critical_action.h",
"ios/scoped_critical_action.mm",
"mac/bridging.h",
"native_library_ios.mm",
"power_monitor/power_monitor_device_source_ios.mm",
"process/process_metrics_ios.cc",
Expand Down
3 changes: 3 additions & 0 deletions base/apple/DIR_METADATA
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
monorail {
component: "Internals"
}
2 changes: 2 additions & 0 deletions base/apple/OWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mark@chromium.org
thakis@chromium.org
20 changes: 10 additions & 10 deletions base/mac/bridging.h → base/apple/bridging.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef BASE_MAC_BRIDGING_H_
#define BASE_MAC_BRIDGING_H_
#ifndef BASE_APPLE_BRIDGING_H_
#define BASE_APPLE_BRIDGING_H_

#include <CoreText/CoreText.h>
#import <Foundation/Foundation.h>
Expand All @@ -23,7 +23,7 @@
#endif

#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "base/mac/bridging.h requires ARC."
#error "base/apple/bridging.h requires ARC."
#endif

// These functions convert pointers of bridged CFTypes to NSTypes and
Expand Down Expand Up @@ -58,7 +58,7 @@
// works for this purpose.

#define CF_TO_NS_CAST_IMPL(TypeCF, TypeNS) \
namespace base::mac { \
namespace base::apple { \
inline BASE_EXPORT TypeNS* _Nullable CFToNSOwnershipCast( \
TypeCF##Ref CF_CONSUMED _Nullable cf_val) { \
DCHECK(!cf_val || TypeCF##GetTypeID() == CFGetTypeID(cf_val)); \
Expand All @@ -85,7 +85,7 @@

#define CF_TO_NS_MUTABLE_CAST_IMPL(name) \
CF_TO_NS_CAST_IMPL(CF##name, NS##name) \
namespace base::mac { \
namespace base::apple { \
inline BASE_EXPORT NSMutable##name* _Nullable CFToNSOwnershipCast( \
CFMutable##name##Ref CF_CONSUMED _Nullable cf_val) { \
DCHECK(!cf_val || CF##name##GetTypeID() == CFGetTypeID(cf_val)); \
Expand Down Expand Up @@ -151,7 +151,7 @@ extern "C" {
Boolean _CFIsObjC(CFTypeID typeID, _Nonnull CFTypeRef obj);
} // extern "C"

namespace base::mac {
namespace base::apple {

inline BASE_EXPORT NSFont* _Nullable CFToNSOwnershipCast(
CTFontRef CF_CONSUMED _Nullable cf_val) {
Expand Down Expand Up @@ -185,14 +185,14 @@ inline BASE_EXPORT _Nullable CTFontRef NSToCFPtrCast(NSFont* _Nullable ns_val) {
return cf_val;
}

} // namespace base::mac
} // namespace base::apple

#endif // BUILDFLAG(IS_IOS)

#undef CF_TO_NS_CAST_IMPL
#undef CF_TO_NS_MUTABLE_CAST_IMPL

namespace base::mac {
namespace base::apple {

template <typename CFT>
id _Nullable CFToNSOwnershipCast(base::ScopedCFTypeRef<CFT>) {
Expand All @@ -203,6 +203,6 @@ id _Nullable CFToNSOwnershipCast(base::ScopedCFTypeRef<CFT>) {
return nil;
}

} // namespace base::mac
} // namespace base::apple

#endif // BASE_MAC_BRIDGING_H_
#endif // BASE_APPLE_BRIDGING_H_
2 changes: 1 addition & 1 deletion base/mac/foundation_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ BASE_EXPORT void SetBaseBundleID(const char* new_base_bundle_id);
} // namespace base::mac

// These casting functions cannot be implemented in a way that will work with
// ARC. Use the casting functions in base/mac/bridging.h instead.
// ARC. Use the casting functions in base/apple/bridging.h instead.
#if !defined(__has_feature) || !__has_feature(objc_arc)

#if defined(__OBJC__)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
#include <string>
#include <vector>

#include "base/apple/bridging.h"
#include "base/containers/span.h"
#include "base/mac/bridging.h"
#include "base/mac/scoped_cftyperef.h"
#include "base/numerics/safe_conversions.h"
#include "base/strings/string_piece.h"
Expand Down Expand Up @@ -103,7 +103,7 @@ void LogKeyOperationFailure(Operation operation,
CFDictionarySetValue(attributes, kSecAttrTokenID,
kSecAttrTokenIDSecureEnclave);
CFDictionarySetValue(attributes, kSecAttrKeySizeInBits,
base::mac::NSToCFPtrCast(@256));
base::apple::NSToCFPtrCast(@256));
CFDictionarySetValue(
attributes, kSecAttrLabel,
base::SysUTF8ToCFStringRef(constants::kDeviceTrustSigningKeyLabel));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

#include <memory>

#include "base/apple/bridging.h"
#include "base/containers/span.h"
#include "base/mac/bridging.h"
#include "base/mac/foundation_util.h"
#include "base/mac/scoped_cftyperef.h"
#include "base/strings/sys_string_conversions.h"
Expand Down Expand Up @@ -67,7 +67,7 @@ void CreateAndSetTestKey() {
CFDictionarySetValue(test_attributes, kSecAttrKeyType,
kSecAttrKeyTypeECSECPrimeRandom);
CFDictionarySetValue(test_attributes, kSecAttrKeySizeInBits,
base::mac::NSToCFPtrCast(@256));
base::apple::NSToCFPtrCast(@256));
base::ScopedCFTypeRef<CFMutableDictionaryRef> private_key_params(
CFDictionaryCreateMutable(kCFAllocatorDefault, 0,
&kCFTypeDictionaryKeyCallBacks,
Expand Down Expand Up @@ -121,7 +121,7 @@ void VerifyQuery(CFDictionaryRef query, CFStringRef label) {
EXPECT_TRUE(CFEqual(kSecAttrTokenIDSecureEnclave,
base::mac::GetValueFromDictionary<CFStringRef>(
attributes, kSecAttrTokenID)));
EXPECT_TRUE(CFEqual(base::mac::NSToCFPtrCast(@256),
EXPECT_TRUE(CFEqual(base::apple::NSToCFPtrCast(@256),
base::mac::GetValueFromDictionary<CFNumberRef>(
attributes, kSecAttrKeySizeInBits)));
auto* private_key_attributes =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#include <memory>

#include "base/mac/bridging.h"
#include "base/apple/bridging.h"
#include "base/mac/scoped_cftyperef.h"

#if !defined(__has_feature) || !__has_feature(objc_arc)
Expand Down Expand Up @@ -49,7 +49,7 @@
bool SecureEnclaveHelperImpl::IsSecureEnclaveSupported() {
TKTokenWatcher* token_watcher = [[TKTokenWatcher alloc] init];
return ([token_watcher.tokenIDs
containsObject:base::mac::CFToNSPtrCast(kSecAttrTokenIDSecureEnclave)]);
containsObject:base::apple::CFToNSPtrCast(kSecAttrTokenIDSecureEnclave)]);
}

} // namespace enterprise_connectors
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
#include <utility>
#include <vector>

#include "base/apple/bridging.h"
#include "base/containers/span.h"
#include "base/mac/bridging.h"
#include "base/mac/scoped_cftyperef.h"
#include "chrome/browser/enterprise/connectors/device_trust/key_management/core/mac/mock_secure_enclave_client.h"
#include "chrome/browser/enterprise/connectors/device_trust/key_management/core/mac/secure_enclave_client.h"
Expand Down Expand Up @@ -54,7 +54,7 @@ void CreateTestKey() {
CFDictionarySetValue(test_attributes, kSecAttrKeyType,
kSecAttrKeyTypeECSECPrimeRandom);
CFDictionarySetValue(test_attributes, kSecAttrKeySizeInBits,
base::mac::NSToCFPtrCast(@256));
base::apple::NSToCFPtrCast(@256));
base::ScopedCFTypeRef<CFMutableDictionaryRef> private_key_params(
CFDictionaryCreateMutable(kCFAllocatorDefault, 0,
&kCFTypeDictionaryKeyCallBacks,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
#include <string>
#include <utility>

#include "base/apple/bridging.h"
#include "base/containers/span.h"
#include "base/mac/bridging.h"
#include "base/mac/scoped_cftyperef.h"
#include "base/strings/sys_string_conversions.h"
#include "chrome/browser/enterprise/connectors/device_trust/key_management/core/mac/mock_secure_enclave_client.h"
Expand Down Expand Up @@ -65,7 +65,7 @@ void SetMockClient() {
CFDictionarySetValue(test_attributes, kSecAttrKeyType,
kSecAttrKeyTypeECSECPrimeRandom);
CFDictionarySetValue(test_attributes, kSecAttrKeySizeInBits,
base::mac::NSToCFPtrCast(@256));
base::apple::NSToCFPtrCast(@256));
base::ScopedCFTypeRef<CFMutableDictionaryRef> private_key_params(
CFDictionaryCreateMutable(kCFAllocatorDefault, 0,
&kCFTypeDictionaryKeyCallBacks,
Expand Down
6 changes: 3 additions & 3 deletions chrome/browser/mac/keystone_glue.mm
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
#include <utility>
#include <vector>

#include "base/apple/bridging.h"
#include "base/file_version_info.h"
#include "base/functional/bind.h"
#include "base/location.h"
#include "base/logging.h"
#include "base/mac/authorization_util.h"
#include "base/mac/bridging.h"
#include "base/mac/bundle_locations.h"
#include "base/mac/foundation_util.h"
#include "base/mac/mac_logging.h"
Expand Down Expand Up @@ -818,7 +818,7 @@ - (BOOL)isAutoupdateEnabledForAllUsers {
// tests can pick it up.
+ (BOOL)isValidSystemKeystone:(NSDictionary*)systemKeystonePlistContents
comparedToBundled:(NSDictionary*)bundledKeystonePlistContents {
NSString* versionKey = base::mac::CFToNSPtrCast(kCFBundleVersionKey);
NSString* versionKey = base::apple::CFToNSPtrCast(kCFBundleVersionKey);

// If the bundled version is missing or broken, this question is irrelevant.
NSString* bundledKeystoneVersionString =
Expand Down Expand Up @@ -917,7 +917,7 @@ - (void)promoteTicket {
l10n_util::GetStringUTF16(IDS_PRODUCT_NAME));
base::mac::ScopedAuthorizationRef authorization =
base::mac::AuthorizationCreateToRunAsRoot(
base::mac::NSToCFPtrCast(prompt));
base::apple::NSToCFPtrCast(prompt));
if (!authorization) {
return;
}
Expand Down
8 changes: 4 additions & 4 deletions chrome/common/mac/app_mode_chrome_locator.mm
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

#include <set>

#include "base/apple/bridging.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/mac/bridging.h"
#include "base/mac/foundation_util.h"
#include "base/strings/sys_string_conversions.h"
#include "chrome/common/chrome_constants.h"
Expand Down Expand Up @@ -84,10 +84,10 @@ bool FindChromeBundle(NSString* bundle_id, base::FilePath* out_bundle) {
// Retrieve the last-run Chrome bundle location.
base::FilePath last_run_bundle_path;
{
NSString* cr_bundle_path_ns = base::mac::CFToNSOwnershipCast(
NSString* cr_bundle_path_ns = base::apple::CFToNSOwnershipCast(
base::mac::CFCastStrict<CFStringRef>(CFPreferencesCopyAppValue(
base::mac::NSToCFPtrCast(app_mode::kLastRunAppBundlePathPrefsKey),
base::mac::NSToCFPtrCast(bundle_id))));
base::apple::NSToCFPtrCast(app_mode::kLastRunAppBundlePathPrefsKey),
base::apple::NSToCFPtrCast(bundle_id))));
last_run_bundle_path = base::mac::NSStringToFilePath(cr_bundle_path_ns);
}

Expand Down
12 changes: 6 additions & 6 deletions chrome/updater/policy/mac/managed_preference_policy_manager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <string>
#include <vector>

#include "base/mac/bridging.h"
#include "base/apple/bridging.h"
#include "base/mac/scoped_cftyperef.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_refptr.h"
Expand Down Expand Up @@ -203,21 +203,21 @@

NSDictionary* ReadManagedPreferencePolicyDictionary() {
base::ScopedCFTypeRef<CFPropertyListRef> policies(CFPreferencesCopyAppValue(
base::mac::NSToCFPtrCast(kManagedPreferencesUpdatePolicies),
base::mac::NSToCFPtrCast(kKeystoneSharedPreferenceSuite)));
base::apple::NSToCFPtrCast(kManagedPreferencesUpdatePolicies),
base::apple::NSToCFPtrCast(kKeystoneSharedPreferenceSuite)));
if (!policies)
return nil;

if (!CFPreferencesAppValueIsForced(
base::mac::NSToCFPtrCast(kManagedPreferencesUpdatePolicies),
base::mac::NSToCFPtrCast(kKeystoneSharedPreferenceSuite))) {
base::apple::NSToCFPtrCast(kManagedPreferencesUpdatePolicies),
base::apple::NSToCFPtrCast(kKeystoneSharedPreferenceSuite))) {
return nil;
}

if (CFGetTypeID(policies) != CFDictionaryGetTypeID())
return nil;

return base::mac::CFToNSOwnershipCast((CFDictionaryRef)policies.release());
return base::apple::CFToNSOwnershipCast((CFDictionaryRef)policies.release());
}

scoped_refptr<PolicyManagerInterface> CreateManagedPreferencePolicyManager() {
Expand Down
4 changes: 2 additions & 2 deletions components/power_metrics/m1_sensors_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#include <utility>

#include "base/mac/bridging.h"
#include "base/apple/bridging.h"
#include "base/mac/foundation_util.h"
#include "base/memory/ptr_util.h"
#include "components/power_metrics/m1_sensors_internal_types_mac.h"
Expand Down Expand Up @@ -66,7 +66,7 @@ extern CFTypeRef IOHIDServiceClientCopyEvent(IOHIDServiceClientRef,
@kIOHIDPrimaryUsagePageKey : @(kHIDPage_AppleVendor),
@kIOHIDPrimaryUsageKey : @(kHIDUsage_AppleVendor_TemperatureSensor),
};
IOHIDEventSystemClientSetMatching(system, base::mac::NSToCFPtrCast(filter));
IOHIDEventSystemClientSetMatching(system, base::apple::NSToCFPtrCast(filter));

return base::WrapUnique(new M1SensorsReader(std::move(system)));
}
Expand Down
6 changes: 3 additions & 3 deletions components/services/quarantine/quarantine_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
#import <ApplicationServices/ApplicationServices.h>
#import <Foundation/Foundation.h>

#include "base/apple/bridging.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/logging.h"
#include "base/mac/bridging.h"
#include "base/mac/foundation_util.h"
#include "base/mac/mac_logging.h"
#include "base/mac/mac_util.h"
Expand Down Expand Up @@ -66,7 +66,7 @@ bool AddOriginMetadataToFile(const base::FilePath& file,
}

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

if (list.count) {
return MDItemSetAttribute(md_item, kMDItemWhereFroms,
base::mac::NSToCFPtrCast(list));
base::apple::NSToCFPtrCast(list));
}

return true;
Expand Down
4 changes: 2 additions & 2 deletions components/services/quarantine/quarantine_mac_unittest.mm
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
#import <ApplicationServices/ApplicationServices.h>
#import <Foundation/Foundation.h>

#include "base/apple/bridging.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/functional/bind.h"
#include "base/mac/bridging.h"
#include "base/mac/foundation_util.h"
#include "base/mac/scoped_cftyperef.h"
#include "base/run_loop.h"
Expand Down Expand Up @@ -169,7 +169,7 @@ void SetUp() override {
NSString* file_path = base::mac::FilePathToNSString(test_file_);
ASSERT_NE(nullptr, file_path);
base::ScopedCFTypeRef<MDItemRef> md_item(
MDItemCreate(kCFAllocatorDefault, base::mac::NSToCFPtrCast(file_path)));
MDItemCreate(kCFAllocatorDefault, base::apple::NSToCFPtrCast(file_path)));
if (!md_item) {
// The quarantine code ignores it if adding origin metadata fails. If for
// some reason MDItemCreate fails (which it seems to do on the bots, not
Expand Down
Loading

0 comments on commit cfa6125

Please sign in to comment.