loolwsd/ChildProcessSession.cpp | 36 +++++++++++++++++------------------- loolwsd/ChildProcessSession.hpp | 6 ++---- 2 files changed, 19 insertions(+), 23 deletions(-)
New commits: commit 08b31ac3f56e6408c6e0ea6e0f618b9144b2a46f Author: Ashod Nakashian <[email protected]> Date: Sat Apr 23 14:05:21 2016 -0400 loolwsd: simplified and improved synching re-activating clients Change-Id: Idc07aecb33b350a0434c4310a0991a9b2ff1d738 Reviewed-on: https://gerrit.libreoffice.org/24323 Reviewed-by: Ashod Nakashian <[email protected]> Tested-by: Ashod Nakashian <[email protected]> diff --git a/loolwsd/ChildProcessSession.cpp b/loolwsd/ChildProcessSession.cpp index f7e74f7..92435ba 100644 --- a/loolwsd/ChildProcessSession.cpp +++ b/loolwsd/ChildProcessSession.cpp @@ -78,6 +78,18 @@ public: Log::trace() << "CallbackWorker::callback [" << _session.getViewId() << "] " << LOKitHelper::kitCallbackTypeToString(nType) << " [" << rPayload << "]." << Log::end; + + // Cache important notifications to replay them when our client + // goes inactive and loses them. + if (nType == LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR || + nType == LOK_CALLBACK_TEXT_SELECTION || + nType == LOK_CALLBACK_TEXT_SELECTION_START || + nType == LOK_CALLBACK_TEXT_SELECTION_END || + nType == LOK_CALLBACK_DOCUMENT_SIZE_CHANGED) + { + _session.setDocState(nType, rPayload); + } + if (_session.isCloseFrame()) { Log::trace("LOKit document begin the closing handshake"); @@ -94,16 +106,6 @@ public: if (nType != LOK_CALLBACK_UNO_COMMAND_RESULT || rPayload.find(".uno:Save") == std::string::npos) { Log::trace("Skipping callback on inactive session " + _session.getName()); - _session.setMissedUpdates(); - if (nType == LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR || - nType == LOK_CALLBACK_TEXT_SELECTION || - nType == LOK_CALLBACK_TEXT_SELECTION_START || - nType == LOK_CALLBACK_TEXT_SELECTION_END || - nType == LOK_CALLBACK_DOCUMENT_SIZE_CHANGED) - { - _session.setMissedNotif(nType, rPayload); - } - return; } } @@ -283,7 +285,6 @@ ChildProcessSession::ChildProcessSession(const std::string& id, _jailId(jailId), _viewId(0), _clientPart(0), - _missedUpdates(false), _onLoad(onLoad), _onUnload(onUnload), _callbackWorker(new CallbackWorker(_callbackQueue, *this)) @@ -322,9 +323,11 @@ void ChildProcessSession::disconnect() bool ChildProcessSession::_handleInput(const char *buffer, int length) { - if (_missedUpdates && _loKitDocument != nullptr) + const std::string firstLine = getFirstLine(buffer, length); + StringTokenizer tokens(firstLine, " ", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM); + + if (tokens.count() > 0 && tokens[0] == "useractive" && _loKitDocument != nullptr) { - _missedUpdates = false; Log::debug("Handling message after inactivity of " + std::to_string(getInactivityMS()) + "ms."); // Client is getting active again. @@ -338,7 +341,7 @@ bool ChildProcessSession::_handleInput(const char *buffer, int length) sendTextFrame("curpart: part=" + std::to_string(curPart)); //TODO: Is the order of these important? - for (const auto& pair : _missedNotif) + for (const auto& pair : _lastDocStates) { switch (pair.first) { @@ -360,13 +363,8 @@ bool ChildProcessSession::_handleInput(const char *buffer, int length) break; } } - - _missedNotif.clear(); } - const std::string firstLine = getFirstLine(buffer, length); - StringTokenizer tokens(firstLine, " ", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM); - if (LOOLProtocol::tokenIndicatesUserInteraction(tokens[0])) { // Keep track of timestamps of incoming client messages that indicate user activity. diff --git a/loolwsd/ChildProcessSession.hpp b/loolwsd/ChildProcessSession.hpp index 6e4a233..3fb82b1 100644 --- a/loolwsd/ChildProcessSession.hpp +++ b/loolwsd/ChildProcessSession.hpp @@ -60,8 +60,7 @@ public: std::unique_lock<std::recursive_mutex> getLock() { return std::unique_lock<std::recursive_mutex>(Mutex); } - void setMissedUpdates() { _missedUpdates = true; } - void setMissedNotif(const int type, const std::string& payload) { _missedNotif.emplace(type, payload); } + void setDocState(const int type, const std::string& payload) { _lastDocStates[type] = payload; } protected: virtual bool loadDocument(const char *buffer, int length, Poco::StringTokenizer& tokens) override; @@ -101,8 +100,7 @@ private: /// View ID, returned by createView() or 0 by default. int _viewId; int _clientPart; - bool _missedUpdates; - std::map<int, std::string> _missedNotif; + std::map<int, std::string> _lastDocStates; std::function<LibreOfficeKitDocument*(const std::string&, const std::string&, const std::string&, bool)> _onLoad; std::function<void(const std::string&)> _onUnload; _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
