From ee82968c697c9ccf8a47e39dd84843d1d52bf545 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Tue, 5 Dec 2023 22:39:05 +0800 Subject: [PATCH] Cache NSXPCConnections when starting FileProviderXPC Signed-off-by: Claudio Cambra --- src/gui/macOS/fileproviderxpc_mac.mm | 41 +++++++++++++++++++--------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/src/gui/macOS/fileproviderxpc_mac.mm b/src/gui/macOS/fileproviderxpc_mac.mm index e4833e8ae1..09164772a6 100644 --- a/src/gui/macOS/fileproviderxpc_mac.mm +++ b/src/gui/macOS/fileproviderxpc_mac.mm @@ -125,6 +125,8 @@ void FileProviderXPC::start() return; } + NSMutableArray *const connections = NSMutableArray.array; + for (NSDictionary *const services in fpServices) { NSArray *const serviceNamesArray = services.allKeys; @@ -153,25 +155,38 @@ void FileProviderXPC::start() return; } - connection.remoteObjectInterface = [NSXPCInterface interfaceWithProtocol:@protocol(ClientCommunicationProtocol)]; - [connection resume]; - const id clientCommService = (id)[connection remoteObjectProxyWithErrorHandler:^(NSError *const error){ - qCWarning(lcFileProviderXPC) << "Error getting remote object proxy" << error; - dispatch_group_leave(group); - }]; - - if (clientCommService == nil) { - qCWarning(lcFileProviderXPC) << "Client communication service is nil"; - dispatch_group_leave(group); - return; - } - + [connection retain]; + [connections addObject:connection]; dispatch_group_leave(group); }]; } } dispatch_group_wait(group, DISPATCH_TIME_FOREVER); + + for (NSXPCConnection * const connection in connections) { + Q_ASSERT(connection != nil); + connection.remoteObjectInterface = [NSXPCInterface interfaceWithProtocol:@protocol(ClientCommunicationProtocol)]; + connection.interruptionHandler = ^{ + qCInfo(lcFileProviderXPC) << "File provider connection interrupted"; + }; + connection.invalidationHandler = ^{ + qCInfo(lcFileProviderXPC) << "File provider connection invalidated"; + }; + [connection resume]; + + const id remoteServiceObject = [connection remoteObjectProxyWithErrorHandler:^(NSError *const error){ + qCWarning(lcFileProviderXPC) << "Error getting remote object proxy" << error; + }]; + + NSObject *const clientCommService = (NSObject *)remoteServiceObject; + if (clientCommService == nil) { + qCWarning(lcFileProviderXPC) << "Client communication service is nil"; + continue; + } + + [clientCommService retain]; + } } } // namespace OCC