diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp index 64ab1df99..0c2e8a9e8 100644 --- a/wsd/ClientSession.cpp +++ b/wsd/ClientSession.cpp @@ -1511,7 +1511,7 @@ bool ClientSession::handleKitToClientMessage(const std::shared_ptr& pay } // Save to Storage and log result. - docBroker->handleSaveResponse(getId(), success, result); + docBroker->handleSaveResponse(client_from_this(), success, result); if (!isCloseFrame()) forwardToClient(payload); diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp index fb8336ce6..c044adec6 100644 --- a/wsd/DocumentBroker.cpp +++ b/wsd/DocumentBroker.cpp @@ -1257,7 +1257,7 @@ bool DocumentBroker::isStorageOutdated() const return currentModifiedTime != lastModifiedTime; } -void DocumentBroker::handleSaveResponse(const std::string& sessionId, bool success, +void DocumentBroker::handleSaveResponse(const std::shared_ptr& session, bool success, const std::string& result) { assertCorrectThread(); @@ -1317,24 +1317,20 @@ void DocumentBroker::handleSaveResponse(const std::string& sessionId, bool succe // The the clients know of any save failures. if (!success && result != "unmodified") { - const auto it = _sessions.find(sessionId); - if (it != _sessions.end()) - { - LOG_INF("Failed to save docKey [" - << _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"); - } + LOG_INF("Failed to save docKey [" << _docKey + << "] as .uno:Save has failed in LOK. Notifying clients"); + session->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, // 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& session) { + const std::string sessionId = session->getId(); LOG_TRC("checkAndUploadToStorage with session " << sessionId); // See if we have anything to upload. @@ -1381,28 +1377,16 @@ void DocumentBroker::checkAndUploadToStorage(const std::string& sessionId) } #endif - const auto it = _sessions.find(sessionId); - if (needToUploadState != NeedToUpload::No) { - if (it == _sessions.end()) - { - 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); - } + uploadToStorage(session, /*force=*/needToUploadState == NeedToUpload::Force); } if (!isAsyncUploading()) { // If marked to destroy, or session is disconnected, remove. - if (_docState.isMarkedToDestroy() || (it != _sessions.end() && it->second->isCloseFrame())) - disconnectSessionInternal(it->second); + if (_docState.isMarkedToDestroy() || session->isCloseFrame()) + disconnectSessionInternal(session); // If marked to destroy, then this was the last session. if (_docState.isMarkedToDestroy() || _sessions.empty()) @@ -2140,10 +2124,10 @@ void DocumentBroker::autoSaveAndStop(const std::string& reason) if (!autoSave(possiblyModified)) { // Nothing to save. Try to upload if necessary. - const std::string sessionId = getWriteableSessionId(); - if (!sessionId.empty()) + const auto session = getWriteableSession(); + if (session) { - checkAndUploadToStorage(sessionId); + checkAndUploadToStorage(session); if (isAsyncUploading()) { LOG_DBG("Uploading document before stopping."); diff --git a/wsd/DocumentBroker.hpp b/wsd/DocumentBroker.hpp index 642cfd477..b85d486c2 100644 --- a/wsd/DocumentBroker.hpp +++ b/wsd/DocumentBroker.hpp @@ -290,11 +290,12 @@ public: /// Handle the save response from Core and upload to storage as necessary. /// Also notifies clients of the result. - void handleSaveResponse(const std::string& sessionId, bool success, const std::string& result); + void handleSaveResponse(const std::shared_ptr& session, bool success, + const std::string& result); /// Check if uploading is needed, and start uploading. /// The current state of uploading must be introspected separately. - void checkAndUploadToStorage(const std::string& sessionId); + void checkAndUploadToStorage(const std::shared_ptr& session); /// Upload the document to Storage if it needs persisting. /// Results are logged and broadcast to users.