wsd: pass ClientSession to checkAndUploadToStorage
And to handleSaveResponse. Change-Id: I01d7bc0424df7f1b4998d9698cdfcadbaaabc704 Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
This commit is contained in:
parent
68beb87b7b
commit
b507d5bb08
3 changed files with 18 additions and 33 deletions
|
@ -1511,7 +1511,7 @@ bool ClientSession::handleKitToClientMessage(const std::shared_ptr<Message>& pay
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save to Storage and log result.
|
// Save to Storage and log result.
|
||||||
docBroker->handleSaveResponse(getId(), success, result);
|
docBroker->handleSaveResponse(client_from_this(), success, result);
|
||||||
|
|
||||||
if (!isCloseFrame())
|
if (!isCloseFrame())
|
||||||
forwardToClient(payload);
|
forwardToClient(payload);
|
||||||
|
|
|
@ -1257,7 +1257,7 @@ bool DocumentBroker::isStorageOutdated() const
|
||||||
return currentModifiedTime != lastModifiedTime;
|
return currentModifiedTime != lastModifiedTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DocumentBroker::handleSaveResponse(const std::string& sessionId, bool success,
|
void DocumentBroker::handleSaveResponse(const std::shared_ptr<ClientSession>& session, bool success,
|
||||||
const std::string& result)
|
const std::string& result)
|
||||||
{
|
{
|
||||||
assertCorrectThread();
|
assertCorrectThread();
|
||||||
|
@ -1317,24 +1317,20 @@ void DocumentBroker::handleSaveResponse(const std::string& sessionId, bool succe
|
||||||
// The the clients know of any save failures.
|
// The the clients know of any save failures.
|
||||||
if (!success && result != "unmodified")
|
if (!success && result != "unmodified")
|
||||||
{
|
{
|
||||||
const auto it = _sessions.find(sessionId);
|
LOG_INF("Failed to save docKey [" << _docKey
|
||||||
if (it != _sessions.end())
|
<< "] as .uno:Save has failed in LOK. Notifying clients");
|
||||||
{
|
session->sendTextFrameAndLogError("error: cmd=storage kind=savefailed");
|
||||||
LOG_INF("Failed to save docKey ["
|
broadcastSaveResult(false, "Could not save the document");
|
||||||
<< _docKey << "] as .uno:Save has failed in LOK. Notifying client "
|
|
||||||
<< sessionId);
|
|
||||||
it->second->sendTextFrameAndLogError("error: cmd=storage kind=savefailed");
|
|
||||||
broadcastSaveResult(false, "Could not save the document");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
checkAndUploadToStorage(sessionId);
|
checkAndUploadToStorage(session);
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is called when either we just got save response, or,
|
// This is called when either we just got save response, or,
|
||||||
// there was nothing to save and want to check for uploading.
|
// there was nothing to save and want to check for uploading.
|
||||||
void DocumentBroker::checkAndUploadToStorage(const std::string& sessionId)
|
void DocumentBroker::checkAndUploadToStorage(const std::shared_ptr<ClientSession>& session)
|
||||||
{
|
{
|
||||||
|
const std::string sessionId = session->getId();
|
||||||
LOG_TRC("checkAndUploadToStorage with session " << sessionId);
|
LOG_TRC("checkAndUploadToStorage with session " << sessionId);
|
||||||
|
|
||||||
// See if we have anything to upload.
|
// See if we have anything to upload.
|
||||||
|
@ -1381,28 +1377,16 @@ void DocumentBroker::checkAndUploadToStorage(const std::string& sessionId)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const auto it = _sessions.find(sessionId);
|
|
||||||
|
|
||||||
if (needToUploadState != NeedToUpload::No)
|
if (needToUploadState != NeedToUpload::No)
|
||||||
{
|
{
|
||||||
if (it == _sessions.end())
|
uploadToStorage(session, /*force=*/needToUploadState == NeedToUpload::Force);
|
||||||
{
|
|
||||||
LOG_ERR("Session with sessionId ["
|
|
||||||
<< sessionId << "] not found to upload docKey [" << _docKey
|
|
||||||
<< "]. The document will not be uploaded to storage at this time.");
|
|
||||||
broadcastSaveResult(false, "Session not found");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
uploadToStorage(it->second, /*force=*/needToUploadState == NeedToUpload::Force);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isAsyncUploading())
|
if (!isAsyncUploading())
|
||||||
{
|
{
|
||||||
// If marked to destroy, or session is disconnected, remove.
|
// If marked to destroy, or session is disconnected, remove.
|
||||||
if (_docState.isMarkedToDestroy() || (it != _sessions.end() && it->second->isCloseFrame()))
|
if (_docState.isMarkedToDestroy() || session->isCloseFrame())
|
||||||
disconnectSessionInternal(it->second);
|
disconnectSessionInternal(session);
|
||||||
|
|
||||||
// If marked to destroy, then this was the last session.
|
// If marked to destroy, then this was the last session.
|
||||||
if (_docState.isMarkedToDestroy() || _sessions.empty())
|
if (_docState.isMarkedToDestroy() || _sessions.empty())
|
||||||
|
@ -2140,10 +2124,10 @@ void DocumentBroker::autoSaveAndStop(const std::string& reason)
|
||||||
if (!autoSave(possiblyModified))
|
if (!autoSave(possiblyModified))
|
||||||
{
|
{
|
||||||
// Nothing to save. Try to upload if necessary.
|
// Nothing to save. Try to upload if necessary.
|
||||||
const std::string sessionId = getWriteableSessionId();
|
const auto session = getWriteableSession();
|
||||||
if (!sessionId.empty())
|
if (session)
|
||||||
{
|
{
|
||||||
checkAndUploadToStorage(sessionId);
|
checkAndUploadToStorage(session);
|
||||||
if (isAsyncUploading())
|
if (isAsyncUploading())
|
||||||
{
|
{
|
||||||
LOG_DBG("Uploading document before stopping.");
|
LOG_DBG("Uploading document before stopping.");
|
||||||
|
|
|
@ -290,11 +290,12 @@ public:
|
||||||
|
|
||||||
/// Handle the save response from Core and upload to storage as necessary.
|
/// Handle the save response from Core and upload to storage as necessary.
|
||||||
/// Also notifies clients of the result.
|
/// Also notifies clients of the result.
|
||||||
void handleSaveResponse(const std::string& sessionId, bool success, const std::string& result);
|
void handleSaveResponse(const std::shared_ptr<ClientSession>& session, bool success,
|
||||||
|
const std::string& result);
|
||||||
|
|
||||||
/// Check if uploading is needed, and start uploading.
|
/// Check if uploading is needed, and start uploading.
|
||||||
/// The current state of uploading must be introspected separately.
|
/// The current state of uploading must be introspected separately.
|
||||||
void checkAndUploadToStorage(const std::string& sessionId);
|
void checkAndUploadToStorage(const std::shared_ptr<ClientSession>& session);
|
||||||
|
|
||||||
/// Upload the document to Storage if it needs persisting.
|
/// Upload the document to Storage if it needs persisting.
|
||||||
/// Results are logged and broadcast to users.
|
/// Results are logged and broadcast to users.
|
||||||
|
|
Loading…
Reference in a new issue