summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Moe Gustavsen <richard.gustavsen@theqtcompany.com>2015-04-24 12:14:49 +0200
committerRichard Moe Gustavsen <richard.gustavsen@theqtcompany.com>2015-05-06 19:46:58 +0000
commit856debeec13d0ea19f97a627c9e7d6f6732be944 (patch)
tree2765c9496058b5a0524a510d104bac1f637f2444
parent8628dd71584099a338e2985718668219f31509ce (diff)
ios: factor out authorization check
Factor out the check since it's needed both when loading assets and when creating an entry list. Note that the file flags returned from the file engine will report if the asset is not readable due to authorization status, so we don't need to check this again when trying to load. Change-Id: I77ebbc370f0a7a6020ed484e53ece32bc7fa51bd Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@theqtcompany.com>
-rw-r--r--src/plugins/platforms/ios/qiosfileengineassetslibrary.mm61
1 files changed, 32 insertions, 29 deletions
diff --git a/src/plugins/platforms/ios/qiosfileengineassetslibrary.mm b/src/plugins/platforms/ios/qiosfileengineassetslibrary.mm
index 44766b0666..c7809c75e0 100644
--- a/src/plugins/platforms/ios/qiosfileengineassetslibrary.mm
+++ b/src/plugins/platforms/ios/qiosfileengineassetslibrary.mm
@@ -47,6 +47,24 @@ static QThreadStorage<QString> g_iteratorCurrentUrl;
static const int kBufferSize = 10;
static ALAsset *kNoAsset = 0;
+static void ensureAuthorizationDialogNotBlocked()
+{
+ if ([ALAssetsLibrary authorizationStatus] != ALAuthorizationStatusNotDetermined)
+ return;
+ if (static_cast<QCoreApplicationPrivate *>(QObjectPrivate::get(qApp))->in_exec)
+ return;
+
+ // Since authorization status has not been determined, the user will be asked
+ // to authorize the app. But since main has not finished, the dialog will be held
+ // back until the launch completes. To avoid a dead-lock below, we start an event
+ // loop to complete the launch.
+ QEventLoop loop;
+ QTimer::singleShot(1, &loop, &QEventLoop::quit);
+ loop.exec();
+}
+
+// -------------------------------------------------------------------------
+
class QIOSAssetEnumerator
{
public:
@@ -61,6 +79,7 @@ public:
, m_writeIndex(0)
, m_nextAssetReady(false)
{
+ ensureAuthorizationDialogNotBlocked();
startEnumerate();
}
@@ -166,35 +185,19 @@ public:
, m_assetUrl(assetUrl)
, m_assetLibrary(0)
{
- switch ([ALAssetsLibrary authorizationStatus]) {
- case ALAuthorizationStatusRestricted:
- case ALAuthorizationStatusDenied:
- engine->setError(QFile::PermissionsError, QLatin1String("Unauthorized access"));
- return;
- case ALAuthorizationStatusNotDetermined:
- if (!static_cast<QCoreApplicationPrivate *>(QObjectPrivate::get(qApp))->in_exec) {
- // Since authorization status has not been determined, the user will be asked
- // to authorize the app. But since main has not finished, the dialog will be held
- // back until the launch completes. To avoid a dead-lock below, we start an event
- // loop to complete the launch.
- QEventLoop loop;
- QTimer::singleShot(1, &loop, &QEventLoop::quit);
- loop.exec();
- }
- break;
- default:
- if (g_currentAssetData) {
- // It's a common pattern that QFiles pointing to the same path are created and destroyed
- // several times during a single event loop cycle. To avoid loading the same asset
- // over and over, we check if the last loaded asset has not been destroyed yet, and try to
- // reuse its data. Since QFile is (mostly) reentrant, we need to protect m_currentAssetData
- // from being modified by several threads at the same time.
- QMutexLocker lock(&g_mutex);
- if (g_currentAssetData && g_currentAssetData->m_assetUrl == assetUrl) {
- m_assetLibrary = [g_currentAssetData->m_assetLibrary retain];
- m_asset = [g_currentAssetData->m_asset retain];
- return;
- }
+ ensureAuthorizationDialogNotBlocked();
+
+ if (g_currentAssetData) {
+ // It's a common pattern that QFiles pointing to the same path are created and destroyed
+ // several times during a single event loop cycle. To avoid loading the same asset
+ // over and over, we check if the last loaded asset has not been destroyed yet, and try to
+ // reuse its data. Since QFile is (mostly) reentrant, we need to protect m_currentAssetData
+ // from being modified by several threads at the same time.
+ QMutexLocker lock(&g_mutex);
+ if (g_currentAssetData && g_currentAssetData->m_assetUrl == assetUrl) {
+ m_assetLibrary = [g_currentAssetData->m_assetLibrary retain];
+ m_asset = [g_currentAssetData->m_asset retain];
+ return;
}
}