#include <QObject>
#include <QHash>
+#include <QDateTime>
#include "accountstate.h"
public:
explicit FileProviderXPC(QObject *parent = nullptr);
- [[nodiscard]] bool fileProviderExtReachable(const QString &extensionAccountId) const;
+ [[nodiscard]] bool fileProviderExtReachable(const QString &extensionAccountId);
// Returns enabled and set state of fast enumeration for the given extension
[[nodiscard]] std::optional<std::pair<bool, bool>> fastEnumerationStateForExtension(const QString &extensionAccountId) const;
private:
QHash<QString, void*> _clientCommServices;
+ QDateTime _lastUnreachableTime;
};
} // namespace OCC::Mac
namespace {
constexpr int64_t semaphoreWaitDelta = 3000000000; // 3 seconds
+ constexpr auto reachableRetryTimeout = 60; // 60 seconds
}
namespace OCC::Mac {
}
}
-bool FileProviderXPC::fileProviderExtReachable(const QString &extensionAccountId) const
+bool FileProviderXPC::fileProviderExtReachable(const QString &extensionAccountId)
{
+ if (_lastUnreachableTime.isValid() && _lastUnreachableTime.secsTo(QDateTime::currentDateTime()) < ::reachableRetryTimeout) {
+ qCInfo(lcFileProviderXPC) << "File provider extension was unreachable less than a minute ago. "
+ << "Not checking again";
+ return false;
+ }
+
const auto service = (NSObject<ClientCommunicationProtocol> *)_clientCommServices.value(extensionAccountId);
if (service == nil) {
return false;
}
+
__block auto response = false;
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
[service getExtensionAccountIdWithCompletionHandler:^(NSString *const, NSError *const) {
dispatch_semaphore_signal(semaphore);
}];
dispatch_semaphore_wait(semaphore, dispatch_time(DISPATCH_TIME_NOW, semaphoreWaitDelta));
+
+ if (!response) {
+ qCWarning(lcFileProviderXPC) << "Could not reach file provider extension.";
+ _lastUnreachableTime = QDateTime::currentDateTime();
+ }
return response;
}