From af22ab55bbf8a136ac5f87d7dff3e6b0cab620f7 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Thu, 29 Aug 2019 08:46:46 -0700 Subject: [PATCH] PR feedback --- .../ui/src/ui/types/ContextAwareProfile.cpp | 14 ++++++------- .../ui/src/ui/types/ContextAwareProfile.h | 21 +++++++++++++------ 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/libraries/ui/src/ui/types/ContextAwareProfile.cpp b/libraries/ui/src/ui/types/ContextAwareProfile.cpp index ee47435d4d..f0b06f2b21 100644 --- a/libraries/ui/src/ui/types/ContextAwareProfile.cpp +++ b/libraries/ui/src/ui/types/ContextAwareProfile.cpp @@ -10,19 +10,20 @@ // #include "ContextAwareProfile.h" -#if !defined(Q_OS_ANDROID) +#include #include #include #include #include - static const QString RESTRICTED_FLAG_PROPERTY = "RestrictFileAccess"; ContextAwareProfile::ContextAwareProfile(QQmlContext* context) : - QQuickWebEngineProfile(context), _context(context) { } + QQuickWebEngineProfile(context), _context(context) { + assert(context); +} void ContextAwareProfile::restrictContext(QQmlContext* context, bool restrict) { @@ -40,12 +41,9 @@ bool ContextAwareProfile::isRestrictedInternal() { bool ContextAwareProfile::isRestricted() { auto now = usecTimestampNow(); - auto cacheAge = now - _lastCacheCheck; - if (cacheAge > MAX_CACHE_AGE) { + if (now > _cacheExpiry) { _cachedValue = isRestrictedInternal(); - _lastCacheCheck = now; + _cacheExpiry = now + MAX_CACHE_AGE; } return _cachedValue; } - -#endif \ No newline at end of file diff --git a/libraries/ui/src/ui/types/ContextAwareProfile.h b/libraries/ui/src/ui/types/ContextAwareProfile.h index b55f95c180..3192d2be54 100644 --- a/libraries/ui/src/ui/types/ContextAwareProfile.h +++ b/libraries/ui/src/ui/types/ContextAwareProfile.h @@ -16,11 +16,21 @@ #if !defined(Q_OS_ANDROID) #include #include + +using ContextAwareProfileParent = QQuickWebEngineProfile; +using RequestInterceptorParent = QWebEngineUrlRequestInterceptor; +#else +#include + +using ContextAwareProfileParent = QObject; +using RequestInterceptorParent = QObject; +#endif + #include class QQmlContext; -class ContextAwareProfile : public QQuickWebEngineProfile { +class ContextAwareProfile : public ContextAwareProfileParent { Q_OBJECT public: static void restrictContext(QQmlContext* context, bool restrict = true); @@ -28,9 +38,9 @@ public: Q_INVOKABLE bool isRestrictedInternal(); protected: - class RequestInterceptor : public QWebEngineUrlRequestInterceptor { + class RequestInterceptor : public RequestInterceptorParent { public: - RequestInterceptor(ContextAwareProfile* parent) : QWebEngineUrlRequestInterceptor(parent), _profile(parent) {} + RequestInterceptor(ContextAwareProfile* parent) : RequestInterceptorParent(parent), _profile(parent) { } bool isRestricted() { return _profile->isRestricted(); } protected: ContextAwareProfile* _profile; @@ -39,9 +49,8 @@ protected: ContextAwareProfile(QQmlContext* parent); QQmlContext* _context{ nullptr }; bool _cachedValue{ false }; - quint64 _lastCacheCheck{ 0 }; - static const quint64 MAX_CACHE_AGE = MSECS_PER_SECOND; + quint64 _cacheExpiry{ 0 }; + constexpr static quint64 MAX_CACHE_AGE = MSECS_PER_SECOND; }; -#endif #endif // hifi_FileTypeProfile_h