wsd: make checkFileInfo call explicit
When we call checkFileInfo from the constructor of CheckFileInfo, it is possible for the callback to get fired immediately if we fail to open a socket. In that case, the caller would have had no chance of having stored the reference to the CheckFileInfo object instance, so the callback would fire without the owner having a way to properly do housekeeping. By moving the call outside of the constructor and making it explicit, we allow for a better management of the CheckFileInfo object instance. Change-Id: I3094b73fa3ab70e83ec5238959defcb2fd9ecf4e Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>pull/8752/head
parent
d60d19eb7a
commit
f3b10c3790
|
@ -250,7 +250,7 @@ void RequestVettingStation::handleRequest(const std::string& id,
|
|||
#if !MOBILEAPP
|
||||
void RequestVettingStation::checkFileInfo(const Poco::URI& uri, bool isReadOnly, int redirectLimit)
|
||||
{
|
||||
auto cfiContinuation = [this, isReadOnly]([[maybe_unused]] CheckFileInfo& checkFileInfo)
|
||||
auto cfiContinuation = [this, isReadOnly](CheckFileInfo& checkFileInfo)
|
||||
{
|
||||
assert(&checkFileInfo == _checkFileInfo.get() && "Unknown CheckFileInfo instance");
|
||||
if (_checkFileInfo && _checkFileInfo->state() == CheckFileInfo::State::Pass &&
|
||||
|
@ -300,8 +300,9 @@ void RequestVettingStation::checkFileInfo(const Poco::URI& uri, bool isReadOnly,
|
|||
};
|
||||
|
||||
// CheckFileInfo asynchronously.
|
||||
_checkFileInfo =
|
||||
std::make_unique<CheckFileInfo>(_poll, uri, std::move(cfiContinuation), redirectLimit);
|
||||
assert(_checkFileInfo == nullptr);
|
||||
_checkFileInfo = std::make_unique<CheckFileInfo>(_poll, uri, std::move(cfiContinuation));
|
||||
_checkFileInfo->checkFileInfo(redirectLimit);
|
||||
}
|
||||
#endif //!MOBILEAPP
|
||||
|
||||
|
|
|
@ -31,17 +31,13 @@
|
|||
|
||||
class CheckFileInfo
|
||||
{
|
||||
/// Limits number of HTTP redirections to prevent from redirection loops.
|
||||
static constexpr auto RedirectionLimit = 21;
|
||||
|
||||
public:
|
||||
/// The CheckFileInfo State.
|
||||
STATE_ENUM(State, None, Active, Timedout, Fail, Pass);
|
||||
|
||||
/// Create an instance with a SocketPoll and a RequestDetails instance.
|
||||
CheckFileInfo(const std::shared_ptr<TerminatingPoll>& poll, const Poco::URI& url,
|
||||
std::function<void(CheckFileInfo&)> onFinishCallback,
|
||||
int redirectionLimit = RedirectionLimit)
|
||||
std::function<void(CheckFileInfo&)> onFinishCallback)
|
||||
: _poll(poll)
|
||||
, _url(url)
|
||||
, _docKey(RequestDetails::getDocKey(url))
|
||||
|
@ -51,8 +47,6 @@ public:
|
|||
{
|
||||
assert(_url == RequestDetails::sanitizeURI(url.toString()) && "Expected sanitized URL");
|
||||
|
||||
// Start the request.
|
||||
checkFileInfo(redirectionLimit);
|
||||
}
|
||||
|
||||
/// Returns the state of the request.
|
||||
|
@ -70,6 +64,9 @@ public:
|
|||
/// Returns the parsed wopiInfo JSON into FileInfo.
|
||||
std::unique_ptr<WopiStorage::WOPIFileInfo> wopiFileInfo(const Poco::URI& uriPublic) const;
|
||||
|
||||
/// Start the actual request.
|
||||
void checkFileInfo(int redirectionLimit);
|
||||
|
||||
private:
|
||||
inline void logPrefix(std::ostream& os) const
|
||||
{
|
||||
|
@ -79,9 +76,6 @@ private:
|
|||
}
|
||||
}
|
||||
|
||||
/// Start the actual request.
|
||||
void checkFileInfo(int redirectionLimit);
|
||||
|
||||
std::shared_ptr<TerminatingPoll> _poll;
|
||||
Poco::URI _url; //< Sanitized URL to the document. Can change through redirection.
|
||||
const std::string _docKey; //< Unique DocKey.
|
||||
|
|
|
@ -203,8 +203,8 @@ void WopiProxy::checkFileInfo(const std::shared_ptr<TerminatingPoll>& poll, cons
|
|||
};
|
||||
|
||||
// CheckFileInfo asynchronously.
|
||||
_checkFileInfo =
|
||||
std::make_unique<CheckFileInfo>(poll, uri, std::move(cfiContinuation), redirectLimit);
|
||||
_checkFileInfo = std::make_unique<CheckFileInfo>(poll, uri, std::move(cfiContinuation));
|
||||
_checkFileInfo->checkFileInfo(redirectLimit);
|
||||
}
|
||||
|
||||
void WopiProxy::download(const std::shared_ptr<TerminatingPoll>& poll, const std::string& url,
|
||||
|
|
Loading…
Reference in New Issue