[Libreoffice-commits] online.git: wsd/DocumentBroker.cpp wsd/DocumentBroker.hpp

2020-06-22 Thread Ashod Nakashian (via logerrit)
 wsd/DocumentBroker.cpp |2 ++
 wsd/DocumentBroker.hpp |2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)

New commits:
commit 17044ade27ec94f135b95350a8a96ae7696049a2
Author: Ashod Nakashian 
AuthorDate: Wed Jun 3 12:30:40 2020 -0400
Commit: Ashod Nakashian 
CommitDate: Tue Jun 23 06:42:53 2020 +0200

wsd: fix: call to virtual function during destruction

Change-Id: I914025fe642f6c78d4a5731fdb8e8920a62838b1
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/96379
Tested-by: Jenkins
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Ashod Nakashian 

diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index f62241808..c242da586 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -2325,6 +2325,8 @@ void ConvertToBroker::dispose()
 
 ConvertToBroker::~ConvertToBroker()
 {
+// Calling a virtual function from a dtor
+// is only valid if there are no inheritors.
 dispose();
 }
 
diff --git a/wsd/DocumentBroker.hpp b/wsd/DocumentBroker.hpp
index 17300d0cb..42d506629 100644
--- a/wsd/DocumentBroker.hpp
+++ b/wsd/DocumentBroker.hpp
@@ -442,7 +442,7 @@ private:
 };
 
 #if !MOBILEAPP
-class ConvertToBroker : public DocumentBroker
+class ConvertToBroker final : public DocumentBroker
 {
 const std::string _format;
 const std::string _sOptions;
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: wsd/DocumentBroker.cpp wsd/DocumentBroker.hpp

2020-04-16 Thread Ashod Nakashian (via logerrit)
 wsd/DocumentBroker.cpp |   18 --
 wsd/DocumentBroker.hpp |2 +-
 2 files changed, 9 insertions(+), 11 deletions(-)

New commits:
commit 2f703dc5ae14875910053b22bf8d806a18257a65
Author: Ashod Nakashian 
AuthorDate: Thu Apr 9 10:37:33 2020 -0400
Commit: Ashod Nakashian 
CommitDate: Fri Apr 17 02:36:39 2020 +0200

wsd: _isModified -> isModified()

Change-Id: I70e35dfede8ae37603bc26cb800223a369ae5e8f
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/92099
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Ashod Nakashian 

diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 8c342c4c3..f79cbbbd4 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -432,7 +432,7 @@ void DocumentBroker::pollThread()
 _poll->continuePolling() << ", ShutdownRequestFlag: " << 
SigUtil::getShutdownRequestFlag() <<
 ", TerminationFlag: " << SigUtil::getTerminationFlag() << ", 
closeReason: " << _closeReason << ". Flushing socket.");
 
-if (_isModified)
+if (isModified())
 {
 std::stringstream state;
 dumpState(state);
@@ -739,9 +739,8 @@ bool DocumentBroker::load(const 
std::shared_ptr& session, const s
 ", Actual: " << fileInfo.getModifiedTime());
 
 _documentChangedInStorage = true;
-std::string message = "close: documentconflict";
-if (_isModified)
-message = "error: cmd=storage kind=documentconflict";
+const std::string message = isModified() ? "error: cmd=storage 
kind=documentconflict"
+ : "close: 
documentconflict";
 
 session->sendTextFrame(message);
 broadcastMessage(message);
@@ -1090,9 +1089,8 @@ bool DocumentBroker::saveToStorageInternal(const 
std::string& sessionId, bool su
 {
 LOG_ERR("PutFile says that Document changed in storage");
 _documentChangedInStorage = true;
-std::string message = "close: documentconflict";
-if (_isModified)
-message = "error: cmd=storage kind=documentconflict";
+const std::string message
+= isModified() ? "error: cmd=storage kind=documentconflict" : 
"close: documentconflict";
 
 broadcastMessage(message);
 }
@@ -1160,7 +1158,7 @@ bool DocumentBroker::autoSave(const bool force, const 
bool dontSaveIfUnmodified)
 
 LOG_TRC("autoSave(): forceful? " << force);
 if (_sessions.empty() || _storage == nullptr || !_isLoaded ||
-!_childProcess->isAlive() || (!_isModified && !force))
+!_childProcess->isAlive() || (!isModified() && !force))
 {
 // Nothing to do.
 LOG_TRC("Nothing to autosave [" << _docKey << "].");
@@ -1186,7 +1184,7 @@ bool DocumentBroker::autoSave(const bool force, const 
bool dontSaveIfUnmodified)
dontSaveIfUnmodified, /*isAutosave=*/false,
/*isExitSave=*/true);
 }
-else if (_isModified)
+else if (isModified())
 {
 const std::chrono::steady_clock::time_point now = 
std::chrono::steady_clock::now();
 const std::chrono::milliseconds::rep inactivityTimeMs = 
std::chrono::duration_cast(now - 
_lastActivityTime).count();
@@ -2377,7 +2375,7 @@ void DocumentBroker::dumpState(std::ostream& os)
 now - _threadStart).count() << "s";
 os << "\n  sent: " << sent;
 os << "\n  recv: " << recv;
-os << "\n  modified?: " << _isModified;
+os << "\n  modified?: " << isModified();
 os << "\n  jail id: " << _jailId;
 os << "\n  filename: " << LOOLWSD::anonymizeUrl(_filename);
 os << "\n  public uri: " << _uriPublic.toString();
diff --git a/wsd/DocumentBroker.hpp b/wsd/DocumentBroker.hpp
index d270f53b0..42fc82bbb 100644
--- a/wsd/DocumentBroker.hpp
+++ b/wsd/DocumentBroker.hpp
@@ -313,7 +313,7 @@ private:
 /// True if we know the doc is modified or
 /// if there has been activity from a client after we last *requested* 
saving,
 /// since there are race conditions vis-a-vis user activity while saving.
-bool isPossiblyModified() const { return _isModified || 
(_lastSaveRequestTime < _lastActivityTime); }
+bool isPossiblyModified() const { return isModified() || 
(_lastSaveRequestTime < _lastActivityTime); }
 
 /// True iff there is at least one non-readonly session other than the 
given.
 /// Since only editable sessions can save, we need to use the last to
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: wsd/DocumentBroker.cpp wsd/DocumentBroker.hpp wsd/LOOLWSD.cpp

2020-03-05 Thread Michael Meeks (via logerrit)
 wsd/DocumentBroker.cpp |   32 
 wsd/DocumentBroker.hpp |7 +++
 wsd/LOOLWSD.cpp|   38 ++
 3 files changed, 41 insertions(+), 36 deletions(-)

New commits:
commit da944760a62a82c21a32017b9c04526ea00d3cbd
Author: Michael Meeks 
AuthorDate: Wed Mar 4 21:56:48 2020 +
Commit: Michael Meeks 
CommitDate: Thu Mar 5 17:10:36 2020 +0100

re-factor: move createNewSession into DocumentBroker.

Change-Id: I78f07a61fd79dfdd1c0d0ef21cf19218beec46ee
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/90025
Tested-by: Jenkins CollaboraOffice 
Reviewed-by: Michael Meeks 

diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 74b827678..18bcdce63 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -1497,6 +1497,38 @@ void DocumentBroker::finalRemoveSession(const 
std::string& id)
 }
 }
 
+std::shared_ptr DocumentBroker::createNewClientSession(const 
WebSocketHandler* ws,
+  const 
std::string& id,
+  const 
Poco::URI& uriPublic,
+  const 
bool isReadOnly,
+  const 
std::string& hostNoTrust)
+{
+try
+{
+// Now we have a DocumentBroker and we're ready to process client 
commands.
+if (ws)
+{
+const std::string statusReady = "statusindicator: ready";
+LOG_TRC("Sending to Client [" << statusReady << "].");
+ws->sendMessage(statusReady);
+}
+
+// In case of WOPI, if this session is not set as readonly, it might 
be set so
+// later after making a call to WOPI host which tells us the 
permission on files
+// (UserCanWrite param).
+auto session = std::make_shared(id, shared_from_this(), 
uriPublic, isReadOnly, hostNoTrust);
+session->construct();
+
+return session;
+}
+catch (const std::exception& exc)
+{
+LOG_WRN("Exception while preparing session [" << id << "]: " << 
exc.what());
+}
+
+return nullptr;
+}
+
 void DocumentBroker::addCallback(const SocketPoll::CallbackFn& fn)
 {
 _poll->addCallback(fn);
diff --git a/wsd/DocumentBroker.hpp b/wsd/DocumentBroker.hpp
index 5e3bea9aa..f56bd1e3f 100644
--- a/wsd/DocumentBroker.hpp
+++ b/wsd/DocumentBroker.hpp
@@ -243,6 +243,13 @@ public:
 /// Hard removes a session by ID, only for ClientSession.
 void finalRemoveSession(const std::string& id);
 
+/// Create new client session
+std::shared_ptr createNewClientSession(const 
WebSocketHandler* ws,
+  const std::string& 
id,
+  const Poco::URI& 
uriPublic,
+  const bool 
isReadOnly,
+  const std::string& 
hostNoTrust);
+
 /// Thread safe termination of this broker if it has a lingering thread
 void joinThread();
 
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index 61b9d8f09..eb35d601c 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -1780,40 +1780,6 @@ static std::shared_ptr 
findOrCreateDocBroker(WebSocketHandler& w
 return docBroker;
 }
 
-static std::shared_ptr createNewClientSession(const 
WebSocketHandler* ws,
- const 
std::string& id,
- const Poco::URI& 
uriPublic,
- const 
std::shared_ptr& docBroker,
- const bool 
isReadOnly,
- const 
std::string& hostNoTrust)
-{
-LOG_CHECK_RET(docBroker && "Null docBroker instance", nullptr);
-try
-{
-// Now we have a DocumentBroker and we're ready to process client 
commands.
-if (ws)
-{
-const std::string statusReady = "statusindicator: ready";
-LOG_TRC("Sending to Client [" << statusReady << "].");
-ws->sendMessage(statusReady);
-}
-
-// In case of WOPI, if this session is not set as readonly, it might 
be set so
-// later after making a call to WOPI host which tells us the 
permission on files
-// (UserCanWrite param).
-auto session = std::make_shared(id, docBroker, 
uriPublic, isReadOnly, hostNoTrust);
-session->construct();
-
-return session;
-}
-catch (const std::exception& exc)
-{
-LOG_WRN("Exception while preparing session [" << id << "]: " << 
exc.what());
-}
-
-return nullptr;
-}
-
 /// Handles the socket that the 

[Libreoffice-commits] online.git: wsd/DocumentBroker.cpp wsd/DocumentBroker.hpp

2019-12-12 Thread Jan Holesovsky (via logerrit)
 wsd/DocumentBroker.cpp |2 ++
 wsd/DocumentBroker.hpp |2 ++
 2 files changed, 4 insertions(+)

New commits:
commit 863111c952300efd3a3b13b9dcc4d41c8dc85405
Author: Jan Holesovsky 
AuthorDate: Thu Dec 12 09:56:43 2019 +0100
Commit: Jan Holesovsky 
CommitDate: Thu Dec 12 09:57:44 2019 +0100

mobile: Fix build.

Change-Id: Ie0f08a984b9333ca65d0fd52c71e358b7fd5f771
Reviewed-on: https://gerrit.libreoffice.org/85018
Reviewed-by: Jan Holesovsky 
Tested-by: Jan Holesovsky 

diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 700a56fbf..77204dd69 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -2207,6 +2207,7 @@ ConvertToBroker::ConvertToBroker(const std::string& uri,
 _limitLifeSeconds = limit_convert_secs;
 }
 
+#if !MOBILEAPP
 bool ConvertToBroker::startConversion(SocketDisposition , const 
std::string )
 {
 std::shared_ptr docBroker = 
std::static_pointer_cast(shared_from_this());
@@ -2252,6 +2253,7 @@ bool ConvertToBroker::startConversion(SocketDisposition 
, const std:
 });
 return true;
 }
+#endif
 
 void ConvertToBroker::dispose()
 {
diff --git a/wsd/DocumentBroker.hpp b/wsd/DocumentBroker.hpp
index 5632c56b6..07f967579 100644
--- a/wsd/DocumentBroker.hpp
+++ b/wsd/DocumentBroker.hpp
@@ -532,8 +532,10 @@ public:
 const std::string& sOptions);
 virtual ~ConvertToBroker();
 
+#if !MOBILEAPP
 /// Move socket to this broker for response & do conversion
 bool startConversion(SocketDisposition , const std::string 
);
+#endif
 
 /// Called when removed from the DocBrokers list
 void dispose() override;
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: wsd/DocumentBroker.cpp wsd/DocumentBroker.hpp wsd/LOOLWSD.cpp

2019-12-11 Thread Michael Meeks (via logerrit)
 wsd/DocumentBroker.cpp |   74 +++--
 wsd/DocumentBroker.hpp |   17 +--
 wsd/LOOLWSD.cpp|   63 +
 3 files changed, 89 insertions(+), 65 deletions(-)

New commits:
commit 948b424abbb3ee493d148896492d18186e3507f2
Author: Michael Meeks 
AuthorDate: Thu Dec 12 05:09:35 2019 +
Commit: Michael Meeks 
CommitDate: Thu Dec 12 07:42:42 2019 +0100

convert-to: wait for load to complete before attempting the save.

Change-Id: Iee3a8a6720bbc29fc4e113bf705f405b840e1e45
Reviewed-on: https://gerrit.libreoffice.org/85009
Reviewed-by: Michael Meeks 
Tested-by: Michael Meeks 

diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index af756c676..700a56fbf 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -2195,14 +2195,64 @@ size_t ConvertToBroker::getInstanceCount()
 
 ConvertToBroker::ConvertToBroker(const std::string& uri,
  const Poco::URI& uriPublic,
- const std::string& docKey)
-: DocumentBroker(uri, uriPublic, docKey)
+ const std::string& docKey,
+ const std::string& format,
+ const std::string& sOptions) :
+DocumentBroker(uri, uriPublic, docKey),
+_format(format),
+_sOptions(sOptions)
 {
 static const int limit_convert_secs = 
LOOLWSD::getConfigValue("per_document.limit_convert_secs", 100);
 NumConverters++;
 _limitLifeSeconds = limit_convert_secs;
 }
 
+bool ConvertToBroker::startConversion(SocketDisposition , const 
std::string )
+{
+std::shared_ptr docBroker = 
std::static_pointer_cast(shared_from_this());
+
+// Create a session to load the document.
+const bool isReadOnly = true;
+_clientSession = std::make_shared(id, docBroker, 
getPublicUri(), isReadOnly, "nocliphost");
+_clientSession->construct();
+
+if (!_clientSession)
+return false;
+
+disposition.setMove([docBroker] (const std::shared_ptr )
+{
+// Perform all of this after removing the socket
+
+// Make sure the thread is running before adding callback.
+docBroker->startThread();
+
+// We no longer own this socket.
+moveSocket->setThreadOwner(std::thread::id(0));
+
+docBroker->addCallback([docBroker, moveSocket]()
+ {
+ auto streamSocket = 
std::static_pointer_cast(moveSocket);
+ docBroker->_clientSession->setSaveAsSocket(streamSocket);
+
+ // Move the socket into DocBroker.
+ docBroker->addSocketToPoll(moveSocket);
+
+ // First add and load the session.
+ docBroker->addSession(docBroker->_clientSession);
+
+ // Load the document manually and request saving in the 
target format.
+ std::string encodedFrom;
+ Poco::URI::encode(docBroker->getPublicUri().getPath(), 
"", encodedFrom);
+ const std::string load = "load url=" + encodedFrom;
+ std::vector loadRequest(load.begin(), load.end());
+ docBroker->_clientSession->handleMessage(true, 
WSOpCode::Text, loadRequest);
+
+ // Save is done in the setLoaded
+ });
+});
+return true;
+}
+
 void ConvertToBroker::dispose()
 {
 if (!_uriOrig.empty())
@@ -2233,6 +2283,26 @@ void ConvertToBroker::removeFile(const std::string 
)
 }
 }
 
+void ConvertToBroker::setLoaded()
+{
+DocumentBroker::setLoaded();
+
+// FIXME: Check for security violations.
+Poco::Path toPath(getPublicUri().getPath());
+toPath.setExtension(_format);
+const std::string toJailURL = "file://" + 
std::string(JAILED_DOCUMENT_ROOT) + toPath.getFileName();
+std::string encodedTo;
+Poco::URI::encode(toJailURL, "", encodedTo);
+
+// Convert it to the requested format.
+const std::string saveAsCmd = "saveas url=" + encodedTo + " format=" + 
_format + " options=" + _sOptions;
+
+// Send the save request ...
+std::vector saveasRequest(saveAsCmd.begin(), saveAsCmd.end());
+
+_clientSession->handleMessage(true, WSOpCode::Text, saveasRequest);
+}
+
 std::vector> 
DocumentBroker::getSessionsTestOnlyUnsafe()
 {
 std::vector> result;
diff --git a/wsd/DocumentBroker.hpp b/wsd/DocumentBroker.hpp
index 3b8f6e844..5632c56b6 100644
--- a/wsd/DocumentBroker.hpp
+++ b/wsd/DocumentBroker.hpp
@@ -245,7 +245,8 @@ public:
 /// Thread safe termination of this broker if it has a lingering thread
 void joinThread();
 
-void setLoaded();
+/// Notify that the load has completed
+virtual void setLoaded();
 
 bool isDocumentChangedInStorage() { return _documentChangedInStorage; }
 
@@ -518,16 +519,28 @@ private:
 
 class ConvertToBroker : 

[Libreoffice-commits] online.git: wsd/DocumentBroker.cpp wsd/DocumentBroker.hpp wsd/Storage.cpp wsd/Storage.hpp

2019-11-21 Thread Michael Meeks (via logerrit)
 wsd/DocumentBroker.cpp |   33 
 wsd/DocumentBroker.hpp |2 +
 wsd/Storage.cpp|   96 -
 wsd/Storage.hpp|   48 +++-
 4 files changed, 154 insertions(+), 25 deletions(-)

New commits:
commit cabd30a1b83c5abea913dcbe8ce869d6b12ea404
Author: Michael Meeks 
AuthorDate: Tue Nov 19 22:51:45 2019 +
Commit: Michael Meeks 
CommitDate: Thu Nov 21 14:24:58 2019 +

Initial wopi-like locking implementation.

Change-Id: I3e16cfc40dbd29a24016b09e62afc9ec488300c7

diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 6b393d277..ef1ad7ed6 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -189,6 +189,7 @@ DocumentBroker::DocumentBroker(const std::string& uri,
 _poll(new DocumentBrokerPoll("docbroker_" + _docId, *this)),
 _stop(false),
 _closeReason("stopped"),
+_lockCtx(new LockContext()),
 _tileVersion(0),
 _debugRenderedTileCount(0)
 {
@@ -563,7 +564,8 @@ bool DocumentBroker::load(const 
std::shared_ptr& session, const s
 WopiStorage* wopiStorage = dynamic_cast(_storage.get());
 if (wopiStorage != nullptr)
 {
-std::unique_ptr wopifileinfo = 
wopiStorage->getWOPIFileInfo(session->getAuthorization());
+std::unique_ptr wopifileinfo =
+wopiStorage->getWOPIFileInfo(session->getAuthorization(), 
*_lockCtx);
 userId = wopifileinfo->getUserId();
 username = wopifileinfo->getUsername();
 userExtraInfo = wopifileinfo->getUserExtraInfo();
@@ -722,7 +724,11 @@ bool DocumentBroker::load(const 
std::shared_ptr& session, const s
 // Let's load the document now, if not loaded.
 if (!_storage->isLoaded())
 {
-std::string localPath = 
_storage->loadStorageFileToLocal(session->getAuthorization(), templateSource);
+std::string localPath = _storage->loadStorageFileToLocal(
+session->getAuthorization(), *_lockCtx, templateSource);
+
+if (!_storage->updateLockState(session->getAuthorization(), *_lockCtx, 
true))
+LOG_ERR("Failed to lock!");
 
 #if !MOBILEAPP
 // Check if we have a prefilter "plugin" for this document format
@@ -955,7 +961,8 @@ bool DocumentBroker::saveToStorageInternal(const 
std::string& sessionId, bool su
 LOG_DBG("Persisting [" << _docKey << "] after saving to URI [" << 
uriAnonym << "].");
 
 assert(_storage && _tileCache);
-StorageBase::SaveResult storageSaveResult = 
_storage->saveLocalFileToStorage(auth, saveAsPath, saveAsFilename, isRename);
+StorageBase::SaveResult storageSaveResult = 
_storage->saveLocalFileToStorage(
+auth, *_lockCtx, saveAsPath, saveAsFilename, isRename);
 if (storageSaveResult.getResult() == StorageBase::SaveResult::OK)
 {
 if (!isSaveAs && !isRename)
@@ -1299,18 +1306,19 @@ size_t DocumentBroker::removeSession(const std::string& 
id)
 LOG_ERR("Invalid or unknown session [" << id << "] to remove.");
 return _sessions.size();
 }
+std::shared_ptr session = it->second;
 
 // Last view going away, can destroy.
 _markToDestroy = (_sessions.size() <= 1);
 
-const bool lastEditableSession = !it->second->isReadOnly() && 
!haveAnotherEditableSession(id);
+const bool lastEditableSession = !session->isReadOnly() && 
!haveAnotherEditableSession(id);
 static const bool dontSaveIfUnmodified = 
!LOOLWSD::getConfigValue("per_document.always_save_on_exit", false);
 
 LOG_INF("Removing session ["
 << id << "] on docKey [" << _docKey << "]. Have " << 
_sessions.size()
-<< " sessions. IsReadOnly: " << it->second->isReadOnly()
-<< ", IsViewLoaded: " << it->second->isViewLoaded() << ", 
IsWaitDisconnected: "
-<< it->second->inWaitDisconnected() << ", MarkToDestroy: " << 
_markToDestroy
+<< " sessions. IsReadOnly: " << session->isReadOnly()
+<< ", IsViewLoaded: " << session->isViewLoaded() << ", 
IsWaitDisconnected: "
+<< session->inWaitDisconnected() << ", MarkToDestroy: " << 
_markToDestroy
 << ", LastEditableSession: " << lastEditableSession
 << ", dontSaveIfUnmodified: " << dontSaveIfUnmodified);
 
@@ -1341,7 +1349,16 @@ void DocumentBroker::disconnectSessionInternal(const 
std::string& id)
 LOOLWSD::dumpEndSessionTrace(getJailId(), id, _uriOrig);
 #endif
 
-LOG_TRC("Disconnect session internal " << id);
+LOG_TRC("Disconnect session internal " << id <<
+" destroy? " << _markToDestroy <<
+" locked? " << _lockCtx->_isLocked);
+
+if (_markToDestroy && // last session to remove; FIXME: Editable?
+_lockCtx->_isLocked && _storage)
+{
+if (!_storage->updateLockState(it->second->getAuthorization(), 
*_lockCtx, 

[Libreoffice-commits] online.git: wsd/DocumentBroker.cpp wsd/DocumentBroker.hpp wsd/LOOLWSD.cpp

2019-11-05 Thread Ashod Nakashian (via logerrit)
 wsd/DocumentBroker.cpp |   55 +++--
 wsd/DocumentBroker.hpp |6 -
 wsd/LOOLWSD.cpp|1 
 3 files changed, 41 insertions(+), 21 deletions(-)

New commits:
commit 35fdc48e28f915e446bf6d78109368414335fcb9
Author: Ashod Nakashian 
AuthorDate: Tue Oct 22 10:28:57 2019 -0400
Commit: Ashod Nakashian 
CommitDate: Wed Nov 6 03:41:44 2019 +0100

wsd: upload to storage when per_document.always_save_on_exit is set

Saving the document on exit is not enough, we also need
to send it to the storage. We now force doing that,
even when there is no modifiction to the document
(i.e. a new version wasn't really saved).

Reviewed-on: https://gerrit.libreoffice.org/81336
Reviewed-by: Andras Timar 
Tested-by: Andras Timar 
(cherry picked from commit f2913f20b03e916ce8a70f927ca3f5655a3768a8)

Change-Id: Ic4e1b1424f32d3141e98c936a51e47c9e4b9f753
Reviewed-on: https://gerrit.libreoffice.org/81576
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 5a0926a2d..fd77b83ae 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -677,7 +677,6 @@ bool DocumentBroker::load(const 
std::shared_ptr& session, const s
 session->setUserName(username);
 session->setUserExtraInfo(userExtraInfo);
 session->setWatermarkText(watermarkText);
-
 if(!watermarkText.empty())
 session->setHash(watermarkText);
 else
@@ -834,13 +833,21 @@ bool DocumentBroker::saveToStorage(const std::string& 
sessionId,
 {
 assertCorrectThread();
 
-if (force)
+// Force saving on exit, if enabled.
+if (!force && isMarkedToDestroy())
 {
-LOG_TRC("Document will be saved forcefully to storage.");
-_storage->forceSave();
+static const bool always_save = 
LOOLWSD::getConfigValue("per_document.always_save_on_exit", false);
+if (always_save)
+{
+LOG_TRC("Enabling forced saving to storage per always_save_on_exit 
config.");
+_storage->forceSave();
+force = true;
+}
 }
 
-const bool res = saveToStorageInternal(sessionId, success, result);
+constexpr bool isRename = false;
+const bool res = saveToStorageInternal(sessionId, success, result, 
/*saveAsPath*/ std::string(),
+   /*saveAsFilename*/ std::string(), 
isRename, force);
 
 // If marked to destroy, or session is disconnected, remove.
 const auto it = _sessions.find(sessionId);
@@ -864,22 +871,21 @@ bool DocumentBroker::saveAsToStorage(const std::string& 
sessionId, const std::st
 return saveToStorageInternal(sessionId, true, "", saveAsPath, 
saveAsFilename, isRename);
 }
 
-bool DocumentBroker::saveToStorageInternal(const std::string& sessionId,
-   bool success, const std::string& 
result,
-   const std::string& saveAsPath, 
const std::string& saveAsFilename, const bool isRename)
+bool DocumentBroker::saveToStorageInternal(const std::string& sessionId, bool 
success,
+   const std::string& result, const 
std::string& saveAsPath,
+   const std::string& saveAsFilename, 
const bool isRename,
+   const bool force)
 {
 assertCorrectThread();
 
 // Record that we got a response to avoid timing out on saving.
 _lastSaveResponseTime = std::chrono::steady_clock::now();
 
-const bool isSaveAs = !saveAsPath.empty();
-
 // If save requested, but core didn't save because document was unmodified
 // notify the waiting thread, if any.
-LOG_TRC("Saving to storage docKey [" << _docKey << "] for session [" << 
sessionId <<
-"]. Success: " << success << ", result: " << result);
-if (!success && result == "unmodified" && !isRename)
+LOG_TRC("Uploading to storage docKey [" << _docKey << "] for session [" << 
sessionId <<
+"]. Success: " << success << ", result: " << result << ", force: " 
<< force);
+if (!success && result == "unmodified" && !isRename && !force)
 {
 LOG_DBG("Save skipped as document [" << _docKey << "] was not 
modified.");
 _lastSaveTime = std::chrono::steady_clock::now();
@@ -890,18 +896,26 @@ bool DocumentBroker::saveToStorageInternal(const 
std::string& sessionId,
 const auto it = _sessions.find(sessionId);
 if (it == _sessions.end())
 {
-LOG_ERR("Session with sessionId [" << sessionId << "] not found while 
saving docKey [" << _docKey << "].");
+LOG_ERR("Session with sessionId ["
+<< sessionId << "] not found while storing document docKey [" 
<< _docKey
+<< "]. The document will not be uploaded to storage at this 
time.");
 return false;
 }
 
 // Check that we 

[Libreoffice-commits] online.git: wsd/DocumentBroker.cpp wsd/DocumentBroker.hpp wsd/LOOLWSD.cpp

2019-10-04 Thread Michael Meeks (via logerrit)
 wsd/DocumentBroker.cpp |   13 +++--
 wsd/DocumentBroker.hpp |8 +++-
 wsd/LOOLWSD.cpp|6 --
 3 files changed, 22 insertions(+), 5 deletions(-)

New commits:
commit 5e7cac28fa74131461f6d9e25334e9cc7568f444
Author: Michael Meeks 
AuthorDate: Fri Oct 4 10:30:49 2019 +0100
Commit: Michael Meeks 
CommitDate: Fri Oct 4 11:01:45 2019 +0100

belt & braces fix erroneous popup of limit dialog

The shared_ptr allows the DocumentBroker's and ConvertToBroker to linger
after they are removed from the list, making 
ConvertToBroker::getInstanceCount
potentially larger than the number of documents transiently. Fix this
with a dispose method called on list removal.
Also make the arithmetic signed, to avoid unfortunate wrapping.
Also when the limit is large, don't show a message whatever happens.

Change-Id: Id2571429de48ae75e851c3fdc49e24a02aaaf6e9

diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index ab71fe5ba..c332f7c52 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -2072,10 +2072,19 @@ ConvertToBroker::ConvertToBroker(const std::string& uri,
 NumConverters++;
 }
 
+void ConvertToBroker::dispose()
+{
+if (!_uriOrig.empty())
+{
+NumConverters--;
+removeFile(_uriOrig);
+_uriOrig.clear();
+}
+}
+
 ConvertToBroker::~ConvertToBroker()
 {
-NumConverters--;
-removeFile(_uriOrig);
+dispose();
 }
 
 void ConvertToBroker::removeFile(const std::string )
diff --git a/wsd/DocumentBroker.hpp b/wsd/DocumentBroker.hpp
index 576906d9e..7c66832a5 100644
--- a/wsd/DocumentBroker.hpp
+++ b/wsd/DocumentBroker.hpp
@@ -225,6 +225,9 @@ public:
 
 virtual ~DocumentBroker();
 
+/// Called when removed from the DocBrokers list
+virtual void dispose() {}
+
 /// Start processing events
 void startThread();
 
@@ -420,7 +423,7 @@ private:
 void getIOStats(uint64_t , uint64_t );
 
 protected:
-const std::string _uriOrig;
+std::string _uriOrig;
 private:
 const Poco::URI _uriPublic;
 /// URL-based key. May be repeated during the lifetime of WSD.
@@ -498,6 +501,9 @@ public:
 const std::string& docKey);
 virtual ~ConvertToBroker();
 
+/// Called when removed from the DocBrokers list
+void dispose() override;
+
 /// How many live conversions are running.
 static size_t getInstanceCount();
 
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index f404798d0..b460d75d8 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -258,8 +258,9 @@ inline void shutdownLimitReached(WebSocketHandler& ws)
 inline void checkSessionLimitsAndWarnClients()
 {
 #if !MOBILEAPP
-size_t docBrokerCount = DocBrokers.size() - 
ConvertToBroker::getInstanceCount();
-if (docBrokerCount > LOOLWSD::MaxDocuments || LOOLWSD::NumConnections >= 
LOOLWSD::MaxConnections)
+ssize_t docBrokerCount = DocBrokers.size() - 
ConvertToBroker::getInstanceCount();
+if (LOOLWSD::MaxDocuments < 1 &&
+(docBrokerCount > LOOLWSD::MaxDocuments || LOOLWSD::NumConnections >= 
LOOLWSD::MaxConnections))
 {
 const std::string info = Poco::format(PAYLOAD_INFO_LIMIT_REACHED, 
LOOLWSD::MaxDocuments, LOOLWSD::MaxConnections);
 LOG_INF("Sending client 'limitreached' message: " << info);
@@ -333,6 +334,7 @@ void cleanupDocBrokers()
 if (!docBroker->isAlive())
 {
 LOG_INF("Removing DocumentBroker for docKey [" << it->first << 
"].");
+docBroker->dispose();
 it = DocBrokers.erase(it);
 continue;
 } else {
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

[Libreoffice-commits] online.git: wsd/DocumentBroker.cpp wsd/DocumentBroker.hpp

2019-05-24 Thread Libreoffice Gerrit user
 wsd/DocumentBroker.cpp |3 +++
 wsd/DocumentBroker.hpp |1 +
 2 files changed, 4 insertions(+)

New commits:
commit 1a41e368add6d95ecd866cba1f2262fdfb329fe5
Author: Miklos Vajna 
AuthorDate: Fri May 24 09:04:07 2019 +0200
Commit: Miklos Vajna 
CommitDate: Fri May 24 09:04:16 2019 +0200

wsd: avoid UB in DocumentBroker::cancelTileRequests()

With this, it's possible to open a document and type keys with
sanitizers enabled.


/home/vmiklos/lode/opt_private/gcc-7.3.0/lib/gcc/x86_64-pc-linux-gnu/7.3.0/../../../../include/c++/7.3.0/bits/unique_ptr.h:323:9:
 runtime error: reference binding to null pointer of type 'TileCache'
#0 0x911996 in std::unique_ptr >::operator*() const 
/home/vmiklos/lode/opt_private/gcc-7.3.0/lib/gcc/x86_64-pc-linux-gnu/7.3.0/../../../../include/c++/7.3.0/bits/unique_ptr.h:323:2
#1 0x8ecb2a in DocumentBroker::tileCache() 
/home/vmiklos/lode/dev/online/./wsd/DocumentBroker.hpp:265:37
#2 0x8c6a63 in 
DocumentBroker::cancelTileRequests(std::shared_ptr const&) 
/home/vmiklos/lode/dev/online/wsd/DocumentBroker.cpp:1586:37
#3 0xb32b0e in ClientSession::_handleInput(char const*, int) 
/home/vmiklos/lode/dev/online/wsd/ClientSession.cpp:194:20
#4 0xd45d3c in Session::handleMessage(bool, WSOpCode, std::vector >&) /home/vmiklos/lode/dev/online/common/Session.cpp:219:13
#5 0x768080 in 
WebSocketHandler::handleTCPStream(std::shared_ptr const&) 
/home/vmiklos/lode/dev/online/./net/WebSocketHandler.hpp:368:13
#6 0x6f800d in 
WebSocketHandler::handleIncomingMessage(SocketDisposition&) 
/home/vmiklos/lode/dev/online/./net/WebSocketHandler.hpp:419:20
#7 0xb2c644 in ClientSession::handleIncomingMessage(SocketDisposition&) 
/home/vmiklos/lode/dev/online/wsd/ClientSession.cpp:74:14
#8 0xa6f641 in StreamSocket::handlePoll(SocketDisposition&, 
std::chrono::time_point > >, int) 
/home/vmiklos/lode/dev/online/./net/Socket.hpp:1037:29
#9 0x6ec63d in SocketPoll::poll(int) 
/home/vmiklos/lode/dev/online/./net/Socket.hpp:570:34
#10 0x83af99 in DocumentBroker::pollThread() 
/home/vmiklos/lode/dev/online/wsd/DocumentBroker.cpp:387:16
#11 0x8fc778 in DocumentBroker::DocumentBrokerPoll::pollingThread() 
/home/vmiklos/lode/dev/online/wsd/DocumentBroker.cpp:165:20
#12 0xdff935 in SocketPoll::pollingThreadEntry() 
/home/vmiklos/lode/dev/online/net/Socket.cpp:184:9
#13 0xe487bd in void std::__invoke_impl(std::__invoke_memfun_deref, void (SocketPoll::*&&)(), 
SocketPoll*&&) 
/home/vmiklos/lode/opt_private/gcc-7.3.0/lib/gcc/x86_64-pc-linux-gnu/7.3.0/../../../../include/c++/7.3.0/bits/invoke.h:73:14
#14 0xe482ca in std::__invoke_result::type std::__invoke(void 
(SocketPoll::*&&)(), SocketPoll*&&) 
/home/vmiklos/lode/opt_private/gcc-7.3.0/lib/gcc/x86_64-pc-linux-gnu/7.3.0/../../../../include/c++/7.3.0/bits/invoke.h:95:14
#15 0xe4817d in decltype(std::__invoke(_S_declval<0ul>(), 
_S_declval<1ul>())) std::thread::_Invoker >::_M_invoke<0ul, 1ul>(std::_Index_tuple<0ul, 1ul>) 
/home/vmiklos/lode/opt_private/gcc-7.3.0/lib/gcc/x86_64-pc-linux-gnu/7.3.0/../../../../include/c++/7.3.0/thread:234:13
#16 0xe47f87 in std::thread::_Invoker >::operator()() 
/home/vmiklos/lode/opt_private/gcc-7.3.0/lib/gcc/x86_64-pc-linux-gnu/7.3.0/../../../../include/c++/7.3.0/thread:243:11
#17 0xe4734a in 
std::thread::_State_impl > >::_M_run() 
/home/vmiklos/lode/opt_private/gcc-7.3.0/lib/gcc/x86_64-pc-linux-gnu/7.3.0/../../../../include/c++/7.3.0/thread:186:13
#18 0x7f5c2ce55e2e in execute_native_thread_routine 
/home/vmiklos/lode/packages/gccbuild/x86_64-pc-linux-gnu/libstdc++-v3/src/c++11/../../../../../gcc-7.3.0/libstdc++-v3/src/c++11/thread.cc:83
#19 0x7f5c2c832558 in start_thread (/lib64/libpthread.so.0+0x7558)
#20 0x7f5c2bf4682e in clone (/lib64/libc.so.6+0xf882e)

SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior 
/home/vmiklos/lode/opt_private/gcc-7.3.0/lib/gcc/x86_64-pc-linux-gnu/7.3.0/../../../../include/c++/7.3.0/bits/unique_ptr.h:323:9
 in

Change-Id: Ief574a11c838c77f7f159b1133beeef0deada201

diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 30f0619c6..51ca64927 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -1588,6 +1588,9 @@ void DocumentBroker::cancelTileRequests(const 
std::shared_ptr& se
 
 session->resetWireIdMap();
 
+if (!hasTileCache())
+return;
+
 const std::string canceltiles = tileCache().cancelTiles(session);
 if (!canceltiles.empty())
 {
diff --git a/wsd/DocumentBroker.hpp b/wsd/DocumentBroker.hpp
index c56ced733..1923d3b93 100644
--- a/wsd/DocumentBroker.hpp
+++ b/wsd/DocumentBroker.hpp
@@ -263,6 +263,7 @@ public:
 const std::string& getDocKey() const { return _docKey; }
 const std::string& getFilename() const { return _filename; };
 TileCache& tileCache() { return *_tileCache; }
+bool hasTileCache() { return _tileCache 

[Libreoffice-commits] online.git: wsd/DocumentBroker.cpp wsd/DocumentBroker.hpp wsd/LOOLWSD.cpp

2019-05-21 Thread Libreoffice Gerrit user
 wsd/DocumentBroker.cpp |   11 ---
 wsd/DocumentBroker.hpp |3 +++
 wsd/LOOLWSD.cpp|9 +
 3 files changed, 20 insertions(+), 3 deletions(-)

New commits:
commit 1845ed42af661dbb7b10a2fb4686ce2c8ef7e521
Author: Michael Meeks 
AuthorDate: Tue May 21 19:50:17 2019 +0100
Commit: Michael Meeks 
CommitDate: Wed May 22 01:57:48 2019 +0200

tdf#123482 - cleanup convert-to folder even more reliably.

Problems could occur if exceptiosn thrown when parsing the input stream.

Change-Id: Id82b3816450194164fc2093554c730b4a94acef1
Reviewed-on: https://gerrit.libreoffice.org/72695
Reviewed-by: Michael Meeks 
Tested-by: Michael Meeks 

diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 6779473a4..698f3dd98 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -1908,13 +1908,18 @@ ConvertToBroker::ConvertToBroker(const std::string& uri,
 ConvertToBroker::~ConvertToBroker()
 {
 NumConverters--;
-if (!_uriOrig.empty())
+removeFile(_uriOrig);
+}
+
+void ConvertToBroker::removeFile(const std::string )
+{
+if (!uriOrig.empty())
 {
 // Remove source file and directory
-Poco::Path path = _uriOrig;
+Poco::Path path = uriOrig;
 Poco::File(path).remove();
 Poco::File(path.makeParent()).remove();
-FileUtil::removeFile(_uriOrig);
+FileUtil::removeFile(uriOrig);
 }
 }
 
diff --git a/wsd/DocumentBroker.hpp b/wsd/DocumentBroker.hpp
index 0642599c2..c56ced733 100644
--- a/wsd/DocumentBroker.hpp
+++ b/wsd/DocumentBroker.hpp
@@ -481,6 +481,9 @@ public:
 
 /// How many live conversions are running.
 static size_t getInstanceCount();
+
+/// Cleanup path and its parent
+static void removeFile(const std::string );
 };
 
 #endif
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index 69e74114a..25877811a 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -572,6 +572,9 @@ class ConvertToPartHandler : public PartHandler
 public:
 std::string getFilename() const { return _filename; }
 
+/// Afterwards someone else is responsible for cleaning that up.
+void takeFile() { _filename.clear(); }
+
 ConvertToPartHandler(bool convertTo = false)
 : _convertTo(convertTo)
 {
@@ -579,6 +582,11 @@ public:
 
 virtual ~ConvertToPartHandler()
 {
+if (!_filename.empty())
+{
+LOG_TRC("Remove un-handled temporary file '" << _filename << "'");
+ConvertToBroker::removeFile(_filename);
+}
 }
 
 virtual void handlePart(const MessageHeader& header, std::istream& stream) 
override
@@ -2377,6 +2385,7 @@ private:
 
 LOG_DBG("New DocumentBroker for docKey [" << docKey << 
"].");
 auto docBroker = 
std::make_shared(fromPath, uriPublic, docKey);
+handler.takeFile();
 
 cleanupDocBrokers();
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

[Libreoffice-commits] online.git: wsd/DocumentBroker.cpp wsd/DocumentBroker.hpp wsd/reference.md wsd/Storage.cpp wsd/Storage.hpp

2018-12-05 Thread Libreoffice Gerrit user
 wsd/DocumentBroker.cpp |   12 +---
 wsd/DocumentBroker.hpp |4 +++-
 wsd/Storage.cpp|1 +
 wsd/Storage.hpp|7 +--
 wsd/reference.md   |4 
 5 files changed, 22 insertions(+), 6 deletions(-)

New commits:
commit 2e9af9da16a7ed42bde4b6294f7970c00be9c566
Author: Samuel Mehrbrodt 
AuthorDate: Tue Dec 4 08:49:49 2018 +0100
Commit: Samuel Mehrbrodt 
CommitDate: Wed Dec 5 11:50:59 2018 +0100

Add custom http header when saving before document is cleaned up from memory

Change-Id: I3ac417d83a79a665ae6575097835542f43d40cef
Reviewed-on: https://gerrit.libreoffice.org/64499
Reviewed-by: Samuel Mehrbrodt 
Tested-by: Samuel Mehrbrodt 

diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index c2dda9221..3b4de7ee6 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -962,7 +962,9 @@ bool DocumentBroker::autoSave(const bool force)
 {
 LOG_TRC("Sending forced save command for [" << _docKey << "].");
 // Don't terminate editing as this can be invoked by the admin OOM, 
but otherwise force saving anyway.
-sent = sendUnoSave(savingSessionId, /*dontTerminateEdit=*/ true, 
/*dontSaveIfUnmodified=*/ true, /*isAutosave=*/ false);
+sent = sendUnoSave(savingSessionId, /*dontTerminateEdit=*/true,
+   /*dontSaveIfUnmodified=*/true, /*isAutosave=*/false,
+   /*isExitSave=*/true);
 }
 else if (_isModified)
 {
@@ -979,14 +981,17 @@ bool DocumentBroker::autoSave(const bool force)
 timeSinceLastSaveMs >= autoSaveDurationMs)
 {
 LOG_TRC("Sending timed save command for [" << _docKey << "].");
-sent = sendUnoSave(savingSessionId, /*dontTerminateEdit=*/ true, 
/*dontSaveIfUnmodified=*/ true, /*isAutosave=*/ true);
+sent = sendUnoSave(savingSessionId, /*dontTerminateEdit=*/true,
+   /*dontSaveIfUnmodified=*/true, 
/*isAutosave=*/true,
+   /*isExitSave=*/false);
 }
 }
 
 return sent;
 }
 
-bool DocumentBroker::sendUnoSave(const std::string& sessionId, bool 
dontTerminateEdit, bool dontSaveIfUnmodified, bool isAutosave)
+bool DocumentBroker::sendUnoSave(const std::string& sessionId, bool 
dontTerminateEdit,
+ bool dontSaveIfUnmodified, bool isAutosave, 
bool isExitSave)
 {
 assertCorrectThread();
 
@@ -1029,6 +1034,7 @@ bool DocumentBroker::sendUnoSave(const std::string& 
sessionId, bool dontTerminat
 
 assert(_storage);
 _storage->setIsAutosave(isAutosave || UnitWSD::get().isAutosave());
+_storage->setIsExitSave(isExitSave);
 
 const std::string saveArgs = oss.str();
 LOG_TRC(".uno:Save arguments: " << saveArgs);
diff --git a/wsd/DocumentBroker.hpp b/wsd/DocumentBroker.hpp
index 09ee0e9d6..3d47c722d 100644
--- a/wsd/DocumentBroker.hpp
+++ b/wsd/DocumentBroker.hpp
@@ -348,7 +348,9 @@ public:
 }
 
 /// Sends the .uno:Save command to LoKit.
-bool sendUnoSave(const std::string& sessionId, bool dontTerminateEdit = 
true, bool dontSaveIfUnmodified = true, bool isAutosave = false);
+bool sendUnoSave(const std::string& sessionId, bool dontTerminateEdit = 
true,
+ bool dontSaveIfUnmodified = true, bool isAutosave = false,
+ bool isExitSave = false);
 
 /// Sends a message to all sessions
 void broadcastMessage(const std::string& message);
diff --git a/wsd/Storage.cpp b/wsd/Storage.cpp
index b40bebfb3..11c658b65 100644
--- a/wsd/Storage.cpp
+++ b/wsd/Storage.cpp
@@ -717,6 +717,7 @@ StorageBase::SaveResult 
WopiStorage::saveLocalFileToStorage(const Authorization&
 request.set("X-WOPI-Override", "PUT");
 request.set("X-LOOL-WOPI-IsModifiedByUser", isUserModified()? 
"true": "false");
 request.set("X-LOOL-WOPI-IsAutosave", getIsAutosave()? "true": 
"false");
+request.set("X-LOOL-WOPI-IsExitSave", isExitSave()? "true": 
"false");
 
 if (!getForceSave())
 {
diff --git a/wsd/Storage.hpp b/wsd/Storage.hpp
index 893fa9e35..6d56c64b0 100644
--- a/wsd/Storage.hpp
+++ b/wsd/Storage.hpp
@@ -174,10 +174,11 @@ public:
 
 bool isUserModified() const { return _isUserModified; }
 
-/// To be able to set the WOPI 'is autosave?' header appropriately.
+/// To be able to set the WOPI 'is autosave/is exitsave?' headers 
appropriately.
 void setIsAutosave(bool isAutosave) { _isAutosave = isAutosave; }
-
 bool getIsAutosave() const { return _isAutosave; }
+void setIsExitSave(bool isExitSave) { _isExitSave = isExitSave; }
+bool isExitSave() const { return _isExitSave; }
 
 void setFileInfo(const FileInfo& fileInfo) { _fileInfo = fileInfo; }
 
@@ -225,6 +226,8 @@ private:
 
 /// This save operation is an autosave.
 bool _isAutosave;
+/// Saving on exit (when the document is cleaned up from memory)
+

[Libreoffice-commits] online.git: wsd/DocumentBroker.cpp wsd/DocumentBroker.hpp

2018-01-15 Thread Ashod Nakashian
 wsd/DocumentBroker.cpp |   36 
 wsd/DocumentBroker.hpp |5 +
 2 files changed, 29 insertions(+), 12 deletions(-)

New commits:
commit f7fc3f494ca824253a2af6ad604622bcd1340b81
Author: Ashod Nakashian 
Date:   Mon Jan 15 00:49:14 2018 -0500

wsd: save before stopping

We don't force saving unconditionally now. Only
when the doc is reasonably expected to be modified
do we force saving (to circumvent the minimum duration
between auto-saves).

We invoke auto-saving before stopping the DocBroker
polling loop, whether due to idleness or server recycling.

Change-Id: I257d55f190d3df6a3ba82f2666c7602da0581d0c
Reviewed-on: https://gerrit.libreoffice.org/47887
Reviewed-by: Michael Meeks 
Tested-by: Michael Meeks 

diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 28a4920d..476ad544 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -275,8 +275,12 @@ void DocumentBroker::pollThread()
 
 if (ShutdownRequestFlag)
 {
-autoSave(true);
-stop("recycling");
+LOG_INF("Autosaving DocumentBroker for docKey [" << getDocKey() << 
"] to recycle server.");
+if (!autoSave(isPossiblyModified()))
+{
+LOG_INF("Terminating DocumentBroker for docKey [" << 
getDocKey() << "] to recycle server.");
+stop("recycling");
+}
 }
 else if (AutoSaveEnabled && !_stop &&
  std::chrono::duration_cast(now - 
last30SecCheckTime).count() >= 30)
@@ -287,14 +291,22 @@ void DocumentBroker::pollThread()
 }
 
 // Remove idle documents after 1 hour.
-const bool idle = (getIdleTimeSecs() >= IdleDocTimeoutSecs);
-
-// If all sessions have been removed, no reason to linger.
-if ((isLoaded() || _markToDestroy) && (_sessions.empty() || idle))
+const bool idle = (isLoaded() && getIdleTimeSecs() >= 
IdleDocTimeoutSecs);
+if (idle)
+{
+// Stop if there is nothing to save.
+LOG_INF("Autosaving idle DocumentBroker for docKey [" << 
getDocKey() << "] to kill.");
+if (!autoSave(isPossiblyModified()))
+{
+LOG_INF("Terminating idle DocumentBroker for docKey [" << 
getDocKey() << "].");
+stop("idle");
+}
+}
+else if (_sessions.empty() && (isLoaded() || _markToDestroy))
 {
-LOG_INF("Terminating " << (idle ? "idle" : "dead") <<
-" DocumentBroker for docKey [" << getDocKey() << "].");
-stop(idle ? "idle" : "dead");
+// If all sessions have been removed, no reason to linger.
+LOG_INF("Terminating dead DocumentBroker for docKey [" << 
getDocKey() << "].");
+stop("dead");
 }
 }
 
@@ -864,8 +876,8 @@ bool DocumentBroker::autoSave(const bool force)
 std::string savingSessionId;
 for (auto& sessionIt : _sessions)
 {
-// Save the document using first session available ...
-if (savingSessionId.empty())
+// Save the document using an editable session, or first ...
+if (savingSessionId.empty() || !sessionIt.second->isReadOnly())
 {
 savingSessionId = sessionIt.second->getId();
 }
@@ -1058,7 +1070,7 @@ size_t DocumentBroker::removeSession(const std::string& 
id)
 ", LastEditableSession: " << lastEditableSession);
 
 // If last editable, save and don't remove until after uploading to 
storage.
-if (!lastEditableSession || !autoSave(true))
+if (!lastEditableSession || !autoSave(isPossiblyModified()))
 removeSessionInternal(id);
 }
 catch (const std::exception& ex)
diff --git a/wsd/DocumentBroker.hpp b/wsd/DocumentBroker.hpp
index 1e8e0746..1571e426 100644
--- a/wsd/DocumentBroker.hpp
+++ b/wsd/DocumentBroker.hpp
@@ -367,6 +367,11 @@ private:
 /// True iff a save is in progress (requested but not completed).
 bool isSaving() const { return _lastSaveResponseTime < 
_lastSaveRequestTime; }
 
+/// True if we know the doc is modified or
+/// if there has been activity from a client after we last *requested* 
saving,
+/// since there are race conditions vis-a-vis user activity while saving.
+bool isPossiblyModified() const { return _isModified || 
(_lastSaveRequestTime < _lastActivityTime); }
+
 /// True iff there is at least one non-readonly session other than the 
given.
 /// Since only editable sessions can save, we need to use the last to
 /// save modified documents, otherwise we'll potentially have to save on
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org

[Libreoffice-commits] online.git: wsd/DocumentBroker.cpp wsd/DocumentBroker.hpp

2018-01-06 Thread Ashod Nakashian
 wsd/DocumentBroker.cpp |2 +-
 wsd/DocumentBroker.hpp |1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

New commits:
commit 040a211d60c6eab8695cad4bee78b22f38428b77
Author: Ashod Nakashian 
Date:   Wed Jan 3 23:15:44 2018 -0500

wsd: set modified flag on the storage when set on the DocumentBroker

Change-Id: Ieb4eb02f68f2d02ad88d6f59ad61de8f1e309670
Reviewed-on: https://gerrit.libreoffice.org/47365
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 53e0ae61..6a164533 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -1401,7 +1401,7 @@ void DocumentBroker::destroyIfLastEditor(const 
std::string& id)
 
 void DocumentBroker::setModified(const bool value)
 {
-if(_isModified != value)
+if (_isModified != value)
 {
 _isModified = value;
 Admin::instance().modificationAlert(_docKey, getPid(), value);
diff --git a/wsd/DocumentBroker.hpp b/wsd/DocumentBroker.hpp
index a56d3332..0e278150 100644
--- a/wsd/DocumentBroker.hpp
+++ b/wsd/DocumentBroker.hpp
@@ -248,6 +248,7 @@ public:
 
 bool isModified() const { return _isModified; }
 void setModified(const bool value);
+
 /// Save the document if the document is modified.
 /// @param force when true, will force saving if there
 /// has been any recent activity after the last save.
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: wsd/DocumentBroker.cpp wsd/DocumentBroker.hpp wsd/LOOLWSD.cpp

2017-05-22 Thread Ashod Nakashian
 wsd/DocumentBroker.cpp |   29 -
 wsd/DocumentBroker.hpp |3 +++
 wsd/LOOLWSD.cpp|3 ---
 3 files changed, 27 insertions(+), 8 deletions(-)

New commits:
commit e877adc84bc6f90bcfa52f9f63666358e6614885
Author: Ashod Nakashian 
Date:   Mon May 22 15:04:35 2017 -0400

wsd: don't stop doc on unauthorized loading

When a client connects with expired/invalid
access_token, the document should remain
active for other/existing clients, if any.

However, if no clients exists (i.e. the
first client has invalid access_token),
then the document should be unloaded and
cleaned up.

Change-Id: Iaad95a4286325cc6ee130b37e3ad635993a71c72
Reviewed-on: https://gerrit.libreoffice.org/37916
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 73178103..17ce1be2 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -785,6 +785,25 @@ std::string DocumentBroker::getJailRoot() const
 
 size_t DocumentBroker::addSession(const std::shared_ptr& 
session)
 {
+try
+{
+return addSessionInternal(session);
+}
+catch (const std::exception& exc)
+{
+LOG_ERR("Failed to add session to [" << _docKey << "] with URI [" << 
session->getPublicUri().toString() << "]: " << exc.what());
+if (_sessions.empty())
+{
+LOG_INF("Doc [" << _docKey << "] has no more sessions. Marking to 
destroy.");
+_markToDestroy = true;
+}
+
+throw;
+}
+}
+
+size_t DocumentBroker::addSessionInternal(const 
std::shared_ptr& session)
+{
 assertCorrectThread();
 
 try
@@ -815,12 +834,7 @@ size_t DocumentBroker::addSession(const 
std::shared_ptr& session)
 _markToDestroy = false;
 _stop = false;
 
-// Add and attach the session.
-_sessions.emplace(session->getId(), session);
-session->setAttached();
-
 const auto id = session->getId();
-const auto count = _sessions.size();
 
 // Request a new session from the child kit.
 const std::string aMessage = "session " + id + ' ' + _docKey + ' ' + 
_docId;
@@ -829,6 +843,11 @@ size_t DocumentBroker::addSession(const 
std::shared_ptr& session)
 // Tell the admin console about this new doc
 Admin::instance().addDoc(_docKey, getPid(), getFilename(), id, 
session->getUserName());
 
+// Add and attach the session.
+_sessions.emplace(session->getId(), session);
+session->setAttached();
+
+const auto count = _sessions.size();
 LOG_TRC("Added " << (session->isReadOnly() ? "readonly" : "non-readonly") 
<<
 " session [" << id << "] to docKey [" <<
 _docKey << "] to have " << count << " sessions.");
diff --git a/wsd/DocumentBroker.hpp b/wsd/DocumentBroker.hpp
index 14fe17e0..23b699e4 100644
--- a/wsd/DocumentBroker.hpp
+++ b/wsd/DocumentBroker.hpp
@@ -350,6 +350,9 @@ private:
 /// Saves the doc to the storage.
 bool saveToStorageInternal(const std::string& sesionId, bool success, 
const std::string& result = "");
 
+/// Loads a new session and adds to the sessions container.
+size_t addSessionInternal(const std::shared_ptr& session);
+
 /// Removes a session by ID. Returns the new number of sessions.
 size_t removeSessionInternal(const std::string& id);
 
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index 3a877242..7c188f17 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -2127,19 +2127,16 @@ private:
 LOG_ERR("Unauthorized Request while loading 
session for " << docBroker->getDocKey() << ": " << exc.what());
 const std::string msg = "error: cmd=internal 
kind=unauthorized";
 clientSession->sendMessage(msg);
-docBroker->stop();
 }
 catch (const StorageConnectionException& exc)
 {
 // Alert user about failed load
 const std::string msg = "error: cmd=storage 
kind=loadfailed";
 clientSession->sendMessage(msg);
-docBroker->stop();
 }
 catch (const std::exception& exc)
 {
 LOG_ERR("Error while loading : " << 
exc.what());
-docBroker->stop();
 }
 });
 });
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: wsd/DocumentBroker.cpp wsd/DocumentBroker.hpp

2017-04-11 Thread Miklos Vajna
 wsd/DocumentBroker.cpp |8 
 wsd/DocumentBroker.hpp |8 
 2 files changed, 8 insertions(+), 8 deletions(-)

New commits:
commit 8a1f321c8492d6c2824317c7e4be1a3bdfa81665
Author: Miklos Vajna 
Date:   Tue Apr 11 08:54:09 2017 +0200

DocumentBroker: avoid unnecessary copying

Change-Id: Iaa555ed8e347d0e1712c617839f007d0b4f3204b

diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 33f88ef7..e041db70 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -522,7 +522,7 @@ bool DocumentBroker::load(const 
std::shared_ptr& session, const s
 return true;
 }
 
-bool DocumentBroker::saveToStorage(const std::string sessionId,
+bool DocumentBroker::saveToStorage(const std::string& sessionId,
bool success, const std::string& result)
 {
 assertCorrectThread();
@@ -823,7 +823,7 @@ size_t DocumentBroker::addSession(const 
std::shared_ptr& session)
 return count;
 }
 
-size_t DocumentBroker::removeSession(const std::string id, bool destroyIfLast)
+size_t DocumentBroker::removeSession(const std::string& id, bool destroyIfLast)
 {
 assertCorrectThread();
 
@@ -846,7 +846,7 @@ size_t DocumentBroker::removeSession(const std::string id, 
bool destroyIfLast)
 return _sessions.size();
 }
 
-size_t DocumentBroker::removeSessionInternal(const std::string id)
+size_t DocumentBroker::removeSessionInternal(const std::string& id)
 {
 assertCorrectThread();
 try
@@ -894,7 +894,7 @@ size_t DocumentBroker::removeSessionInternal(const 
std::string id)
 return _sessions.size();
 }
 
-void DocumentBroker::addCallback(SocketPoll::CallbackFn fn)
+void DocumentBroker::addCallback(const SocketPoll::CallbackFn& fn)
 {
 _poll->addCallback(fn);
 }
diff --git a/wsd/DocumentBroker.hpp b/wsd/DocumentBroker.hpp
index 20bdc496..62cb6a95 100644
--- a/wsd/DocumentBroker.hpp
+++ b/wsd/DocumentBroker.hpp
@@ -233,7 +233,7 @@ public:
 void setLoaded();
 
 /// Save the document to Storage if it needs persisting.
-bool saveToStorage(const std::string sesionId, bool success, const 
std::string& result = "");
+bool saveToStorage(const std::string& sesionId, bool success, const 
std::string& result = "");
 bool isModified() const { return _isModified; }
 void setModified(const bool value);
 
@@ -265,10 +265,10 @@ public:
 size_t addSession(const std::shared_ptr& session);
 
 /// Removes a session by ID. Returns the new number of sessions.
-size_t removeSession(const std::string id, bool destroyIfLast = false);
+size_t removeSession(const std::string& id, bool destroyIfLast = false);
 
 /// Add a callback to be invoked in our polling thread.
-void addCallback(SocketPoll::CallbackFn fn);
+void addCallback(const SocketPoll::CallbackFn& fn);
 
 /// Transfer this socket into our polling thread / loop.
 void addSocketToPoll(const std::shared_ptr& socket);
@@ -342,7 +342,7 @@ private:
 bool saveToStorageInternal(const std::string& sesionId, bool success, 
const std::string& result = "");
 
 /// Removes a session by ID. Returns the new number of sessions.
-size_t removeSessionInternal(const std::string id);
+size_t removeSessionInternal(const std::string& id);
 
 /// Forward a message from child session to its respective client session.
 bool forwardToClient(const std::shared_ptr& payload);
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: wsd/DocumentBroker.cpp wsd/DocumentBroker.hpp

2017-04-06 Thread Ashod Nakashian
 wsd/DocumentBroker.cpp |   10 +++---
 wsd/DocumentBroker.hpp |6 +++---
 2 files changed, 10 insertions(+), 6 deletions(-)

New commits:
commit 1e1f23716c9ee3ce880d1d927945386cf5400293
Author: Ashod Nakashian 
Date:   Thu Apr 6 13:49:44 2017 -0400

wsd: don't take reference to session member being destroyed

Change-Id: I0074f4557018feb47a7a2a95a3fca238407a0023
Reviewed-on: https://gerrit.libreoffice.org/36227
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 9550dfd2..eb53f195 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -516,7 +516,7 @@ bool DocumentBroker::load(const 
std::shared_ptr& session, const s
 return true;
 }
 
-bool DocumentBroker::saveToStorage(const std::string& sessionId,
+bool DocumentBroker::saveToStorage(const std::string sessionId,
bool success, const std::string& result)
 {
 assertCorrectThread();
@@ -817,7 +817,7 @@ size_t DocumentBroker::addSession(const 
std::shared_ptr& session)
 return count;
 }
 
-size_t DocumentBroker::removeSession(const std::string& id, bool destroyIfLast)
+size_t DocumentBroker::removeSession(const std::string id, bool destroyIfLast)
 {
 assertCorrectThread();
 
@@ -840,7 +840,7 @@ size_t DocumentBroker::removeSession(const std::string& id, 
bool destroyIfLast)
 return _sessions.size();
 }
 
-size_t DocumentBroker::removeSessionInternal(const std::string& id)
+size_t DocumentBroker::removeSessionInternal(const std::string id)
 {
 assertCorrectThread();
 try
@@ -853,6 +853,10 @@ size_t DocumentBroker::removeSessionInternal(const 
std::string& id)
 LOOLWSD::dumpEndSessionTrace(getJailId(), id, _uriOrig);
 
 const auto readonly = (it->second ? it->second->isReadOnly() : 
false);
+
+//FIXME: We might be called from the session we are removing,
+//FIXME: and if this is the last/only reference, we destroy it.
+//FIXME: Should flag and remove from the poll thread.
 _sessions.erase(it);
 
 const auto count = _sessions.size();
diff --git a/wsd/DocumentBroker.hpp b/wsd/DocumentBroker.hpp
index c8758ba9..88fa2b6e 100644
--- a/wsd/DocumentBroker.hpp
+++ b/wsd/DocumentBroker.hpp
@@ -233,7 +233,7 @@ public:
 void setLoaded();
 
 /// Save the document to Storage if it needs persisting.
-bool saveToStorage(const std::string& sesionId, bool success, const 
std::string& result = "");
+bool saveToStorage(const std::string sesionId, bool success, const 
std::string& result = "");
 bool isModified() const { return _isModified; }
 void setModified(const bool value);
 
@@ -265,7 +265,7 @@ public:
 size_t addSession(const std::shared_ptr& session);
 
 /// Removes a session by ID. Returns the new number of sessions.
-size_t removeSession(const std::string& id, bool destroyIfLast = false);
+size_t removeSession(const std::string id, bool destroyIfLast = false);
 
 /// Add a callback to be invoked in our polling thread.
 void addCallback(SocketPoll::CallbackFn fn);
@@ -342,7 +342,7 @@ private:
 bool saveToStorageInternal(const std::string& sesionId, bool success, 
const std::string& result = "");
 
 /// Removes a session by ID. Returns the new number of sessions.
-size_t removeSessionInternal(const std::string& id);
+size_t removeSessionInternal(const std::string id);
 
 /// Forward a message from child session to its respective client session.
 bool forwardToClient(const std::shared_ptr& payload);
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: wsd/DocumentBroker.cpp wsd/DocumentBroker.hpp

2017-04-06 Thread Ashod Nakashian
 wsd/DocumentBroker.cpp |4 ++--
 wsd/DocumentBroker.hpp |5 -
 2 files changed, 2 insertions(+), 7 deletions(-)

New commits:
commit 7da1909d3c7596f6801391f7286efeadd114c44b
Author: Ashod Nakashian 
Date:   Thu Apr 6 13:49:22 2017 -0400

wsd: kill DocumentBroker::getSessionsCount

Change-Id: Icd3229fe9b7d2f17a0e8a8f955c41ead8bca98c7
Reviewed-on: https://gerrit.libreoffice.org/36226
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 0ee99738..9550dfd2 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -247,7 +247,7 @@ void DocumentBroker::pollThread()
 
 // Cleanup used and dead entries.
 if ((isLoaded() || _markToDestroy) &&
-(getSessionsCount() == 0 || !isAlive() || idle))
+(_sessions.empty() || !isAlive() || idle))
 {
 LOG_INF("Terminating " << (idle ? "idle" : "dead") <<
 " DocumentBroker for docKey [" << getDocKey() << "].");
@@ -1369,7 +1369,7 @@ void DocumentBroker::dumpState(std::ostream& os)
 os << "\n  jailed uri: " << _uriJailed.toString();
 os << "\n  doc key: " << _docKey;
 os << "\n  doc id: " << _docId;
-os << "\n  num sessions: " << getSessionsCount();
+os << "\n  num sessions: " << _sessions.size();
 os << "\n  last editable?: " << _lastEditableSession;
 std::time_t t = std::chrono::system_clock::to_time_t(
 std::chrono::system_clock::now()
diff --git a/wsd/DocumentBroker.hpp b/wsd/DocumentBroker.hpp
index fd8d20e8..c8758ba9 100644
--- a/wsd/DocumentBroker.hpp
+++ b/wsd/DocumentBroker.hpp
@@ -251,11 +251,6 @@ public:
 const std::string& getFilename() const { return _filename; };
 TileCache& tileCache() { return *_tileCache; }
 bool isAlive() const;
-size_t getSessionsCount() const
-{
-Util::assertIsLocked(_mutex);
-return _sessions.size();
-}
 
 /// Are we running in either shutdown, or the polling thread.
 /// Asserts in the debug builds, otherwise just logs.
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: wsd/DocumentBroker.cpp wsd/DocumentBroker.hpp wsd/LOOLWSD.cpp

2017-04-06 Thread Michael Meeks
 wsd/DocumentBroker.cpp |   12 
 wsd/DocumentBroker.hpp |2 +-
 wsd/LOOLWSD.cpp|   32 +++-
 3 files changed, 20 insertions(+), 26 deletions(-)

New commits:
commit 90127ac0e3e7d4dd90e3143c7b310249c274c1a9
Author: Michael Meeks 
Date:   Thu Apr 6 17:58:41 2017 +0100

Let the DocBroker thread clean itself up and expire.

(cherry picked from commit 2e372b70b32d4e052458547daa229c537442774f)

Change-Id: I5835c83f44ef770fa6ccd2418fc6ca73e17694e4
Reviewed-on: https://gerrit.libreoffice.org/36225
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index a5a995df..0ee99738 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -241,6 +241,18 @@ void DocumentBroker::pollThread()
 LOG_INF("No more sessions in doc [" << _docKey << "]. 
Terminating.");
 _stop = true;
 }
+
+// Remove idle documents after 1 hour.
+const bool idle = getIdleTimeSecs() >= 3600;
+
+// Cleanup used and dead entries.
+if ((isLoaded() || _markToDestroy) &&
+(getSessionsCount() == 0 || !isAlive() || idle))
+{
+LOG_INF("Terminating " << (idle ? "idle" : "dead") <<
+" DocumentBroker for docKey [" << getDocKey() << "].");
+_stop = true;
+}
 }
 
 LOG_INF("Finished polling doc [" << _docKey << "]. stop: " << _stop << ", 
continuePolling: " <<
diff --git a/wsd/DocumentBroker.hpp b/wsd/DocumentBroker.hpp
index d05437e9..fd8d20e8 100644
--- a/wsd/DocumentBroker.hpp
+++ b/wsd/DocumentBroker.hpp
@@ -304,7 +304,7 @@ public:
 void handleTileCombinedResponse(const std::vector& payload);
 
 void destroyIfLastEditor(const std::string& id);
-bool isMarkedToDestroy() const { return _markToDestroy; }
+bool isMarkedToDestroy() const { return _markToDestroy || _stop; }
 
 bool handleInput(const std::vector& payload);
 
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index e5d4cb68..439ab67e 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -235,33 +235,15 @@ void cleanupDocBrokers()
 {
 auto docBroker = it->second;
 
-// If document busy at the moment, cleanup later.
-auto lock = docBroker->getDeferredLock();
-if (lock.try_lock())
+// Remove only when not alive.
+if (!docBroker->isAlive())
 {
-// Remove idle documents after 1 hour.
-const bool idle = (docBroker->getIdleTimeSecs() >= 3600);
-
-// Cleanup used and dead entries.
-if ((docBroker->isLoaded() || docBroker->isMarkedToDestroy()) &&
-(docBroker->getSessionsCount() == 0 || !docBroker->isAlive() 
|| idle))
-{
-LOG_INF("Terminating " << (idle ? "idle" : "dead") <<
-" DocumentBroker for docKey [" << it->first << "].");
-docBroker->stop();
-
-// Remove only when not alive.
-if (!docBroker->isAlive())
-{
-LOG_INF("Removing " << (idle ? "idle" : "dead") <<
-" DocumentBroker for docKey [" << it->first << 
"].");
-it = DocBrokers.erase(it);
-continue;
-}
-}
+LOG_INF("Removing DocumentBroker for docKey [" << it->first << 
"].");
+it = DocBrokers.erase(it);
+continue;
+} else {
+++it;
 }
-
-++it;
 }
 
 if (count != DocBrokers.size())
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: wsd/DocumentBroker.cpp wsd/DocumentBroker.hpp wsd/LOOLWSD.cpp

2017-04-06 Thread Michael Meeks
 wsd/DocumentBroker.cpp |8 +++-
 wsd/DocumentBroker.hpp |3 +--
 wsd/LOOLWSD.cpp|   15 ++-
 3 files changed, 14 insertions(+), 12 deletions(-)

New commits:
commit 01519eff70f1157dbbb4cb329acc7754f34a2765
Author: Michael Meeks 
Date:   Wed Apr 5 21:31:15 2017 +0100

Always cleanup DocBrokers in the PrisonerPoll thread.

This simplifies things, and keeps process management in one thread.
Also - wakeup the DocumentBroker when we want to stop it.

Change-Id: I597ba4b34719fc072a4b4ad3697442b5eebe5784
Reviewed-on: https://gerrit.libreoffice.org/36182
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 5a4de9e2..396bf52b 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -264,7 +264,7 @@ void DocumentBroker::pollThread()
 _poll->poll(std::min(flushTimeoutMs - elapsedMs, POLL_TIMEOUT_MS / 5));
 }
 
-// Cleanup.
+// Async cleanup.
 LOOLWSD::doHousekeeping();
 
 LOG_INF("Finished docBroker polling thread for docKey [" << _docKey << 
"].");
@@ -306,6 +306,12 @@ void DocumentBroker::joinThread()
 _poll->joinThread();
 }
 
+void DocumentBroker::stop()
+{
+_stop = true;
+_poll->wakeup();
+}
+
 bool DocumentBroker::load(const std::shared_ptr& session, const 
std::string& jailId)
 {
 assertCorrectThread();
diff --git a/wsd/DocumentBroker.hpp b/wsd/DocumentBroker.hpp
index 0af441ff..d05437e9 100644
--- a/wsd/DocumentBroker.hpp
+++ b/wsd/DocumentBroker.hpp
@@ -222,8 +222,7 @@ public:
 void startThread();
 
 /// Flag for termination.
-//TODO: Take reason to broadcast to clients.
-void stop() { _stop = true; }
+void stop();
 
 /// Thread safe termination of this broker if it has a lingering thread
 void joinThread();
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index 08a20ce7..e5d4cb68 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -226,7 +226,7 @@ void alertAllUsersInternal(const std::string& msg)
 /// Remove dead and idle DocBrokers.
 /// The client of idle document should've greyed-out long ago.
 /// Returns true if at least one is removed.
-bool cleanupDocBrokers()
+void cleanupDocBrokers()
 {
 Util::assertIsLocked(DocBrokersMutex);
 
@@ -277,11 +277,7 @@ bool cleanupDocBrokers()
 
 LOG_END(logger);
 }
-
-return true;
 }
-
-return false;
 }
 
 /// Forks as many children as requested.
@@ -582,7 +578,7 @@ class PrisonerPoll : public TerminatingPoll {
 public:
 PrisonerPoll() : TerminatingPoll("prisoner_poll") {}
 
-/// Check prisoners are still alive and balaned.
+/// Check prisoners are still alive and balanced.
 void wakeupHook() override;
 };
 
@@ -1099,12 +1095,13 @@ bool LOOLWSD::checkAndRestoreForKit()
 #endif
 }
 
-void PrisonerPoll::wakeupHook()
+void LOOLWSD::doHousekeeping()
 {
-LOOLWSD::doHousekeeping();
+PrisonerPoll.wakeup();
 }
 
-void LOOLWSD::doHousekeeping()
+/// Really do the house-keeping
+void PrisonerPoll::wakeupHook()
 {
 if (!LOOLWSD::checkAndRestoreForKit())
 {
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: wsd/DocumentBroker.cpp wsd/DocumentBroker.hpp wsd/LOOLWSD.cpp

2017-04-01 Thread Ashod Nakashian
 wsd/DocumentBroker.cpp |   28 ++--
 wsd/DocumentBroker.hpp |9 ++---
 wsd/LOOLWSD.cpp|   47 +--
 3 files changed, 33 insertions(+), 51 deletions(-)

New commits:
commit 63ab3bcfa49ec9f6efb0fa81657ea64eaf0ab007
Author: Ashod Nakashian 
Date:   Sat Apr 1 19:20:54 2017 -0400

wsd: remove queueSession and simplify session loading

Change-Id: Ia03a4ed64b743da8fa7e27de853623126698b9c0
Reviewed-on: https://gerrit.libreoffice.org/36016
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 0a6d2f01..494f21f3 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -223,22 +223,6 @@ void DocumentBroker::pollThread()
 // Main polling loop goodness.
 while (!_stop && _poll->continuePolling() && !TerminationFlag && 
!ShutdownRequestFlag)
 {
-// First, load new sessions.
-for (const auto& pair : _sessions)
-{
-try
-{
-auto& session = pair.second;
-if (!session->isAttached())
-addSession(session);
-}
-catch (const std::exception& exc)
-{
-LOG_ERR("Error while adding new session to doc [" << _docKey 
<< "]: " << exc.what());
-//TODO: Send failure to client and remove session.
-}
-}
-
 _poll->poll(SocketPoll::DefaultPollTimeoutMs);
 
 if (!std::getenv("LOOL_NO_AUTOSAVE") && !_stop &&
@@ -746,16 +730,6 @@ std::string DocumentBroker::getJailRoot() const
 return Poco::Path(_childRoot, _jailId).toString();
 }
 
-size_t DocumentBroker::queueSession(std::shared_ptr& session)
-{
-std::unique_lock lock(_mutex);
-
-_sessions.emplace(session->getId(), session);
-_poll->wakeup();
-
-return _sessions.size();
-}
-
 size_t DocumentBroker::addSession(const std::shared_ptr& 
session)
 {
 assert(isCorrectThread());
@@ -788,6 +762,8 @@ size_t DocumentBroker::addSession(const 
std::shared_ptr& session)
 _markToDestroy = false;
 _stop = false;
 
+// Add and attach the session.
+_sessions.emplace(session->getId(), session);
 session->setAttached();
 
 const auto id = session->getId();
diff --git a/wsd/DocumentBroker.hpp b/wsd/DocumentBroker.hpp
index a7473531..915db5a6 100644
--- a/wsd/DocumentBroker.hpp
+++ b/wsd/DocumentBroker.hpp
@@ -266,10 +266,8 @@ public:
 
 std::string getJailRoot() const;
 
-/// Queue a new session to be attached asynchronously.
-/// @return amount of session we have after all the queued ones will be
-/// created.
-size_t queueSession(std::shared_ptr& session);
+/// Add a new session. Returns the new number of sessions.
+size_t addSession(const std::shared_ptr& session);
 
 /// Removes a session by ID. Returns the new number of sessions.
 size_t removeSession(const std::string& id, bool destroyIfLast = false);
@@ -354,9 +352,6 @@ private:
 /// Forward a message from child session to its respective client session.
 bool forwardToClient(const std::shared_ptr& payload);
 
-/// Add a new session. Returns the new number of sessions.
-size_t addSession(const std::shared_ptr& session);
-
 /// The thread function that all of the I/O for all sessions
 /// associated with this document.
 void pollThread();
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index db5f55a2..05c6e1da 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -1324,8 +1324,6 @@ static std::shared_ptr 
createNewClientSession(const WebSocketHand
 // (UserCanWrite param).
 auto session = std::make_shared(id, docBroker, 
uriPublic, isReadOnly);
 
-docBroker->queueSession(session);
-
 return session;
 }
 catch (const std::exception& exc)
@@ -1860,17 +1858,18 @@ private:
 auto clientSession = createNewClientSession(nullptr, _id, 
uriPublic, docBroker, isReadOnly);
 if (clientSession)
 {
+clientSession->setSaveAsSocket(socket);
+
 // Transfer the client socket to the DocumentBroker.
 // Move the socket into DocBroker.
 docBroker->addSocketToPoll(socket);
 socketOwnership = 
SocketHandlerInterface::SocketOwnership::MOVED;
 
-clientSession->setSaveAsSocket(socket);
-
-docBroker->startThread();
-
-docBroker->addCallback([&]()
+docBroker->addCallback([&, clientSession]()
 {
+// First add and load the session.
+docBroker->addSession(clientSession);
+
 // Load the 

[Libreoffice-commits] online.git: wsd/DocumentBroker.cpp wsd/DocumentBroker.hpp

2017-03-25 Thread Ashod Nakashian
 wsd/DocumentBroker.cpp |5 ++---
 wsd/DocumentBroker.hpp |4 ++--
 2 files changed, 4 insertions(+), 5 deletions(-)

New commits:
commit a57b9e6917c6d1a80eb4d800d63dfde7f40f79f2
Author: Ashod Nakashian 
Date:   Sat Mar 25 13:56:17 2017 -0400

wsd: const correctness

Change-Id: I2bba04ccba9fd97e10ecc56f7db1f62a66a8f5f0
Reviewed-on: https://gerrit.libreoffice.org/35702
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index d3934d1b..2f7ab961 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -300,7 +300,7 @@ DocumentBroker::~DocumentBroker()
 _childProcess.reset();
 }
 
-bool DocumentBroker::load(std::shared_ptr& session, const 
std::string& jailId)
+bool DocumentBroker::load(const std::shared_ptr& session, const 
std::string& jailId)
 {
 Util::assertIsLocked(_mutex);
 
@@ -743,7 +743,7 @@ size_t 
DocumentBroker::queueSession(std::shared_ptr& session)
 return _sessions.size() + _newSessions.size();
 }
 
-size_t DocumentBroker::addSession(std::shared_ptr& session)
+size_t DocumentBroker::addSession(const std::shared_ptr& 
session)
 {
 Util::assertIsLocked(_mutex);
 
@@ -864,7 +864,6 @@ size_t DocumentBroker::removeSessionInternal(const 
std::string& id)
 return _sessions.size();
 }
 
-
 void DocumentBroker::addCallback(SocketPoll::CallbackFn fn)
 {
 _poll->addCallback(fn);
diff --git a/wsd/DocumentBroker.hpp b/wsd/DocumentBroker.hpp
index 526f873d..13acb9bb 100644
--- a/wsd/DocumentBroker.hpp
+++ b/wsd/DocumentBroker.hpp
@@ -225,7 +225,7 @@ public:
 void startThread();
 
 /// Loads a document from the public URI into the jail.
-bool load(std::shared_ptr& session, const std::string& 
jailId);
+bool load(const std::shared_ptr& session, const 
std::string& jailId);
 bool isLoaded() const { return _isLoaded; }
 void setLoaded();
 
@@ -354,7 +354,7 @@ private:
 bool forwardToClient(const std::shared_ptr& payload);
 
 /// Add a new session. Returns the new number of sessions.
-size_t addSession(std::shared_ptr& session);
+size_t addSession(const std::shared_ptr& session);
 
 /// The thread function that all of the I/O for all sessions
 /// associated with this document.
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: wsd/DocumentBroker.cpp wsd/DocumentBroker.hpp wsd/LOOLWSD.cpp

2017-03-12 Thread Ashod Nakashian
 wsd/DocumentBroker.cpp |5 -
 wsd/DocumentBroker.hpp |8 
 wsd/LOOLWSD.cpp|6 +-
 3 files changed, 5 insertions(+), 14 deletions(-)

New commits:
commit 388d7b1dbf1a5c2d155c0149247b3a319114f8b0
Author: Ashod Nakashian 
Date:   Sun Mar 12 14:12:36 2017 -0400

wsd: TerminatingPoll always starts its own thread

Since all TerminatingPoll instances need to fire
a thread, no reason to do it manually and risk
races. Now TerminatingPoll does it in the ctor.

Change-Id: I59850ad48b3789f3a23d01abb05a7f28e5717031
Reviewed-on: https://gerrit.libreoffice.org/35114
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 1b47d68..fa8ba94 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -163,11 +163,6 @@ DocumentBroker::DocumentBroker(const std::string& uri,
 _stop = false;
 }
 
-void DocumentBroker::startThread()
-{
-_poll->startThread();
-}
-
 // The inner heart of the DocumentBroker - our poll loop.
 void DocumentBroker::pollThread()
 {
diff --git a/wsd/DocumentBroker.hpp b/wsd/DocumentBroker.hpp
index 2d30802..2a9c152 100644
--- a/wsd/DocumentBroker.hpp
+++ b/wsd/DocumentBroker.hpp
@@ -44,7 +44,10 @@ class TerminatingPoll : public SocketPoll
 {
 public:
 TerminatingPoll(const std::string ) :
-SocketPoll(threadName) {}
+SocketPoll(threadName)
+{
+startThread();
+}
 
 bool continuePolling() override
 {
@@ -220,9 +223,6 @@ public:
 
 ~DocumentBroker();
 
-/// Start processing events
-void startThread();
-
 /// Loads a document from the public URI into the jail.
 bool load(std::shared_ptr& session, const std::string& 
jailId);
 bool isLoaded() const { return _isLoaded; }
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index a459bf4..98250b4 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -2167,7 +2167,6 @@ private:
 
 void handleClientWsUpgrade(const Poco::Net::HTTPRequest& request, const 
std::string& url)
 {
-// requestHandler = new ClientRequestHandler();
 LOG_INF("Client WS request" << request.getURI() << ", url: " << url);
 
 // First Upgrade.
@@ -2221,9 +2220,9 @@ private:
 _clientSession->onConnect(socket);
 docBroker->addSocketToPoll(socket);
 }
-docBroker->startThread();
 }
 }
+
 if (!docBroker || !_clientSession)
 LOG_WRN("Failed to connect DocBroker and Client Session.");
 }
@@ -2349,14 +2348,11 @@ public:
 void startPrisoners(const int port)
 {
 PrisonerPoll.insertNewSocket(findPrisonerServerPort(port));
-PrisonerPoll.startThread();
 }
 
 void start(const int port)
 {
 _acceptPoll.insertNewSocket(findServerPort(port));
-_acceptPoll.startThread();
-WebServerPoll.startThread();
 }
 
 void stop()
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: wsd/DocumentBroker.cpp wsd/DocumentBroker.hpp wsd/LOOLWSD.cpp

2017-03-12 Thread Ashod Nakashian
 wsd/DocumentBroker.cpp |   34 ++
 wsd/DocumentBroker.hpp |   10 +-
 wsd/LOOLWSD.cpp|4 ++--
 3 files changed, 13 insertions(+), 35 deletions(-)

New commits:
commit cbd00bf7c8600afb0f7ec09a8ad90f1b5ed2f298
Author: Ashod Nakashian 
Date:   Sun Mar 12 13:56:42 2017 -0400

wsd: simplify DocumentBroker construction

DocumentBrokerPoll is always owned by a
single DocumentBroker instance, so we
can hold a reference to it. This eliminates
the need to hold a shared_ptr to the owner
which, in turn, eliminates the need for
a create wrapper.

Change-Id: I954c9dddcc3b2cfdd5dfcc8248ab3d47a897f684
Reviewed-on: https://gerrit.libreoffice.org/35113
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index c4c3307..1b47d68 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -114,23 +114,22 @@ std::string DocumentBroker::getDocKey(const Poco::URI& 
uri)
 }
 
 /// The Document Broker Poll - one of these in a thread per document
-class DocumentBroker::DocumentBrokerPoll : public TerminatingPoll
+class DocumentBroker::DocumentBrokerPoll final : public TerminatingPoll
 {
-std::shared_ptr _docBroker;
+/// The DocumentBroker owning us.
+DocumentBroker& _docBroker;
+
 public:
-DocumentBrokerPoll(const std::string )
-: TerminatingPoll(threadName)
-{
-}
-void setDocumentBroker(const std::shared_ptr )
+DocumentBrokerPoll(const std::string , DocumentBroker& 
docBroker) :
+TerminatingPoll(threadName),
+_docBroker(docBroker)
 {
-_docBroker = docBroker;
 }
 
 virtual void pollingThread()
 {
-assert (_docBroker);
-_docBroker->pollThread();
+// Delegate to the docBroker.
+_docBroker.pollThread();
 }
 };
 
@@ -152,7 +151,7 @@ DocumentBroker::DocumentBroker(const std::string& uri,
 _cursorPosY(0),
 _cursorWidth(0),
 _cursorHeight(0),
-_poll(new DocumentBrokerPoll("docbrk_poll")),
+_poll(new DocumentBrokerPoll("docbrk_poll", *this)),
 _tileVersion(0),
 _debugRenderedTileCount(0)
 {
@@ -164,19 +163,6 @@ DocumentBroker::DocumentBroker(const std::string& uri,
 _stop = false;
 }
 
-std::shared_ptr DocumentBroker::create(
-const std::string& uri,
-const Poco::URI& uriPublic,
-const std::string& docKey,
-const std::string& childRoot)
-{
-std::shared_ptr docBroker = 
std::make_shared(uri, uriPublic, docKey, childRoot);
-
-docBroker->_poll->setDocumentBroker(docBroker);
-
-return docBroker;
-}
-
 void DocumentBroker::startThread()
 {
 _poll->startThread();
diff --git a/wsd/DocumentBroker.hpp b/wsd/DocumentBroker.hpp
index 0ca4ab7..2d30802 100644
--- a/wsd/DocumentBroker.hpp
+++ b/wsd/DocumentBroker.hpp
@@ -212,19 +212,11 @@ public:
 /// Dummy document broker that is marked to destroy.
 DocumentBroker();
 
-/// Use create - not this constructor ...
-/// FIXME: friend with make_shared etc.
+/// Construct DocumentBroker with URI, docKey, and root path.
 DocumentBroker(const std::string& uri,
const Poco::URI& uriPublic,
const std::string& docKey,
const std::string& childRoot);
-public:
-static std::shared_ptr create(
-   const std::string& uri,
-   const Poco::URI& uriPublic,
-   const std::string& docKey,
-   const std::string& childRoot);
-
 
 ~DocumentBroker();
 
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index eb06f5f..a459bf4 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -1296,7 +1296,7 @@ static std::shared_ptr 
createDocBroker(WebSocketHandler& ws,
 
 // Set the one we just created.
 LOG_DBG("New DocumentBroker for docKey [" << docKey << "].");
-auto docBroker = DocumentBroker::create(uri, uriPublic, docKey, 
LOOLWSD::ChildRoot);
+auto docBroker = std::make_shared(uri, uriPublic, docKey, 
LOOLWSD::ChildRoot);
 DocBrokers.emplace(docKey, docBroker);
 LOG_TRC("Have " << DocBrokers.size() << " DocBrokers after inserting [" << 
docKey << "].");
 
@@ -1958,7 +1958,7 @@ private:
 std::unique_lock 
docBrokersLock(DocBrokersMutex);
 
 LOG_DBG("New DocumentBroker for docKey [" << docKey << 
"].");
-auto docBroker = DocumentBroker::create(fromPath, 
uriPublic, docKey, LOOLWSD::ChildRoot);
+auto docBroker = 
std::make_shared(fromPath, uriPublic, docKey, 
LOOLWSD::ChildRoot);
 
 cleanupDocBrokers();
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: wsd/DocumentBroker.cpp wsd/DocumentBroker.hpp

2017-03-11 Thread Michael Meeks
 wsd/DocumentBroker.cpp |   15 ++-
 wsd/DocumentBroker.hpp |4 +++-
 2 files changed, 17 insertions(+), 2 deletions(-)

New commits:
commit 51ae42d513842994091d10b15565ba4741092122
Author: Michael Meeks 
Date:   Sat Mar 11 22:01:27 2017 +

DocumentBroker: log load time and dump it on request.

diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 6ddb463..c4c3307 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -190,6 +190,8 @@ void DocumentBroker::pollThread()
 
 LOG_INF("Starting docBroker polling thread for docKey [" << _docKey << 
"].");
 
+_threadStart = std::chrono::steady_clock::now();
+
 // Request a kit process for this doc.
 _childProcess = getNewChild_Blocks();
 if (!_childProcess)
@@ -603,6 +605,14 @@ bool DocumentBroker::saveToStorageInternal(const 
std::string& sessionId,
 return false;
 }
 
+void DocumentBroker::setLoaded()
+{
+_isLoaded = true;
+_loadDuration = std::chrono::duration_cast(
+std::chrono::steady_clock::now() - _threadStart);
+LOG_TRC("Document loaded in " << _loadDuration.count() << "ms");
+}
+
 bool DocumentBroker::autoSave(const bool force)
 {
 if (_sessions.empty() || _storage == nullptr || !_isLoaded ||
@@ -1311,7 +1321,10 @@ void DocumentBroker::dumpState()
 std::cerr << " *** Marked to destroy ***\n";
 else
 std::cerr << " has live sessions\n";
-std::cerr << "  loaded?: " << _isLoaded << "\n";
+if (_isLoaded)
+std::cerr << "  loaded in: " << _loadDuration.count() << "ms\n";
+else
+std::cerr << "  still loading...\n";
 std::cerr << "  modified?: " << _isModified << "\n";
 std::cerr << "  jail id: " << _jailId << "\n";
 std::cerr << "  public uri: " << _uriPublic.toString() << "\n";
diff --git a/wsd/DocumentBroker.hpp b/wsd/DocumentBroker.hpp
index b07b9b5..0ca4ab7 100644
--- a/wsd/DocumentBroker.hpp
+++ b/wsd/DocumentBroker.hpp
@@ -234,7 +234,7 @@ public:
 /// Loads a document from the public URI into the jail.
 bool load(std::shared_ptr& session, const std::string& 
jailId);
 bool isLoaded() const { return _isLoaded; }
-void setLoaded() { _isLoaded = true; }
+void setLoaded();
 
 /// Save the document to Storage if it needs persisting.
 bool saveToStorage(const std::string& sesionId, bool success, const 
std::string& result = "");
@@ -417,6 +417,8 @@ private:
 int _debugRenderedTileCount;
 
 std::chrono::steady_clock::time_point _lastActivityTime;
+std::chrono::steady_clock::time_point _threadStart;
+std::chrono::milliseconds _loadDuration;
 
 static constexpr auto IdleSaveDurationMs = 30 * 1000;
 static constexpr auto AutoSaveDurationMs = 300 * 1000;
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: wsd/DocumentBroker.cpp wsd/DocumentBroker.hpp

2017-01-25 Thread Ashod Nakashian
 wsd/DocumentBroker.cpp |   80 +
 wsd/DocumentBroker.hpp |3 +
 2 files changed, 37 insertions(+), 46 deletions(-)

New commits:
commit f73a17c759f1628db26ec3e8606b5ab799b1acf3
Author: Ashod Nakashian 
Date:   Sun Jan 22 23:18:37 2017 -0500

wsd: use Message objects to handle kit responses

Change-Id: Ifc9c53ead8d87e9aebfd8c60442a726de5270cc5
Reviewed-on: https://gerrit.libreoffice.org/33440
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index fb19ca4..7b3ee4c 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -716,39 +716,42 @@ void DocumentBroker::alertAllUsers(const std::string& msg)
 
 bool DocumentBroker::handleInput(const std::vector& payload)
 {
-const auto msg = LOOLProtocol::getAbbreviatedMessage(payload);
+auto message = std::make_shared(payload.data(), payload.size(), 
Message::Dir::Out);
+const auto& msg = message->abbr();
 LOG_TRC("DocumentBroker handling child message: [" << msg << "].");
 
 LOOLWSD::dumpOutgoingTrace(getJailId(), "0", msg);
 
-const auto command = LOOLProtocol::getFirstToken(msg);
-if (command == "tile:")
+if (LOOLProtocol::getFirstToken(message->forwardToken(), '-') == "client")
 {
-handleTileResponse(payload);
-}
-else if (command == "tilecombine:")
-{
-handleTileCombinedResponse(payload);
-}
-else if (LOOLProtocol::getFirstToken(command, '-') == "client")
-{
-forwardToClient(command, payload);
-}
-else if (command == "errortoall:")
-{
-StringTokenizer tokens(msg, " ", StringTokenizer::TOK_IGNORE_EMPTY | 
StringTokenizer::TOK_TRIM);
-assert(tokens.count() == 3);
-std::string cmd, kind;
-LOOLProtocol::getTokenString(tokens, "cmd", cmd);
-assert(cmd != "");
-LOOLProtocol::getTokenString(tokens, "kind", kind);
-assert(kind != "");
-Util::alertAllUsers(cmd, kind);
+forwardToClient(message);
 }
 else
 {
-LOG_ERR("Unexpected message: [" << msg << "].");
-return false;
+const auto& command = message->firstToken();
+if (command == "tile:")
+{
+handleTileResponse(payload);
+}
+else if (command == "tilecombine:")
+{
+handleTileCombinedResponse(payload);
+}
+else if (command == "errortoall:")
+{
+LOG_CHECK_RET(message->tokens().size() == 3, false);
+std::string cmd, kind;
+LOOLProtocol::getTokenString((*message)[1], "cmd", cmd);
+LOG_CHECK_RET(cmd != "", false);
+LOOLProtocol::getTokenString((*message)[2], "kind", kind);
+LOG_CHECK_RET(kind != "", false);
+Util::alertAllUsers(cmd, kind);
+}
+else
+{
+LOG_ERR("Unexpected message: [" << msg << "].");
+return false;
+}
 }
 
 return true;
@@ -1002,37 +1005,24 @@ bool DocumentBroker::forwardToChild(const std::string& 
viewId, const std::string
 return false;
 }
 
-bool DocumentBroker::forwardToClient(const std::string& prefix, const 
std::vector& payload)
+bool DocumentBroker::forwardToClient(const std::shared_ptr& payload)
 {
-assert(payload.size() > prefix.size());
-
-// Remove the prefix and trim.
-size_t index = prefix.size();
-for ( ; index < payload.size(); ++index)
-{
-if (payload[index] != ' ')
-{
-break;
-}
-}
-
-auto data = payload.data() + index;
-auto size = payload.size() - index;
-const auto message = getAbbreviatedMessage(data, size);
-LOG_TRC("Forwarding payload to " << prefix << ' ' << message);
+const std::string& msg = payload->abbr();
+const std::string& prefix = payload->forwardToken();
+LOG_TRC("Forwarding payload to [" << prefix << "]: " << msg);
 
 std::string name;
 std::string sid;
-if (LOOLProtocol::parseNameValuePair(prefix, name, sid, '-') && name == 
"client")
+if (LOOLProtocol::parseNameValuePair(payload->forwardToken(), name, sid, 
'-') && name == "client")
 {
 const auto it = _sessions.find(sid);
 if (it != _sessions.end())
 {
-return it->second->handleKitToClientMessage(data, size);
+return 
it->second->handleKitToClientMessage(payload->data().data(), payload->size());
 }
 else
 {
-LOG_WRN("Client session [" << sid << "] not found to forward 
message: " << message);
+LOG_WRN("Client session [" << sid << "] not found to forward 
message: " << msg);
 }
 }
 else
diff --git a/wsd/DocumentBroker.hpp b/wsd/DocumentBroker.hpp
index 27c4916..8c416ba 100644
--- a/wsd/DocumentBroker.hpp
+++ b/wsd/DocumentBroker.hpp
@@ -35,6 

[Libreoffice-commits] online.git: wsd/DocumentBroker.cpp wsd/DocumentBroker.hpp

2017-01-01 Thread Ashod Nakashian
 wsd/DocumentBroker.cpp |   17 +++--
 wsd/DocumentBroker.hpp |   18 +-
 2 files changed, 16 insertions(+), 19 deletions(-)

New commits:
commit 28db46a59c1dd07ef1cbcc928f4de408e15bf0f3
Author: Ashod Nakashian 
Date:   Sun Jan 1 19:42:19 2017 -0500

wsd: always update the last save time to detect failures

When saving we need to differentiate between no-op
and failure. The lastSaveTime must always be updated
when saving didn't fail (i.e. no modification or saved).

Change-Id: I0e2455afac22c82f0b623f9441fbc0bca8a7cb83
Reviewed-on: https://gerrit.libreoffice.org/32629
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index dd15f06..a9a2dac 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -372,6 +372,7 @@ bool DocumentBroker::save(const std::string& sessionId, 
bool success, const std:
 if (!success && result == "unmodified")
 {
 LOG_DBG("Save skipped as document [" << _docKey << "] was not 
modified.");
+_lastSaveTime = std::chrono::steady_clock::now();
 _saveCV.notify_all();
 return true;
 }
@@ -395,6 +396,7 @@ bool DocumentBroker::save(const std::string& sessionId, 
bool success, const std:
 // Nothing to do.
 LOG_DBG("Skipping unnecessary saving to URI [" << uri << "] with 
docKey [" << _docKey <<
 "]. File last modified " << _lastFileModifiedTime.elapsed() / 
100 << " seconds ago.");
+_lastSaveTime = std::chrono::steady_clock::now();
 _saveCV.notify_all();
 return true;
 }
@@ -483,16 +485,11 @@ bool DocumentBroker::autoSave(const bool force, const 
size_t waitTimeoutMs, std:
 }
 else if (_isModified)
 {
-// Find the most recent activity.
-double inactivityTimeMs = std::numeric_limits::max();
-for (const auto& sessionIt : _sessions)
-{
-inactivityTimeMs = std::min(sessionIt.second->getInactivityMS(), 
inactivityTimeMs);
-}
-
-const auto timeSinceLastSaveMs = getTimeSinceLastSaveMs();
+const auto now = std::chrono::steady_clock::now();
+const auto inactivityTimeMs = 
std::chrono::duration_cast(now - 
_lastActivityTime).count();
+const auto timeSinceLastSaveMs = 
std::chrono::duration_cast(now - 
_lastSaveTime).count();
 LOG_TRC("Time since last save of docKey [" << _docKey << "] is " << 
timeSinceLastSaveMs <<
-" ms and most recent activity was " << inactivityTimeMs << "ms 
ago.");
+"ms and most recent activity was " << inactivityTimeMs << "ms 
ago.");
 
 // Either we've been idle long enough, or it's auto-save time.
 if (inactivityTimeMs >= IdleSaveDurationMs ||
@@ -1089,7 +1086,7 @@ void DocumentBroker::closeDocument(const std::string& 
reason)
 
 void DocumentBroker::updateLastActivityTime()
 {
-_lastActivity = std::chrono::steady_clock::now();
+_lastActivityTime = std::chrono::steady_clock::now();
 Admin::instance().updateLastActivityTime(_docKey);
 }
 
diff --git a/wsd/DocumentBroker.hpp b/wsd/DocumentBroker.hpp
index 54eb3be..0c2457a 100644
--- a/wsd/DocumentBroker.hpp
+++ b/wsd/DocumentBroker.hpp
@@ -226,13 +226,6 @@ public:
 return _sessions.size();
 }
 
-/// @eturn the time in milliseconds since last save.
-double getTimeSinceLastSaveMs() const
-{
-const auto duration = (std::chrono::steady_clock::now() - 
_lastSaveTime);
-return 
std::chrono::duration_cast(duration).count();
-}
-
 std::string getJailRoot() const;
 
 /// Add a new session. Returns the new number of sessions.
@@ -303,7 +296,7 @@ public:
 
 std::size_t getIdleTimeSecs() const
 {
-const auto duration = (std::chrono::steady_clock::now() - 
_lastActivity);
+const auto duration = (std::chrono::steady_clock::now() - 
_lastActivityTime);
 return 
std::chrono::duration_cast(duration).count();
 }
 
@@ -326,8 +319,15 @@ private:
 Poco::URI _uriJailed;
 std::string _jailId;
 std::string _filename;
+
+/// The last time we tried saving, regardless of whether the
+/// document was modified and saved or not.
 std::chrono::steady_clock::time_point _lastSaveTime;
+
+/// The document's last-modified time on storage.
 Poco::Timestamp _documentLastModifiedTime;
+
+/// The jailed file last-modified time.
 Poco::Timestamp _lastFileModifiedTime;
 std::map _sessions;
 std::unique_ptr _storage;
@@ -350,7 +350,7 @@ private:
 
 int _debugRenderedTileCount;
 
-std::chrono::steady_clock::time_point _lastActivity;
+std::chrono::steady_clock::time_point _lastActivityTime;
 
 static constexpr auto IdleSaveDurationMs = 30 * 1000;
 static constexpr auto AutoSaveDurationMs = 300 * 1000;

[Libreoffice-commits] online.git: wsd/DocumentBroker.cpp wsd/DocumentBroker.hpp wsd/LOOLWSD.cpp

2017-01-01 Thread Ashod Nakashian
 wsd/DocumentBroker.cpp |2 +-
 wsd/DocumentBroker.hpp |8 ++--
 wsd/LOOLWSD.cpp|   10 ++
 3 files changed, 13 insertions(+), 7 deletions(-)

New commits:
commit 65d2036d63fa9304b1c8a88f18f946ba02bb1001
Author: Ashod Nakashian 
Date:   Sun Jan 1 18:16:56 2017 -0500

wsd: use chrono instead of time_t

While time_t is much simpler, it's too
opaque. The new chrono library is type-safe
and does conversion correctly, as well as
guarantees monotonity and other desirable
properties.

Change-Id: Id41c44c397a31d73e894e8f1715ff18f2b67df53
Reviewed-on: https://gerrit.libreoffice.org/32627
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index af13b73..dd15f06 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -1089,7 +1089,7 @@ void DocumentBroker::closeDocument(const std::string& 
reason)
 
 void DocumentBroker::updateLastActivityTime()
 {
-_lastActivity = std::time(nullptr);
+_lastActivity = std::chrono::steady_clock::now();
 Admin::instance().updateLastActivityTime(_docKey);
 }
 
diff --git a/wsd/DocumentBroker.hpp b/wsd/DocumentBroker.hpp
index d913adc..54eb3be 100644
--- a/wsd/DocumentBroker.hpp
+++ b/wsd/DocumentBroker.hpp
@@ -301,7 +301,11 @@ public:
 
 void updateLastActivityTime();
 
-std::time_t getIdleTime() const { return std::time(nullptr) - 
_lastActivity; }
+std::size_t getIdleTimeSecs() const
+{
+const auto duration = (std::chrono::steady_clock::now() - 
_lastActivity);
+return 
std::chrono::duration_cast(duration).count();
+}
 
 private:
 /// Sends the .uno:Save command to LoKit.
@@ -346,7 +350,7 @@ private:
 
 int _debugRenderedTileCount;
 
-std::time_t _lastActivity;
+std::chrono::steady_clock::time_point _lastActivity;
 
 static constexpr auto IdleSaveDurationMs = 30 * 1000;
 static constexpr auto AutoSaveDurationMs = 300 * 1000;
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index 3a07668..0268407 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -274,7 +274,7 @@ bool cleanupDocBrokers()
 auto lock = docBroker->getLock();
 
 // Remove idle documents after 1 hour.
-const bool idle = (docBroker->getIdleTime() >= 3600);
+const bool idle = (docBroker->getIdleTimeSecs() >= 3600);
 
 // Cleanup used and dead entries.
 if (docBroker->isLoaded() &&
@@ -2086,11 +2086,12 @@ int LOOLWSD::main(const std::vector& 
/*args*/)
 LOG_INF("Starting master server listening on " << ClientPortNumber);
 srv.start();
 
+
 #if ENABLE_DEBUG
 time_t startTimeSpan = time(nullptr);
 #endif
 
-time_t last30SecCheck = time(nullptr);
+auto last30SecCheckTime = std::chrono::steady_clock::now();
 int status = 0;
 while (!TerminationFlag && !SigUtil::isShuttingDown())
 {
@@ -2173,7 +2174,8 @@ int LOOLWSD::main(const std::vector& 
/*args*/)
 // Nothing more to do this round.
 }
 else if (!std::getenv("LOOL_NO_AUTOSAVE") &&
- (time(nullptr) >= last30SecCheck + 30))
+ std::chrono::duration_cast
+(std::chrono::steady_clock::now() - 
last30SecCheckTime).count() >= 30)
 {
 try
 {
@@ -2190,7 +2192,7 @@ int LOOLWSD::main(const std::vector& 
/*args*/)
 LOG_ERR("Exception: " << exc.what());
 }
 
-last30SecCheck = time(nullptr);
+last30SecCheckTime = std::chrono::steady_clock::now();
 }
 else
 {
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits