0

Move some base/apple/ files into base:🍎:

Bug: 1474628
Change-Id: I1ba27e9e5d692d4fbaad8830646fb70632d2cc57
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4799473
Reviewed-by: Mark Mentovai <mark@chromium.org>
Auto-Submit: Avi Drissman <avi@chromium.org>
Commit-Queue: Avi Drissman <avi@chromium.org>
Owners-Override: Avi Drissman <avi@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1186166}
This commit is contained in:
Avi Drissman
2023-08-21 23:57:01 +00:00
committed by Chromium LUCI CQ
parent 3990580934
commit 42f9d8fe64
21 changed files with 67 additions and 63 deletions

@ -6,7 +6,7 @@
#include "base/apple/scoped_dispatch_object.h"
namespace base {
namespace base::apple {
struct DispatchSourceMach::Storage {
// The dispatch queue used to service the source_.
@ -62,4 +62,4 @@ dispatch_queue_t DispatchSourceMach::Queue() const {
return storage_->queue.get();
}
} // namespace base
} // namespace base::apple

@ -11,7 +11,7 @@
#include "base/base_export.h"
namespace base {
namespace base::apple {
// This class encapsulates a MACH_RECV dispatch source. When this object is
// destroyed, the source will be cancelled and it will wait for the source
@ -50,6 +50,6 @@ class BASE_EXPORT DispatchSourceMach {
std::unique_ptr<Storage> storage_;
};
} // namespace base
} // namespace base::apple
#endif // BASE_APPLE_DISPATCH_SOURCE_MACH_H_

@ -13,7 +13,7 @@
#include "base/test/test_timeouts.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace base {
namespace base::apple {
class DispatchSourceMachTest : public testing::Test {
public:
@ -122,4 +122,4 @@ TEST_F(DispatchSourceMachTest, NoMessagesAfterDestruction) {
dispatch_release(queue);
}
} // namespace base
} // namespace base::apple

@ -17,7 +17,7 @@
#error Do not use this file, or allow it to be included, in Objective-C code.
#endif
namespace base {
namespace base::apple {
namespace internal {
@ -37,6 +37,6 @@ template <typename T>
using ScopedDispatchObject =
ScopedTypeRef<T, internal::ScopedDispatchObjectTraits<T>>;
} // namespace base
} // namespace base::apple
#endif // BASE_APPLE_SCOPED_DISPATCH_OBJECT_H_

@ -22,7 +22,7 @@
@class NSAutoreleasePool;
namespace base {
namespace base::apple {
// scoped_nsobject<> is patterned after std::unique_ptr<>, but maintains
// ownership of an NSObject subclass object. Style deviations here are solely
@ -97,6 +97,6 @@ class scoped_nsobject<id> : public scoped_nsprotocol<id> {
using scoped_nsprotocol<id>::scoped_nsprotocol;
};
} // namespace base
} // namespace base::apple
#endif // BASE_APPLE_SCOPED_NSOBJECT_H_

@ -14,17 +14,17 @@
namespace {
TEST(ScopedNSObjectTest, ScopedNSObject) {
base::scoped_nsobject<NSObject> p1([[NSObject alloc] init]);
base::apple::scoped_nsobject<NSObject> p1([[NSObject alloc] init]);
ASSERT_TRUE(p1.get());
ASSERT_EQ(1u, [p1 retainCount]);
base::scoped_nsobject<NSObject> p2(p1);
base::apple::scoped_nsobject<NSObject> p2(p1);
ASSERT_EQ(p1.get(), p2.get());
ASSERT_EQ(2u, [p1 retainCount]);
p2.reset();
ASSERT_EQ(nil, p2.get());
ASSERT_EQ(1u, [p1 retainCount]);
{
base::scoped_nsobject<NSObject> p3 = p1;
base::apple::scoped_nsobject<NSObject> p3 = p1;
ASSERT_EQ(p1.get(), p3.get());
ASSERT_EQ(2u, [p1 retainCount]);
@autoreleasepool {
@ -34,19 +34,19 @@ TEST(ScopedNSObjectTest, ScopedNSObject) {
ASSERT_EQ(2u, [p1 retainCount]);
}
ASSERT_EQ(1u, [p1 retainCount]);
base::scoped_nsobject<NSObject> p4([p1.get() retain]);
base::apple::scoped_nsobject<NSObject> p4([p1.get() retain]);
ASSERT_EQ(2u, [p1 retainCount]);
ASSERT_TRUE(p1 == p1.get());
ASSERT_TRUE(p1 == p1);
ASSERT_FALSE(p1 != p1);
ASSERT_FALSE(p1 != p1.get());
base::scoped_nsobject<NSObject> p5([[NSObject alloc] init]);
base::apple::scoped_nsobject<NSObject> p5([[NSObject alloc] init]);
ASSERT_TRUE(p1 != p5);
ASSERT_TRUE(p1 != p5.get());
ASSERT_FALSE(p1 == p5);
ASSERT_FALSE(p1 == p5.get());
base::scoped_nsobject<NSObject> p6 = p1;
base::apple::scoped_nsobject<NSObject> p6 = p1;
ASSERT_EQ(3u, [p6 retainCount]);
@autoreleasepool {
p6.autorelease();
@ -55,8 +55,8 @@ TEST(ScopedNSObjectTest, ScopedNSObject) {
}
ASSERT_EQ(2u, [p1 retainCount]);
base::scoped_nsobject<NSObject> p7([NSObject new]);
base::scoped_nsobject<NSObject> p8(std::move(p7));
base::apple::scoped_nsobject<NSObject> p7([NSObject new]);
base::apple::scoped_nsobject<NSObject> p8(std::move(p7));
ASSERT_TRUE(p8);
ASSERT_EQ(1u, [p8 retainCount]);
ASSERT_FALSE(p7.get());
@ -66,20 +66,21 @@ TEST(ScopedNSObjectTest, ScopedNSObject) {
// static_assert.
#if 0
TEST(ScopedNSObjectTest, FailToCreateScopedNSObjectAutoreleasePool) {
base::scoped_nsobject<NSAutoreleasePool> pool;
base::apple::scoped_nsobject<NSAutoreleasePool> pool;
}
#endif
TEST(ScopedNSObjectTest, ScopedNSObjectInContainer) {
base::scoped_nsobject<id> p([[NSObject alloc] init]);
base::apple::scoped_nsobject<id> p([[NSObject alloc] init]);
ASSERT_TRUE(p.get());
ASSERT_EQ(1u, [p retainCount]);
{
std::vector<base::scoped_nsobject<id>> objects;
std::vector<base::apple::scoped_nsobject<id>> objects;
objects.push_back(p);
ASSERT_EQ(2u, [p retainCount]);
ASSERT_EQ(p.get(), objects[0].get());
objects.push_back(base::scoped_nsobject<id>([[NSObject alloc] init]));
objects.push_back(
base::apple::scoped_nsobject<id>([[NSObject alloc] init]));
ASSERT_TRUE(objects[1].get());
ASSERT_EQ(1u, [objects[1] retainCount]);
}
@ -87,11 +88,11 @@ TEST(ScopedNSObjectTest, ScopedNSObjectInContainer) {
}
TEST(ScopedNSObjectTest, ScopedNSObjectFreeFunctions) {
base::scoped_nsobject<id> p1([[NSObject alloc] init]);
base::apple::scoped_nsobject<id> p1([[NSObject alloc] init]);
id o1 = p1.get();
ASSERT_TRUE(o1 == p1);
ASSERT_FALSE(o1 != p1);
base::scoped_nsobject<id> p2([[NSObject alloc] init]);
base::apple::scoped_nsobject<id> p2([[NSObject alloc] init]);
ASSERT_TRUE(o1 != p2);
ASSERT_FALSE(o1 == p2);
id o2 = p2.get();
@ -101,12 +102,12 @@ TEST(ScopedNSObjectTest, ScopedNSObjectFreeFunctions) {
}
TEST(ScopedNSObjectTest, ResetWithAnotherScopedNSObject) {
base::scoped_nsobject<id> p1([[NSObject alloc] init]);
base::apple::scoped_nsobject<id> p1([[NSObject alloc] init]);
id o1 = p1.get();
id o2 = nil;
{
base::scoped_nsobject<id> p2([[NSObject alloc] init]);
base::apple::scoped_nsobject<id> p2([[NSObject alloc] init]);
o2 = p2.get();
p1.reset(p2);
EXPECT_EQ(2u, [p1 retainCount]);

@ -76,7 +76,7 @@ class FilePathWatcherFSEvents : public FilePathWatcher::PlatformDelegate {
FilePathWatcher::Callback callback_;
// The dispatch queue on which the event stream is scheduled.
ScopedDispatchObject<dispatch_queue_t> queue_;
apple::ScopedDispatchObject<dispatch_queue_t> queue_;
// Target path to watch (passed to callback).
// (Only accessed from the libdispatch queue.)

@ -116,9 +116,10 @@ void MachPortRendezvousServer::RegisterPortsForPid(
DCHECK_LT(ports.size(), kMaximumRendezvousPorts);
DCHECK(!ports.empty());
ScopedDispatchObject<dispatch_source_t> exit_watcher(dispatch_source_create(
DISPATCH_SOURCE_TYPE_PROC, static_cast<uintptr_t>(pid),
DISPATCH_PROC_EXIT, dispatch_source_->Queue()));
apple::ScopedDispatchObject<dispatch_source_t> exit_watcher(
dispatch_source_create(DISPATCH_SOURCE_TYPE_PROC,
static_cast<uintptr_t>(pid), DISPATCH_PROC_EXIT,
dispatch_source_->Queue()));
dispatch_source_set_event_handler(exit_watcher, ^{
OnClientExited(pid);
});
@ -130,7 +131,7 @@ void MachPortRendezvousServer::RegisterPortsForPid(
}
MachPortRendezvousServer::ClientData::ClientData(
ScopedDispatchObject<dispatch_source_t> exit_watcher,
apple::ScopedDispatchObject<dispatch_source_t> exit_watcher,
MachPortsForRendezvous ports)
: exit_watcher(exit_watcher), ports(ports) {}
@ -147,7 +148,7 @@ MachPortRendezvousServer::MachPortRendezvousServer() {
BOOTSTRAP_CHECK(kr == KERN_SUCCESS, kr)
<< "bootstrap_check_in " << bootstrap_name;
dispatch_source_ = std::make_unique<DispatchSourceMach>(
dispatch_source_ = std::make_unique<apple::DispatchSourceMach>(
bootstrap_name.c_str(), server_port_.get(), ^{
HandleRequest();
});

@ -109,14 +109,14 @@ class BASE_EXPORT MachPortRendezvousServer {
friend struct MachPortRendezvousFuzzer;
struct ClientData {
ClientData(ScopedDispatchObject<dispatch_source_t> exit_watcher,
ClientData(apple::ScopedDispatchObject<dispatch_source_t> exit_watcher,
MachPortsForRendezvous ports);
ClientData(ClientData&&);
~ClientData();
// A DISPATCH_SOURCE_TYPE_PROC / DISPATCH_PROC_EXIT dispatch source. When
// the source is triggered, it calls OnClientExited().
ScopedDispatchObject<dispatch_source_t> exit_watcher;
apple::ScopedDispatchObject<dispatch_source_t> exit_watcher;
MachPortsForRendezvous ports;
};
@ -150,7 +150,7 @@ class BASE_EXPORT MachPortRendezvousServer {
apple::ScopedMachReceiveRight server_port_;
// Mach message dispatch source for |server_port_|.
std::unique_ptr<DispatchSourceMach> dispatch_source_;
std::unique_ptr<apple::DispatchSourceMach> dispatch_source_;
Lock lock_;
// Association of pid-to-ports.

@ -14,7 +14,7 @@ struct WaitableEventWatcher::Storage {
// A TYPE_MACH_RECV dispatch source on |receive_right_|. When a receive event
// is delivered, the message queue will be peeked and the bound |callback_|
// may be run. This will be null if nothing is currently being watched.
ScopedDispatchObject<dispatch_source_t> dispatch_source;
apple::ScopedDispatchObject<dispatch_source_t> dispatch_source;
};
WaitableEventWatcher::WaitableEventWatcher()

@ -42,7 +42,7 @@ void MachBootstrapAcceptor::Start() {
return;
}
dispatch_source_ = std::make_unique<base::DispatchSourceMach>(
dispatch_source_ = std::make_unique<base::apple::DispatchSourceMach>(
server_name_.c_str(), port(), ^{
HandleRequest();
});

@ -64,7 +64,7 @@ class MachBootstrapAcceptor {
mojo::NamedPlatformChannel::ServerName server_name_;
raw_ptr<Delegate, AcrossTasksDanglingUntriaged> delegate_;
mojo::PlatformChannelServerEndpoint endpoint_;
std::unique_ptr<base::DispatchSourceMach> dispatch_source_;
std::unique_ptr<base::apple::DispatchSourceMach> dispatch_source_;
};
} // namespace apps

@ -12,7 +12,7 @@
@interface ZombieCxxDestructTest : NSObject
{
base::scoped_nsobject<id> _aRef;
base::apple::scoped_nsobject<id> _aRef;
}
- (instancetype)initWith:(id)anObject;
@end
@ -53,12 +53,12 @@ namespace {
// NOTE(shess): To test the negative, comment out the |g_objectDestruct()|
// call in |ZombieDealloc()|.
TEST(ObjcZombieTest, CxxDestructors) {
base::scoped_nsobject<id> anObject([[NSObject alloc] init]);
base::apple::scoped_nsobject<id> anObject([[NSObject alloc] init]);
EXPECT_EQ(1u, [anObject retainCount]);
ASSERT_TRUE(ObjcEvilDoers::ZombieEnable(YES, 100));
base::scoped_nsobject<ZombieCxxDestructTest> soonInfected(
base::apple::scoped_nsobject<ZombieCxxDestructTest> soonInfected(
[[ZombieCxxDestructTest alloc] initWith:anObject]);
EXPECT_EQ(2u, [anObject retainCount]);
@ -75,12 +75,12 @@ TEST(ObjcZombieTest, CxxDestructors) {
// Verify that the associated objects are released when the object is
// released.
TEST(ObjcZombieTest, AssociatedObjectsReleased) {
base::scoped_nsobject<id> anObject([[NSObject alloc] init]);
base::apple::scoped_nsobject<id> anObject([[NSObject alloc] init]);
EXPECT_EQ(1u, [anObject retainCount]);
ASSERT_TRUE(ObjcEvilDoers::ZombieEnable(YES, 100));
base::scoped_nsobject<ZombieAssociatedObjectTest> soonInfected(
base::apple::scoped_nsobject<ZombieAssociatedObjectTest> soonInfected(
[[ZombieAssociatedObjectTest alloc] initWithAssociatedObject:anObject]);
EXPECT_EQ(2u, [anObject retainCount]);

@ -51,7 +51,8 @@ class SystemMemoryPressureEvaluator
void OnMemoryPressureChanged();
// The dispatch source that generates memory pressure change notifications.
base::ScopedDispatchObject<dispatch_source_t> memory_level_event_source_;
base::apple::ScopedDispatchObject<dispatch_source_t>
memory_level_event_source_;
// Timer that will re-notify with the current vote at regular interval.
base::RepeatingTimer renotify_current_vote_timer_;

@ -52,7 +52,7 @@ class NamedMojoServerEndpointConnectorMac final
// Note: |server_endpoint_| must outlive |dispatch_source_|.
mojo::PlatformChannelServerEndpoint server_endpoint_;
std::unique_ptr<base::DispatchSourceMach> dispatch_source_;
std::unique_ptr<base::apple::DispatchSourceMach> dispatch_source_;
};
NamedMojoServerEndpointConnectorMac::NamedMojoServerEndpointConnectorMac(
@ -120,7 +120,7 @@ bool NamedMojoServerEndpointConnectorMac::TryStart() {
}
server_endpoint_ = std::move(server_endpoint);
dispatch_source_ = std::make_unique<base::DispatchSourceMach>(
dispatch_source_ = std::make_unique<base::apple::DispatchSourceMach>(
options_.server_name.c_str(), port(), ^{
HandleRequest();
});

@ -58,7 +58,7 @@ ChildProcessTaskPortProvider::ChildProcessTaskPortProvider() {
const std::string dispatch_name = base::StringPrintf(
"%s.ChildProcessTaskPortProvider.%p", base::apple::BaseBundleID(), this);
notification_source_ = std::make_unique<base::DispatchSourceMach>(
notification_source_ = std::make_unique<base::apple::DispatchSourceMach>(
dispatch_name.c_str(), notification_port_.get(), ^{
OnTaskPortDied();
});

@ -82,7 +82,7 @@ class CONTENT_EXPORT ChildProcessTaskPortProvider : public base::PortProvider {
base::apple::ScopedMachReceiveRight notification_port_;
// Dispatch source for |notification_port_|.
std::unique_ptr<base::DispatchSourceMach> notification_source_;
std::unique_ptr<base::apple::DispatchSourceMach> notification_source_;
};
} // namespace content

@ -186,9 +186,9 @@ not compile with ARC, but that are no longer needed with ARC code. Because there
are still parts of Chromium that cannot be compiled with ARC, these utilities
remain, however they should not (or sometimes cannot) be used from ARC:
- `base::scoped_nsobject<>`: This only exists to handle scoping of Objective-C
objects in non-ARC code. It cannot be used in ARC code; use `__strong`
instead.
- `scoped_nsobject<>`/`scoped_nsprotocol<>`: These only exists to handle scoping
of Objective-C objects in non-ARC code. They cannot be used in ARC code; use
`__strong` instead.
- `ScopedNSAutoreleasePool`: Use `@autoreleasepool` instead, and remove any use
of `ScopedNSAutoreleasePool` that you encounter, if possible.
`ScopedNSAutoreleasePool` was rewritten to be able to work in ARC code, but

@ -221,7 +221,7 @@ class SharedEventAndSignalValue : public BackpressureMetalSharedEvent {
uint64_t signaled_value() const { return signaled_value_; }
private:
base::scoped_nsprotocol<id<MTLSharedEvent>> shared_event_;
base::apple::scoped_nsprotocol<id<MTLSharedEvent>> shared_event_;
uint64_t signaled_value_;
};

@ -91,21 +91,21 @@ gfx::BufferFormat GetBufferFormatForPlane(viz::SharedImageFormat format,
#if BUILDFLAG(SKIA_USE_METAL)
base::scoped_nsprotocol<id<MTLTexture>> CreateMetalTexture(
base::apple::scoped_nsprotocol<id<MTLTexture>> CreateMetalTexture(
id<MTLDevice> mtl_device,
IOSurfaceRef io_surface,
const gfx::Size& size,
viz::SharedImageFormat format,
int plane_index) {
TRACE_EVENT0("gpu", "IOSurfaceImageBackingFactory::CreateMetalTexture");
base::scoped_nsprotocol<id<MTLTexture>> mtl_texture;
base::apple::scoped_nsprotocol<id<MTLTexture>> mtl_texture;
MTLPixelFormat mtl_pixel_format =
static_cast<MTLPixelFormat>(ToMTLPixelFormat(format, plane_index));
if (mtl_pixel_format == MTLPixelFormatInvalid) {
return mtl_texture;
}
base::scoped_nsobject<MTLTextureDescriptor> mtl_tex_desc(
base::apple::scoped_nsobject<MTLTextureDescriptor> mtl_tex_desc(
[MTLTextureDescriptor new]);
[mtl_tex_desc setTextureType:MTLTextureType2D];
[mtl_tex_desc
@ -134,7 +134,7 @@ base::scoped_nsprotocol<id<MTLTexture>> CreateMetalTexture(
}
std::vector<skgpu::graphite::BackendTexture> CreateGraphiteMetalTextures(
std::vector<base::scoped_nsprotocol<id<MTLTexture>>> mtl_textures,
std::vector<base::apple::scoped_nsprotocol<id<MTLTexture>>> mtl_textures,
const viz::SharedImageFormat format,
const gfx::Size& size) {
int num_planes = format.NumberOfPlanes();
@ -399,7 +399,7 @@ class IOSurfaceImageBacking::SkiaGraphiteIOSurfaceRepresentation
SharedImageBacking* backing,
MemoryTypeTracker* tracker,
skgpu::graphite::Recorder* recorder,
std::vector<base::scoped_nsprotocol<id<MTLTexture>>> mtl_textures)
std::vector<base::apple::scoped_nsprotocol<id<MTLTexture>>> mtl_textures)
: SkiaGraphiteImageRepresentation(manager, backing, tracker),
recorder_(recorder),
mtl_textures_(std::move(mtl_textures)) {
@ -482,7 +482,7 @@ class IOSurfaceImageBacking::SkiaGraphiteIOSurfaceRepresentation
}
const raw_ptr<skgpu::graphite::Recorder> recorder_;
std::vector<base::scoped_nsprotocol<id<MTLTexture>>> mtl_textures_;
std::vector<base::apple::scoped_nsprotocol<id<MTLTexture>>> mtl_textures_;
std::vector<sk_sp<SkSurface>> write_surfaces_;
};
#endif
@ -1125,14 +1125,15 @@ IOSurfaceImageBacking::ProduceSkiaGraphite(
} else {
CHECK_EQ(context_state->gr_context_type(), GrContextType::kGraphiteMetal);
#if BUILDFLAG(SKIA_USE_METAL)
std::vector<base::scoped_nsprotocol<id<MTLTexture>>> mtl_textures;
std::vector<base::apple::scoped_nsprotocol<id<MTLTexture>>> mtl_textures;
mtl_textures.reserve(format().NumberOfPlanes());
for (int plane = 0; plane < format().NumberOfPlanes(); plane++) {
auto plane_size = format().GetPlaneSize(plane, size());
base::scoped_nsprotocol<id<MTLTexture>> mtl_texture = CreateMetalTexture(
context_state->metal_context_provider()->GetMTLDevice(),
io_surface_.get(), plane_size, format(), plane);
base::apple::scoped_nsprotocol<id<MTLTexture>> mtl_texture =
CreateMetalTexture(
context_state->metal_context_provider()->GetMTLDevice(),
io_surface_.get(), plane_size, format(), plane);
if (!mtl_texture) {
LOG(ERROR) << "Failed to create MTLTexture from IOSurface";
return nullptr;

@ -22,7 +22,7 @@
namespace gl {
struct GLDisplayEGL::ObjCStorage {
base::scoped_nsprotocol<id<MTLSharedEvent>> metal_shared_event;
base::apple::scoped_nsprotocol<id<MTLSharedEvent>> metal_shared_event;
uint64_t metal_signaled_value = 0;
};