// Copyright Epic Games, Inc. All Rights Reserved. #pragma once #include "BackgroundHttpNotificationObject.h" #include "Containers/Array.h" #include "Containers/UnrealString.h" #include "Interfaces/IBackgroundHttpRequest.h" #include "Logging/LogMacros.h" #include "Templates/SharedPointer.h" #include "Async/Mutex.h" DECLARE_LOG_CATEGORY_EXTERN(LogBackgroundHttpRequest, Log, All) /** * Contains implementation of some common functions that don't have to vary between implementation */ class FBackgroundHttpRequestImpl : public IBackgroundHttpRequest { public: BACKGROUNDHTTP_API FBackgroundHttpRequestImpl(); virtual ~FBackgroundHttpRequestImpl() {} //This should be called from the platform level when a BG download finishes. BACKGROUNDHTTP_API virtual void OnBackgroundDownloadComplete(); // IBackgroundHttpRequest BACKGROUNDHTTP_API virtual bool ProcessRequest() override; BACKGROUNDHTTP_API virtual void CancelRequest() override; BACKGROUNDHTTP_API virtual void PauseRequest() override; BACKGROUNDHTTP_API virtual void ResumeRequest() override; BACKGROUNDHTTP_API virtual void SetURLAsList(const TArray& URLs, int NumRetriesToAttempt) override; BACKGROUNDHTTP_API virtual const TArray& GetURLList() const override; BACKGROUNDHTTP_API virtual void SetExpectedResultSize(const uint64 ExpectedSize) override; BACKGROUNDHTTP_API virtual uint64 GetExpectedResultSize() const override; BACKGROUNDHTTP_API virtual void SetCompleteNotification(FBackgroundHttpNotificationObjectPtr DownloadCompleteNotificationObjectIn) override; BACKGROUNDHTTP_API virtual void CompleteWithExistingResponseData(FBackgroundHttpResponsePtr BackgroundResponse) override; BACKGROUNDHTTP_API virtual FBackgroundHttpRequestCompleteDelegate& OnProcessRequestComplete() override; BACKGROUNDHTTP_API virtual FBackgroundHttpProgressUpdateDelegate& OnProgressUpdated() override; UE_DEPRECATED(5.7, "FBackgroundHttpRequestImpl::OnRequestMetrics is deprecated, please use OnRequestMetricsExtended instead.") BACKGROUNDHTTP_API virtual FBackgroundHttpRequestMetricsDelegate& OnRequestMetrics() override; BACKGROUNDHTTP_API virtual FBackgroundHttpRequestMetricsExtendedDelegate& OnRequestMetricsExtended() override; BACKGROUNDHTTP_API virtual const FBackgroundHttpResponsePtr GetResponse() const override; BACKGROUNDHTTP_API virtual const FString& GetRequestID() const override; BACKGROUNDHTTP_API virtual void SetRequestID(const FString& NewRequestID) override; BACKGROUNDHTTP_API virtual bool HandleDelayedProcess() override; BACKGROUNDHTTP_API virtual EBackgroundHTTPPriority GetRequestPriority() const override; BACKGROUNDHTTP_API virtual void SetRequestPriority(EBackgroundHTTPPriority NewPriority) override; BACKGROUNDHTTP_API virtual void NotifyNotificationObjectOfComplete(const bool bWasSuccess); UE_DEPRECATED(5.7, "FBackgroundHttpRequestImpl::NotifyRequestMetricsAvailable is deprecated, please use NotifyRequestMetricsExtendedAvailable instead.") BACKGROUNDHTTP_API virtual void NotifyRequestMetricsAvailable(const int32 TotalBytesDownloaded, const float DownloadDuration); BACKGROUNDHTTP_API virtual void NotifyRequestMetricsExtendedAvailable(const FBackgroundHttpRequestMetricsExtended ExtendedMetrics); UE_DEPRECATED(5.7, "FBackgroundHttpRequestImpl::SetMetrics is deprecated, please use SetMetricsExtended instead.") BACKGROUNDHTTP_API virtual void SetMetrics(const int32 TotalBytesDownloaded, const float DownloadDuration) override; BACKGROUNDHTTP_API virtual void SetMetricsExtended(const FBackgroundHttpRequestMetricsExtended ExtendedMetrics) override; protected: UE::FMutex DownloadCompleteMutex; TSharedPtr DownloadCompleteNotificationObject; FBackgroundHttpResponsePtr Response; TArray URLList; FString RequestID; int NumberOfTotalRetries; EBackgroundHTTPPriority RequestPriority; uint64 ExpectedResultSize; using FDownloadMetricsInfo = FBackgroundHttpRequestMetricsExtended; TOptional OptionalMetricsInfo; FBackgroundHttpRequestCompleteDelegate HttpRequestCompleteDelegate; FBackgroundHttpProgressUpdateDelegate HttpProgressUpdateDelegate; FBackgroundHttpRequestMetricsDelegate HttpRequestMetricsDelegate; FBackgroundHttpRequestMetricsExtendedDelegate HttpRequestMetricsExtendedDelegate; };