Clean up FileProviderXPC code, separate everything into single-responsibility methods

Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
This commit is contained in:
Claudio Cambra 2023-12-27 19:10:37 +08:00
parent 5ee2cfa749
commit 95bebc5214
3 changed files with 25 additions and 5 deletions

View file

@ -60,7 +60,8 @@ FileProvider::FileProvider(QObject * const parent)
_xpc = std::make_unique<FileProviderXPC>(new FileProviderXPC(this));
if (_xpc) {
qCInfo(lcMacFileProvider) << "Initialised file provider XPC.";
_xpc->start();
_xpc->connectToExtensions();
_xpc->configureExtensions();
} else {
qCWarning(lcMacFileProvider) << "Could not initialise file provider XPC.";
}

View file

@ -16,6 +16,8 @@
#include <QObject>
#import <Foundation/Foundation.h>
namespace OCC {
namespace Mac {
@ -28,7 +30,14 @@ public:
explicit FileProviderXPC(QObject *parent = nullptr);
public slots:
void start();
void connectToExtensions();
void configureExtensions();
private:
void setupConnections();
void processConnections(NSArray *const services);
NSArray *_clientCommServices;
};
}

View file

@ -32,7 +32,7 @@ FileProviderXPC::FileProviderXPC(QObject *parent)
{
}
void FileProviderXPC::start()
void FileProviderXPC::connectToExtensions()
{
qCInfo(lcFileProviderXPC) << "Starting file provider XPC";
@ -40,6 +40,11 @@ void FileProviderXPC::start()
const auto domainUrls = FileProviderXPCUtils::getDomainUrlsForManagers(managers);
const auto fpServices = FileProviderXPCUtils::getFileProviderServicesAtUrls(domainUrls);
const auto connections = FileProviderXPCUtils::connectToFileProviderServices(fpServices);
processConnections(connections);
}
void FileProviderXPC::processConnections(NSArray *const connections)
{
dispatch_group_t group = dispatch_group_create();
NSMutableDictionary<NSString *, NSObject<ClientCommunicationProtocol>*> *const clientCommServices = NSMutableDictionary.dictionary;
@ -95,7 +100,12 @@ void FileProviderXPC::start()
[clientCommServices setObject:clientCommService forKey:extensionNcAccount];
}
for (NSString *const extensionNcAccount in clientCommServices) {
_clientCommServices = clientCommServices.copy;
}
void FileProviderXPC::configureExtensions()
{
for (NSString *const extensionNcAccount in _clientCommServices) {
qCInfo(lcFileProviderXPC) << "Sending message to client communication service";
const auto qExtensionNcAccount = QString::fromNSString(extensionNcAccount);
@ -116,7 +126,7 @@ void FileProviderXPC::start()
NSString *const serverUrl = account->url().toString().toNSString();
NSString *const password = credentials->password().toNSString();
NSObject<ClientCommunicationProtocol> *const clientCommService = [clientCommServices objectForKey:extensionNcAccount];
NSObject<ClientCommunicationProtocol> *const clientCommService = [_clientCommServices objectForKey:extensionNcAccount];
[clientCommService configureAccountWithUser:user
serverUrl:serverUrl
password:password];