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

2019-03-02 Thread Libreoffice Gerrit user
 wsd/ClientSession.cpp  |   35 ---
 wsd/ClientSession.hpp  |   13 -
 wsd/DocumentBroker.cpp |9 +++--
 wsd/TestStubs.cpp  |7 ---
 wsd/TileCache.cpp  |   28 +++-
 wsd/TileCache.hpp  |6 --
 6 files changed, 22 insertions(+), 76 deletions(-)

New commits:
commit 829e94b779afad5bc6192e54868ecbf17a61633f
Author: Michael Meeks 
AuthorDate: Sat Mar 2 19:26:08 2019 +0100
Commit: Michael Meeks 
CommitDate: Sat Mar 2 21:42:34 2019 +0100

TileCache: remove redundant, expensive tracking in ClientSession.

No need for all these call outs. removeOutdatedTileSubscriptions can't,

Expect it is quicker now and more reliable to trace the tiles being
rendered and count the waiters.

Change-Id: I9724c7f38cf888b35c628857c0f11b51e74613ca

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index c0a02b806..c3d5b9a83 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -1315,39 +1315,4 @@ void ClientSession::traceTileBySend(const TileDesc& 
tile, bool deduplicated)
 addTileOnFly(tile);
 }
 
-void ClientSession::traceSubscribeToTile(const std::string& cacheName)
-{
-_tilesBeingRendered.insert(cacheName);
-}
-
-void ClientSession::traceUnSubscribeToTile(const std::string& cacheName)
-{
-_tilesBeingRendered.erase(cacheName);
-}
-
-void ClientSession::removeOutdatedTileSubscriptions()
-{
-const std::shared_ptr docBroker = getDocumentBroker();
-if(!docBroker)
-return;
-
-auto iterator = _tilesBeingRendered.begin();
-while(iterator != _tilesBeingRendered.end())
-{
-double elapsedTime = 
docBroker->tileCache().getTileBeingRenderedElapsedTimeMs(*iterator);
-if(elapsedTime < 0.0 && elapsedTime > 200.0)
-{
-LOG_INF("Tracked TileBeingRendered was dropped because of time 
out.");
-_tilesBeingRendered.erase(iterator);
-}
-else
-++iterator;
-}
-}
-
-void ClientSession::clearTileSubscription()
-{
-_tilesBeingRendered.clear();
-}
-
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/wsd/ClientSession.hpp b/wsd/ClientSession.hpp
index 827a0f857..8db5b3718 100644
--- a/wsd/ClientSession.hpp
+++ b/wsd/ClientSession.hpp
@@ -21,7 +21,6 @@
 #include 
 #include 
 #include 
-#include 
 
 class DocumentBroker;
 
@@ -130,14 +129,6 @@ public:
 /// Call this method anytime when a new tile is sent to the client
 void traceTileBySend(const TileDesc& tile, bool deduplicated = false);
 
-/// Trask tiles what we a subscription to
-void traceSubscribeToTile(const std::string& tileCacheName);
-void traceUnSubscribeToTile(const std::string& tileCacheName);
-void removeOutdatedTileSubscriptions();
-void clearTileSubscription();
-
-size_t getTilesBeingRenderedCount() const {return 
_tilesBeingRendered.size();}
-
 /// Clear wireId map anytime when client visible area changes (visible 
area, zoom, part number)
 void resetWireIdMap();
 
@@ -227,10 +218,6 @@ private:
 /// TileID's of the sent tiles. Push by sending and pop by tileprocessed 
message from the client.
 std::list> 
_tilesOnFly;
 
-/// Names of tiles requested from kit, which this session is subsrcibed to
-/// Track only non-thumbnail tiles (getId() == -1)
-std::unordered_set _tilesBeingRendered;
-
 /// Requested tiles are stored in this list, before we can send them to 
the client
 std::deque _requestedTiles;
 
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 8f058bd2c..888500de8 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -1462,9 +1462,6 @@ void DocumentBroker::sendRequestedTiles(const 
std::shared_ptr& se
 tilesOnFlyUpperLimit = 200; // Have a big number here to get all tiles 
requested by file openning
 }
 
-
-// Update client's tilesBeingRendered list
-session->removeOutdatedTileSubscriptions();
 // Drop tiles which we are waiting for too long
 session->removeOutdatedTilesOnFly();
 
@@ -1475,7 +1472,8 @@ void DocumentBroker::sendRequestedTiles(const 
std::shared_ptr& se
 {
 size_t delayedTiles = 0;
 std::vector tilesNeedsRendering;
-while(session->getTilesOnFlyCount() + 
session->getTilesBeingRenderedCount() < tilesOnFlyUpperLimit &&
+size_t beingRendered = 
_tileCache->countTilesBeingRenderedForSession(session);
+while(session->getTilesOnFlyCount() + beingRendered < 
tilesOnFlyUpperLimit &&
   !requestedTiles.empty() &&
   // If we delayed all tiles we don't send any tile (we will when 
next tileprocessed message arrives)
   delayedTiles < requestedTiles.size())
@@ -1516,6 +1514,7 @@ void DocumentBroker::sendRequestedTiles(const 
std::shared_ptr& se
 _debugRenderedTileCount++;
 }
 tileCache().subscribeToTileRendering(tile, session);
+

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

2018-08-23 Thread Libreoffice Gerrit user
 wsd/ClientSession.cpp  |   26 --
 wsd/ClientSession.hpp  |4 +++-
 wsd/DocumentBroker.cpp |2 ++
 3 files changed, 25 insertions(+), 7 deletions(-)

New commits:
commit 759d1fe72294b22669f19dabf28a4fcf4922af8c
Author: Tamás Zolnai 
AuthorDate: Thu Aug 23 12:46:49 2018 +0200
Commit: Tamás Zolnai 
CommitDate: Thu Aug 23 12:47:52 2018 +0200

Drop too old tileID's from tiles-on-fly list

So we can avoid that tile sending stop working because server is
waiting for tileprocessed messages which will not arrive.

Change-Id: I545346c50d49340999608aadac32b5190ede43c5

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 4635bd57f..99ed308ea 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -52,7 +52,6 @@ ClientSession::ClientSession(const std::string& id,
 _tileWidthTwips(0),
 _tileHeightTwips(0),
 _isTextDocument(false),
-_tilesOnFly(0),
 _tilesBeingRendered(0)
 {
 const size_t curConnections = ++LOOLWSD::NumConnections;
@@ -343,10 +342,9 @@ bool ClientSession::_handleInput(const char *buffer, int 
length)
 sendTextFrame("error: cmd=tileprocessed kind=syntax");
 return false;
 }
-auto iter = std::find(_tilesOnFly.begin(), _tilesOnFly.end(), tileID);
-if(iter != _tilesOnFly.end())
-_tilesOnFly.erase(iter);
-else
+
+size_t retValue = _tilesOnFly.erase(tileID);
+if(retValue == 0)
 LOG_WRN("Tileprocessed message with an unknown tile ID");
 
 docBroker->sendRequestedTiles(shared_from_this());
@@ -1043,7 +1041,7 @@ Authorization ClientSession::getAuthorization() const
 
 void ClientSession::addTileOnFly(const TileDesc& tile)
 {
-_tilesOnFly.push_back(generateTileID(tile));
+_tilesOnFly.insert({generateTileID(tile), 
std::chrono::steady_clock::now()});
 }
 
 void ClientSession::clearTilesOnFly()
@@ -1051,6 +1049,19 @@ void ClientSession::clearTilesOnFly()
 _tilesOnFly.clear();
 }
 
+void ClientSession::removeOutdatedTilesOnFly()
+{
+for(auto tileIter = _tilesOnFly.begin(); tileIter != _tilesOnFly.begin(); 
++tileIter)
+{
+double elapsedTimeMs = 
std::chrono::duration_cast(std::chrono::steady_clock::now()
 - tileIter->second).count();
+if(elapsedTimeMs > 3000)
+{
+LOG_WRN("Tracker tileID was dropped because of time out. 
Tileprocessed message did not arrive");
+_tilesOnFly.erase(tileIter);
+}
+}
+}
+
 void ClientSession::onDisconnect()
 {
 LOG_INF(getName() << " Disconnected, current number of connections: " << 
LOOLWSD::NumConnections);
@@ -1245,7 +1256,10 @@ void ClientSession::removeOutdatedTileSubscriptions()
 {
 double elapsedTime = 
docBroker->tileCache().getTileBeingRenderedElapsedTimeMs(*iterator);
 if(elapsedTime < 0.0 && elapsedTime > 5000.0)
+{
+LOG_WRN("Tracked TileBeingRendered was dropped because of time 
out.");
 _tilesBeingRendered.erase(iterator);
+}
 else
 ++iterator;
 }
diff --git a/wsd/ClientSession.hpp b/wsd/ClientSession.hpp
index 7e7fef7ab..6f55494b2 100644
--- a/wsd/ClientSession.hpp
+++ b/wsd/ClientSession.hpp
@@ -19,6 +19,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 class DocumentBroker;
@@ -125,6 +126,7 @@ public:
 void addTileOnFly(const TileDesc& tile);
 void clearTilesOnFly();
 size_t getTilesOnFlyCount() const { return _tilesOnFly.size(); }
+void removeOutdatedTilesOnFly();
 
 Util::Rectangle getVisibleArea() const { return _clientVisibleArea; }
 int getTileWidthInTwips() const { return _tileWidthTwips; }
@@ -230,7 +232,7 @@ private:
 bool _isTextDocument;
 
 /// TileID's of the sent tiles. Push by sending and pop by tileprocessed 
message from the client.
-std::list _tilesOnFly;
+std::unordered_map 
_tilesOnFly;
 
 /// Names of tiles requested from kit, which this session is subsrcibed to
 /// Track only non-thumbnail tiles (getId() == -1)
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index b01d0753b..310eac031 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -1378,6 +1378,8 @@ void DocumentBroker::sendRequestedTiles(const 
std::shared_ptr& se
 
 // Update client's tilesBeingRendered list
 session->removeOutdatedTileSubscriptions();
+// Drop tiles which we are waiting for too long
+session->removeOutdatedTilesOnFly();
 
 // All tiles were processed on client side what we sent last time, so we 
can send a new banch of tiles
 // which was invalidated / requested in the meantime
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2018-08-20 Thread Libreoffice Gerrit user
 wsd/ClientSession.cpp  |5 -
 wsd/ClientSession.hpp  |2 --
 wsd/DocumentBroker.cpp |1 -
 wsd/SenderQueue.hpp|9 -
 4 files changed, 17 deletions(-)

New commits:
commit 7d98b5f01567af9625eaacbf25da671362a27c56
Author: Tamás Zolnai 
AuthorDate: Mon Aug 20 15:03:57 2018 +0200
Commit: Tamás Zolnai 
CommitDate: Mon Aug 20 15:13:59 2018 +0200

Revert "Get back "Cancel tiles also in wsd's senderqueue""

This reverts commit f1a385be98aba7191de79606d1cfdfa6973dfc39.

It's not easy, it can interfere the tile tracking.

Change-Id: I1e4ec9b4d66e5e912873f673fd5cb71ba55a9332
Reviewed-on: https://gerrit.libreoffice.org/59326
Reviewed-by: Tamás Zolnai 
Tested-by: Tamás Zolnai 

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 3f27a435c..90e099d38 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -1001,11 +1001,6 @@ bool ClientSession::handleKitToClientMessage(const char* 
buffer, const int lengt
 return forwardToClient(payload);
 }
 
-void ClientSession::cancelTilesInQueue()
-{
-_senderQueue.cancelTiles();
-}
-
 bool ClientSession::forwardToClient(const std::shared_ptr& payload)
 {
 if (isCloseFrame())
diff --git a/wsd/ClientSession.hpp b/wsd/ClientSession.hpp
index 4037d81a2..997058f68 100644
--- a/wsd/ClientSession.hpp
+++ b/wsd/ClientSession.hpp
@@ -99,8 +99,6 @@ public:
 }
 }
 
-void cancelTilesInQueue();
-
 /// Set the save-as socket which is used to send convert-to results.
 void setSaveAsSocket(const std::shared_ptr& socket)
 {
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index cf5c8eb84..be5c3aae4 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -1448,7 +1448,6 @@ void DocumentBroker::cancelTileRequests(const 
std::shared_ptr& se
 // Clear tile requests
 session->clearTilesOnFly();
 session->getRequestedTiles() = boost::none;
-session->cancelTilesInQueue();
 
 session->clearTileSubscription();
 
diff --git a/wsd/SenderQueue.hpp b/wsd/SenderQueue.hpp
index 927e3e735..fc3464b3f 100644
--- a/wsd/SenderQueue.hpp
+++ b/wsd/SenderQueue.hpp
@@ -84,15 +84,6 @@ public:
 }
 }
 
-void cancelTiles()
-{
-std::remove_if(_queue.begin(), _queue.end(),
-[](const queue_item_t& cur)
-{
-return cur->firstToken() == "tile:";
-});
-}
-
 private:
 /// Deduplicate messages based on the new one.
 /// Returns true if the new message should be
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2018-08-17 Thread Libreoffice Gerrit user
 wsd/ClientSession.cpp  |5 +
 wsd/ClientSession.hpp  |2 ++
 wsd/DocumentBroker.cpp |1 +
 wsd/SenderQueue.hpp|9 +
 4 files changed, 17 insertions(+)

New commits:
commit f1a385be98aba7191de79606d1cfdfa6973dfc39
Author: Tamás Zolnai 
AuthorDate: Fri Aug 17 23:36:47 2018 +0200
Commit: Tamás Zolnai 
CommitDate: Fri Aug 17 23:47:10 2018 +0200

Get back "Cancel tiles also in wsd's senderqueue"

This reverts commit ec8b7bc012503559841c96c5a16c13798c103387.

Change-Id: I0a4f3f529c86522261085d4feec45e4b56a7e0e6

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 90e099d38..3f27a435c 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -1001,6 +1001,11 @@ bool ClientSession::handleKitToClientMessage(const char* 
buffer, const int lengt
 return forwardToClient(payload);
 }
 
+void ClientSession::cancelTilesInQueue()
+{
+_senderQueue.cancelTiles();
+}
+
 bool ClientSession::forwardToClient(const std::shared_ptr& payload)
 {
 if (isCloseFrame())
diff --git a/wsd/ClientSession.hpp b/wsd/ClientSession.hpp
index 997058f68..4037d81a2 100644
--- a/wsd/ClientSession.hpp
+++ b/wsd/ClientSession.hpp
@@ -99,6 +99,8 @@ public:
 }
 }
 
+void cancelTilesInQueue();
+
 /// Set the save-as socket which is used to send convert-to results.
 void setSaveAsSocket(const std::shared_ptr& socket)
 {
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index be5c3aae4..cf5c8eb84 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -1448,6 +1448,7 @@ void DocumentBroker::cancelTileRequests(const 
std::shared_ptr& se
 // Clear tile requests
 session->clearTilesOnFly();
 session->getRequestedTiles() = boost::none;
+session->cancelTilesInQueue();
 
 session->clearTileSubscription();
 
diff --git a/wsd/SenderQueue.hpp b/wsd/SenderQueue.hpp
index fc3464b3f..927e3e735 100644
--- a/wsd/SenderQueue.hpp
+++ b/wsd/SenderQueue.hpp
@@ -84,6 +84,15 @@ public:
 }
 }
 
+void cancelTiles()
+{
+std::remove_if(_queue.begin(), _queue.end(),
+[](const queue_item_t& cur)
+{
+return cur->firstToken() == "tile:";
+});
+}
+
 private:
 /// Deduplicate messages based on the new one.
 /// Returns true if the new message should be
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2018-07-31 Thread Libreoffice Gerrit user
 wsd/ClientSession.cpp  |5 +
 wsd/ClientSession.hpp  |2 ++
 wsd/DocumentBroker.cpp |1 +
 wsd/SenderQueue.hpp|9 +
 wsd/TileCache.cpp  |5 +++--
 5 files changed, 20 insertions(+), 2 deletions(-)

New commits:
commit 0bb96131c495dfe1d98ebbfe01df5c4268d16de8
Author: Tamás Zolnai 
AuthorDate: Tue Jul 31 13:03:05 2018 +0200
Commit: Tamás Zolnai 
CommitDate: Tue Jul 31 13:18:44 2018 +0200

Cancel tiles also in wsd's senderqueue

Change-Id: I683b3cacee2f87d0dc0f28ad9ac3e122bcd043f1

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index b421d3304..886a3dcec 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -1040,6 +1040,11 @@ bool ClientSession::handleKitToClientMessage(const char* 
buffer, const int lengt
 return forwardToClient(payload);
 }
 
+void ClientSession::cancelTilesInQueue()
+{
+_senderQueue.cancelTiles();
+}
+
 bool ClientSession::forwardToClient(const std::shared_ptr& payload)
 {
 if (isCloseFrame())
diff --git a/wsd/ClientSession.hpp b/wsd/ClientSession.hpp
index fe565a672..8d434f44a 100644
--- a/wsd/ClientSession.hpp
+++ b/wsd/ClientSession.hpp
@@ -100,6 +100,8 @@ public:
 }
 }
 
+void cancelTilesInQueue();
+
 /// Set the save-as socket which is used to send convert-to results.
 void setSaveAsSocket(const std::shared_ptr& socket)
 {
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 84ad69a15..e6ead209a 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -1445,6 +1445,7 @@ void DocumentBroker::cancelTileRequests(const 
std::shared_ptr& se
 // Clear tile requests
 session->clearTilesOnFly();
 session->getRequestedTiles() = boost::none;
+session->cancelTilesInQueue();
 
 const std::string canceltiles = tileCache().cancelTiles(session);
 if (!canceltiles.empty())
diff --git a/wsd/SenderQueue.hpp b/wsd/SenderQueue.hpp
index fc3464b3f..927e3e735 100644
--- a/wsd/SenderQueue.hpp
+++ b/wsd/SenderQueue.hpp
@@ -84,6 +84,15 @@ public:
 }
 }
 
+void cancelTiles()
+{
+std::remove_if(_queue.begin(), _queue.end(),
+[](const queue_item_t& cur)
+{
+return cur->firstToken() == "tile:";
+});
+}
+
 private:
 /// Deduplicate messages based on the new one.
 /// Returns true if the new message should be
diff --git a/wsd/TileCache.cpp b/wsd/TileCache.cpp
index f80f64a1c..efa68e4ba 100644
--- a/wsd/TileCache.cpp
+++ b/wsd/TileCache.cpp
@@ -529,7 +529,7 @@ std::string TileCache::cancelTiles(const 
std::shared_ptr &subscri
 
 assertCorrectThread();
 
-const ClientSession* sub = subscriber.get();
+ClientSession* sub = subscriber.get();
 
 std::ostringstream oss;
 
@@ -564,7 +564,8 @@ std::string TileCache::cancelTiles(const 
std::shared_ptr &subscri
 ++it;
 }
 
-subscriber->clearSubscription();
+if(sub)
+sub->clearSubscription();
 const std::string canceltiles = oss.str();
 return canceltiles.empty() ? canceltiles : "canceltiles " + canceltiles;
 }
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2017-05-12 Thread Jan Holesovsky
 wsd/ClientSession.cpp  |   13 +
 wsd/ClientSession.hpp  |7 +
 wsd/DocumentBroker.cpp |   31 ++-
 wsd/Storage.cpp|   65 +
 wsd/Storage.hpp|   23 +
 5 files changed, 90 insertions(+), 49 deletions(-)

New commits:
commit 95e892168ce3b6e56ded62bb9ce2c02ada627dba
Author: Jan Holesovsky 
Date:   Fri May 12 17:42:03 2017 +0200

wsd: When connecting new sessions, always use the original URI...

...but in combination with the appropriate session's access_token to always
authenticate against the same instance of the WOPI host.

Change-Id: Ic94dfa8fcb226a2d134272b22edc1f8f76c24e34

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 55b17d64..5ef70522 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -726,6 +726,19 @@ bool ClientSession::forwardToClient(const 
std::shared_ptr& payload)
 return true;
 }
 
+std::string ClientSession::getAccessToken() const
+{
+std::string accessToken;
+Poco::URI::QueryParameters queryParams = _uriPublic.getQueryParameters();
+for (auto& param: queryParams)
+{
+if (param.first == "access_token")
+return param.second;
+}
+
+return std::string();
+}
+
 void ClientSession::onDisconnect()
 {
 LOG_INF(getName() << " Disconnected, current number of connections: " << 
LOOLWSD::NumConnections);
diff --git a/wsd/ClientSession.hpp b/wsd/ClientSession.hpp
index 22fad016..8c791c88 100644
--- a/wsd/ClientSession.hpp
+++ b/wsd/ClientSession.hpp
@@ -90,8 +90,15 @@ public:
 
 /// Exact URI (including query params - access tokens etc.) with which
 /// client made the request to us
+///
+/// Note: This URI is unsafe - when connecting to existing sessions, we 
must
+/// ignore everything but the access_token, and use the access_token with
+/// the URI of the initial request.
 const Poco::URI& getPublicUri() const { return _uriPublic; }
 
+/// The access token of this session.
+std::string getAccessToken() const;
+
 /// Set WOPI fileinfo object
 void setWopiFileInfo(std::unique_ptr& 
wopiFileInfo) { _wopiFileInfo = std::move(wopiFileInfo); }
 
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 21f6965f..bb7b9c5e 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -383,9 +383,6 @@ bool DocumentBroker::load(const 
std::shared_ptr& session, const s
 return false;
 }
 
-const Poco::URI& uriPublic = session->getPublicUri();
-LOG_DBG("Loading from URI: " << uriPublic.toString());
-
 _jailId = jailId;
 
 // The URL is the publicly visible one, not visible in the chroot jail.
@@ -402,7 +399,9 @@ bool DocumentBroker::load(const 
std::shared_ptr& session, const s
 {
 // Pass the public URI to storage as it needs to load using the token
 // and other storage-specific data provided in the URI.
-LOG_DBG("Creating new storage instance for URI [" << 
uriPublic.toString() << "].");
+const Poco::URI& uriPublic = session->getPublicUri();
+LOG_DBG("Loading, and creating new storage instance for URI [" << 
uriPublic.toString() << "].");
+
 _storage = StorageBase::create(uriPublic, jailRoot, 
jailPath.toString());
 if (_storage == nullptr)
 {
@@ -421,8 +420,7 @@ 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(uriPublic);
+std::unique_ptr wopifileinfo = 
wopiStorage->getWOPIFileInfo(session->getAccessToken());
 userid = wopifileinfo->_userid;
 username = wopifileinfo->_username;
 
@@ -473,8 +471,7 @@ bool DocumentBroker::load(const 
std::shared_ptr& session, const s
 LocalStorage* localStorage = 
dynamic_cast(_storage.get());
 if (localStorage != nullptr)
 {
-std::unique_ptr localfileinfo =
-  
localStorage->getLocalFileInfo(uriPublic);
+std::unique_ptr localfileinfo = 
localStorage->getLocalFileInfo();
 userid = localfileinfo->_userid;
 username = localfileinfo->_username;
 }
@@ -488,7 +485,7 @@ bool DocumentBroker::load(const 
std::shared_ptr& session, const s
 const auto fileInfo = _storage->getFileInfo();
 if (!fileInfo.isValid())
 {
-LOG_ERR("Invalid fileinfo for URI [" << uriPublic.toString() << "].");
+LOG_ERR("Invalid fileinfo for URI [" << 
session->getPublicUri().toString() << "].");
 return false;
 }
 
@@ -509,7 +506,7 @@ bool DocumentBroker::load(const 
std::shared_ptr& session, const s
 fileInfo._modifiedTime != Zero &&
 _documentLastModifiedTime != fileInfo._modifiedTime)
 {
-LOG

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

2017-04-20 Thread Ashod Nakashian
 wsd/ClientSession.cpp  |4 ++--
 wsd/ClientSession.hpp  |6 +++---
 wsd/DocumentBroker.cpp |2 +-
 3 files changed, 6 insertions(+), 6 deletions(-)

New commits:
commit 7019ca8c257b6f4e4b91988243da12236c9de94a
Author: Ashod Nakashian 
Date:   Thu Apr 20 22:17:08 2017 -0400

wsd: ClientSession's isLoaded -> isViewLoaded

Not to confuse with the DocumentBroker isLoaded,
this is view-specific. Except for the first view,
which is identical to the document being loaded,
subsequent view loadings are independent from,
though follow, document loading.

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

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 8be60603..11db33af 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -38,7 +38,7 @@ ClientSession::ClientSession(const std::string& id,
 _uriPublic(uriPublic),
 _isDocumentOwner(false),
 _isAttached(false),
-_isLoaded(false)
+_isViewLoaded(false)
 {
 const size_t curConnections = ++LOOLWSD::NumConnections;
 LOG_INF("ClientSession ctor [" << getName() << "], current number of 
connections: " << curConnections);
@@ -632,7 +632,7 @@ bool ClientSession::handleKitToClientMessage(const char* 
buffer, const int lengt
 }
 else if (tokens[0] == "status:")
 {
-setLoaded();
+setViewLoaded();
 docBroker->setLoaded();
 
 // Forward the status response to the client.
diff --git a/wsd/ClientSession.hpp b/wsd/ClientSession.hpp
index 81c55c70..b0eefecf 100644
--- a/wsd/ClientSession.hpp
+++ b/wsd/ClientSession.hpp
@@ -39,8 +39,8 @@ public:
 void setAttached() { _isAttached = true; }
 
 /// Returns true if this session has loaded a view (i.e. we got status 
message).
-bool isLoaded() const { return _isLoaded; }
-void setLoaded() { _isLoaded = true; }
+bool isViewLoaded() const { return _isViewLoaded; }
+void setViewLoaded() { _isViewLoaded = true; }
 
 const std::string getUserId() const { return _userId; }
 const std::string getUserName() const {return _userName; }
@@ -148,7 +148,7 @@ private:
 bool _isAttached;
 
 /// If we have loaded a view.
-bool _isLoaded;
+bool _isViewLoaded;
 
 /// Wopi FileInfo object
 std::unique_ptr _wopiFileInfo;
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index fd3a6ea9..a2b90d50 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -1216,7 +1216,7 @@ void DocumentBroker::destroyIfLastEditor(const 
std::string& id)
 for (const auto& it : _sessions)
 {
 if (it.second->getId() != id &&
-it.second->isLoaded() &&
+it.second->isViewLoaded() &&
 !it.second->isReadOnly())
 {
 // Found another editable.
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2017-04-19 Thread Ashod Nakashian
 wsd/ClientSession.cpp  |4 +++-
 wsd/ClientSession.hpp  |   10 +-
 wsd/DocumentBroker.cpp |1 +
 3 files changed, 13 insertions(+), 2 deletions(-)

New commits:
commit f326a058d41f6a0cc334f8458d98ca68cc40f189
Author: Ashod Nakashian 
Date:   Thu Apr 20 00:08:13 2017 -0400

wsd: rely only on loaded sessions for saving

If a session is not loaded, it might never
do so. We should skip them when deciding
whether to save using a disconnecting
session or rely on another.

This is to avoid failing to save when
the remaining sessions never really load
the document at all, and are therefore useless.

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

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 414f8b94..8be60603 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -37,7 +37,8 @@ ClientSession::ClientSession(const std::string& id,
 _docBroker(docBroker),
 _uriPublic(uriPublic),
 _isDocumentOwner(false),
-_isAttached(false)
+_isAttached(false),
+_isLoaded(false)
 {
 const size_t curConnections = ++LOOLWSD::NumConnections;
 LOG_INF("ClientSession ctor [" << getName() << "], current number of 
connections: " << curConnections);
@@ -631,6 +632,7 @@ bool ClientSession::handleKitToClientMessage(const char* 
buffer, const int lengt
 }
 else if (tokens[0] == "status:")
 {
+setLoaded();
 docBroker->setLoaded();
 
 // Forward the status response to the client.
diff --git a/wsd/ClientSession.hpp b/wsd/ClientSession.hpp
index 396f45c9..81c55c70 100644
--- a/wsd/ClientSession.hpp
+++ b/wsd/ClientSession.hpp
@@ -34,10 +34,14 @@ public:
 
 void setReadOnly() override;
 
-/// Returns true if a document is loaded (i.e. we got status message).
+/// Returns true if this session is added to a DocBroker.
 bool isAttached() const { return _isAttached; }
 void setAttached() { _isAttached = true; }
 
+/// Returns true if this session has loaded a view (i.e. we got status 
message).
+bool isLoaded() const { return _isLoaded; }
+void setLoaded() { _isLoaded = true; }
+
 const std::string getUserId() const { return _userId; }
 const std::string getUserName() const {return _userName; }
 void setUserId(const std::string& userId) { _userId = userId; }
@@ -140,8 +144,12 @@ private:
 /// The socket to which the converted (saveas) doc is sent.
 std::shared_ptr _saveAsSocket;
 
+/// If we are added to a DocBroker.
 bool _isAttached;
 
+/// If we have loaded a view.
+bool _isLoaded;
+
 /// Wopi FileInfo object
 std::unique_ptr _wopiFileInfo;
 
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 31ab6598..bb76ea33 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -1218,6 +1218,7 @@ void DocumentBroker::destroyIfLastEditor(const 
std::string& id)
 for (const auto& it : _sessions)
 {
 if (it.second->getId() != id &&
+it.second->isLoaded() &&
 !it.second->isReadOnly())
 {
 // Found another editable.
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

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

New commits:
commit d3a8106cda570fb8881139dc4347e02247036664
Author: Ashod Nakashian 
Date:   Sat Mar 25 14:19:17 2017 -0400

wsd: remove NewSessions

Sessions are now added to the DocBroker
_sessions map and loaded from the poll
thread first before processing their
messages.

Since messages are not read from the
sockets outside of the poll thread,
there is no reason to queue them
at all. The only exception is when
messages are passed directly
to ClientSession during convert-to
requests. That will be handled
separately (for now convert-to test
fails).

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

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 73e4cb5b..fbc50b98 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -38,6 +38,7 @@ ClientSession::ClientSession(const std::string& id,
 _uriPublic(uriPublic),
 _isReadOnly(readOnly),
 _isDocumentOwner(false),
+_isLoaded(false),
 _stop(false)
 {
 const size_t curConnections = ++LOOLWSD::NumConnections;
@@ -632,7 +633,6 @@ bool ClientSession::handleKitToClientMessage(const char* 
buffer, const int lengt
 }
 else if (tokens[0] == "status:")
 {
-_isLoaded = true;
 docBroker->setLoaded();
 
 // Forward the status response to the client.
diff --git a/wsd/ClientSession.hpp b/wsd/ClientSession.hpp
index 19aee2af..c027f4b3 100644
--- a/wsd/ClientSession.hpp
+++ b/wsd/ClientSession.hpp
@@ -37,6 +37,7 @@ public:
 
 /// Returns true if a document is loaded (i.e. we got status message).
 bool isLoaded() const { return _isLoaded; }
+void setLoaded() { _isLoaded = true; }
 
 const std::string getUserId() const { return _userId; }
 void setUserId(const std::string& userId) { _userId = userId; }
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index eb204b8d..fe0372e7 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -211,41 +211,20 @@ void DocumentBroker::pollThread()
 // Main polling loop goodness.
 while (!_stop && !TerminationFlag && !ShutdownRequestFlag)
 {
-while (true)
+// First, load new sessions.
+for (const auto& pair : _sessions)
 {
-std::unique_lock lock(_mutex);
-if (_newSessions.empty())
-break;
-
-NewSession& newSession = _newSessions.front();
 try
 {
-addSession(newSession._session);
-
-// now send the queued messages
-for (std::string message : newSession._messages)
-{
-// provide the jailed document path to the 'load' message
-assert(!_uriJailed.empty());
-std::vector tokens = 
LOOLProtocol::tokenize(message);
-if (tokens.size() > 1 && tokens[1] == "load")
-{
-// The json options must come last.
-message = tokens[0] + ' ' + tokens[1] + ' ' + 
tokens[2];
-message += " jail=" + _uriJailed.toString() + ' ';
-message += Poco::cat(std::string(" "), tokens.begin() 
+ 3, tokens.end());
-}
-
-LOG_DBG("Sending a queued message: " + message);
-_childProcess->sendTextFrame(message);
-}
+auto& session = pair.second;
+if (!session->isLoaded())
+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.
 }
-
-_newSessions.pop_front();
 }
 
 _poll->poll(SocketPoll::DefaultPollTimeoutMs);
@@ -740,10 +719,10 @@ size_t 
DocumentBroker::queueSession(std::shared_ptr& session)
 {
 Util::assertIsLocked(_mutex);
 
-_newSessions.push_back(NewSession(session));
+_sessions.emplace(session->getId(), session);
 _poll->wakeup();
 
-return _sessions.size() + _newSessions.size();
+return _sessions.size();
 }
 
 size_t DocumentBroker::addSession(const std::shared_ptr& 
session)
@@ -778,12 +757,9 @@ size_t DocumentBroker::addSession(const 
std::shared_ptr& session)
 _markToDestroy = false;
 _stop = false;
 
-const auto id = session->getId();
-if (!_sessions.emplace(id, session).second)
-{
-LOG_WRN("Docum

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

2017-03-16 Thread Ashod Nakashian
 wsd/ClientSession.cpp  |4 ++--
 wsd/ClientSession.hpp  |   30 +++---
 wsd/DocumentBroker.cpp |1 +
 wsd/LOOLWSD.cpp|   46 ++
 4 files changed, 20 insertions(+), 61 deletions(-)

New commits:
commit 5aedff24229bee65a5c0fd7154dce3f65e95567c
Author: Ashod Nakashian 
Date:   Thu Mar 16 22:42:02 2017 -0400

wsd: convert-to functional again

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

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 1f179ed4..268dc05c 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -414,7 +414,7 @@ bool ClientSession::filterMessage(const std::string& 
message) const
 {
 // By default, don't allow anything
 allowed = false;
-if (tokens[0] == "userinactive" || tokens[0] == "useractive")
+if (tokens[0] == "userinactive" || tokens[0] == "useractive" || 
tokens[0] == "saveas")
 {
 allowed = true;
 }
@@ -503,7 +503,7 @@ bool ClientSession::handleKitToClientMessage(const char* 
buffer, const int lengt
 const auto& object = parsedJSON.extract();
 if (object->get("commandName").toString() == ".uno:Save")
 {
-bool success = object->get("success").toString() == "true";
+const bool success = object->get("success").toString() == 
"true";
 std::string result;
 if (object->has("result"))
 {
diff --git a/wsd/ClientSession.hpp b/wsd/ClientSession.hpp
index c18e5cee..794ca06d 100644
--- a/wsd/ClientSession.hpp
+++ b/wsd/ClientSession.hpp
@@ -89,24 +89,24 @@ public:
 _senderQueue.stop();
 }
 
-/**
- * Return the URL of the saved-as document when it's ready. If called
- * before it's ready, the call blocks till then.
- */
-std::string getSaveAsUrl(const unsigned timeoutMs)
+void setSaveAsSocket(const std::shared_ptr& socket)
 {
-const auto payload = _saveAsQueue.get(timeoutMs);
-if (payload.empty())
-{
-throw std::runtime_error("Timed-out while getting save-as URL.");
-}
-
-return std::string(payload.data(), payload.size());
+_saveAsSocket = socket;
 }
 
 void setSaveAsUrl(const std::string& url)
 {
-_saveAsQueue.put(url);
+Poco::URI resultURL(url);
+LOG_TRC("Save-as URL: " << resultURL.toString());
+
+if (!resultURL.getPath().empty())
+{
+const std::string mimeType = "application/octet-stream";
+std::string encodedFilePath;
+Poco::URI::encode(resultURL.getPath(), "", encodedFilePath);
+LOG_TRC("Sending file: " << encodedFilePath);
+HttpHelper::sendFile(_saveAsSocket, encodedFilePath, mimeType);
+}
 }
 
 std::shared_ptr getDocumentBroker() const { return 
_docBroker.lock(); }
@@ -164,8 +164,8 @@ private:
 /// Whether this session is the owner of currently opened document
 bool _isDocumentOwner;
 
-/// Store URLs of completed 'save as' documents.
-MessageQueue _saveAsQueue;
+/// The socket to which the converted (saveas) doc is sent.
+std::shared_ptr _saveAsSocket;
 
 bool _isLoaded;
 
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index a4153ffb..e6ddb30c 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -478,6 +478,7 @@ bool DocumentBroker::load(std::shared_ptr& 
session, const std::st
 bool DocumentBroker::saveToStorage(const std::string& sessionId,
bool success, const std::string& result)
 {
+LOG_TRC("Saving to storage docKey [" << _docKey << "] for session [" << 
sessionId << "]: " << result);
 const bool res = saveToStorageInternal(sessionId, success, result);
 
 // If marked to destroy, then this was the last session.
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index fac23b22..a4e34062 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -1598,47 +1598,6 @@ private:
 void performWrites() override
 {
 LOG_ERR("performWrites");
-auto socket = _socket.lock();
-
-// Send it back to the client.
-try
-{
-Poco::URI 
resultURL(_clientSession->getSaveAsUrl(COMMAND_TIMEOUT_MS));
-LOG_TRC("Save-as URL: " << resultURL.toString());
-
-if (!resultURL.getPath().empty())
-{
-const std::string mimeType = "application/octet-stream";
-std::string encodedFilePath;
-URI::encode(resultURL.getPath(), "", encodedFilePath);
-LOG_TRC("Sending file: " << encodedFilePath);
-HttpHelper::sendFile(socket, encodedFilePath, mimeType);
-}
-}
-catch (const std::exception& ex)
- 

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

2017-01-22 Thread Ashod Nakashian
 wsd/ClientSession.cpp   |   21 ++---
 wsd/ClientSession.hpp   |7 +++
 wsd/DocumentBroker.cpp  |   13 +
 wsd/PrisonerSession.cpp |   31 ---
 wsd/PrisonerSession.hpp |   10 --
 5 files changed, 26 insertions(+), 56 deletions(-)

New commits:
commit 1f3d9ee457148fcc9eff3fbd3da66002010eb8bb
Author: Ashod Nakashian 
Date:   Sat Jan 21 20:31:22 2017 -0500

wsd: ClientSession now encapsulates PrisonerSession

No need to expose PrisonerSession via ClientSession
when the marshalling of messages can be done by
ClientSession directly.

PrisonerSession can now be removed altogether.

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

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 3bc76de..63ca129 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -43,6 +43,7 @@ ClientSession::ClientSession(const std::string& id,
 {
 LOG_INF("ClientSession ctor [" << getName() << "].");
 
+_peer = std::make_shared(*this, docBroker);
 _senderThread = std::thread([this]{ senderThread(); });
 }
 
@@ -62,21 +63,6 @@ bool ClientSession::isLoaded() const
 return _isLoadRequested && _peer && _peer->gotStatus();
 }
 
-void ClientSession::bridgePrisonerSession()
-{
-auto docBroker = getDocumentBroker();
-if (docBroker)
-{
-_peer = std::make_shared(shared_from_this(), 
docBroker);
-}
-else
-{
-const std::string msg = "No valid DocBroker while bridging Prisoner 
Session for " + getName();
-LOG_ERR(msg);
-throw std::runtime_error(msg);
-}
-}
-
 bool ClientSession::_handleInput(const char *buffer, int length)
 {
 LOG_TRC(getName() << ": handling [" << getAbbreviatedMessage(buffer, 
length) << "].");
@@ -495,4 +481,9 @@ void ClientSession::senderThread()
 LOG_DBG(getName() << " SenderThread finished");
 }
 
+bool ClientSession::handleKitToClientMessage(const char* data, const int size)
+{
+return _peer->handleInput(data, size);
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/wsd/ClientSession.hpp b/wsd/ClientSession.hpp
index 5d97d70..b6211a7 100644
--- a/wsd/ClientSession.hpp
+++ b/wsd/ClientSession.hpp
@@ -37,16 +37,15 @@ public:
 
 bool isLoaded() const;
 
-/// Create and connect Prisoner Session between DocumentBroker and us.
-void bridgePrisonerSession();
-std::shared_ptr getPeer() const { return _peer; }
-
 const std::string getUserId() const { return _userId; }
 void setUserId(const std::string& userId) { _userId = userId; }
 void setUserName(const std::string& userName) { _userName = userName; }
 void setDocumentOwner(const bool documentOwner) { _isDocumentOwner = 
documentOwner; }
 bool isDocumentOwner() const { return _isDocumentOwner; }
 
+/// Handle kit-to-client message.
+bool handleKitToClientMessage(const char* data, const int size);
+
 using Session::sendTextFrame;
 
 bool sendBinaryFrame(const char* buffer, int length) override
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 1d699a2..38d13c1 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -651,9 +651,6 @@ size_t 
DocumentBroker::addSession(std::shared_ptr& session)
 const std::string aMessage = "session " + id + ' ' + _docKey;
 _childProcess->sendTextFrame(aMessage);
 
-// Now we are ready to bridge between the kit and client.
-session->bridgePrisonerSession();
-
 // Tell the admin console about this new doc
 Admin::instance().addDoc(_docKey, getPid(), getFilename(), id);
 
@@ -1032,15 +1029,7 @@ bool DocumentBroker::forwardToClient(const std::string& 
prefix, const std::vecto
 const auto it = _sessions.find(sid);
 if (it != _sessions.end())
 {
-const auto peer = it->second->getPeer();
-if (peer)
-{
-return peer->handleInput(data, size);
-}
-else
-{
-LOG_WRN("Client session [" << sid << "] has no peer to forward 
message: " << message);
-}
+return it->second->handleKitToClientMessage(data, size);
 }
 else
 {
diff --git a/wsd/PrisonerSession.cpp b/wsd/PrisonerSession.cpp
index d05a9a6..9a2b0cf 100644
--- a/wsd/PrisonerSession.cpp
+++ b/wsd/PrisonerSession.cpp
@@ -32,9 +32,9 @@ using namespace LOOLProtocol;
 using Poco::Path;
 using Poco::StringTokenizer;
 
-PrisonerSession::PrisonerSession(std::shared_ptr clientSession,
+PrisonerSession::PrisonerSession(ClientSession& clientSession,
  std::shared_ptr docBroker) :
-Session("ToPrisoner-" + clientSession->getId(), clientSession->getId(), 
nullptr),
+Session("ToPrisoner-" + clientSession.getId(), clientSession.getId(), 
nullptr),
 _docBroke

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

2017-01-15 Thread Ashod Nakashian
 wsd/ClientSession.cpp   |   11 ++-
 wsd/ClientSession.hpp   |4 
 wsd/DocumentBroker.cpp  |1 +
 wsd/PrisonerSession.cpp |4 +++-
 wsd/PrisonerSession.hpp |4 
 5 files changed, 22 insertions(+), 2 deletions(-)

New commits:
commit 05620be4c5d0369d160ac79f4eaee00013229324
Author: Ashod Nakashian 
Date:   Wed Jan 11 16:45:14 2017 -0500

wsd: autosave on disconnecting based on loaded sessions only

When a client disconnects, we autosave only when there
are no other sessions. The idea being that it'd be
wasteful to save on every client disconnect, so long
that we have a later chance of saving.

This doesn't hold, however, when the only other
remaining session is one that had just connected
and hasn't loaded a view yet. WSD wouldn't
know about this, but when unloading the
disconnecting session, Kit will exit the process
as the last view is gone, losing all unsaved changes.

This patch tracks the sessions in WSD that have
loaded a view and takes that into account when
deciding to autosave on disconnect or not, thereby
fixing this corner case that may result in data loss.

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

diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 9715f32..f24a525 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -38,6 +38,7 @@ ClientSession::ClientSession(const std::string& id,
 _isReadOnly(readOnly),
 _isDocumentOwner(false),
 _loadPart(-1),
+_isLoadRequested(false),
 _stop(false)
 {
 LOG_INF("ClientSession ctor [" << getName() << "].");
@@ -57,7 +58,11 @@ ClientSession::~ClientSession()
 {
 _senderThread.join();
 }
+}
 
+bool ClientSession::isLoaded() const
+{
+return _isLoadRequested && _peer && _peer->gotStatus();
 }
 
 void ClientSession::bridgePrisonerSession()
@@ -279,7 +284,11 @@ bool ClientSession::loadDocument(const char* /*buffer*/, 
int /*length*/, StringT
 oss << " options=" << _docOptions;
 
 const auto loadRequest = oss.str();
-return forwardToChild(loadRequest, docBroker);
+if (forwardToChild(loadRequest, docBroker))
+{
+_isLoadRequested = true;
+return true;
+}
 }
 catch (const Poco::SyntaxException&)
 {
diff --git a/wsd/ClientSession.hpp b/wsd/ClientSession.hpp
index 7952029..c946a94 100644
--- a/wsd/ClientSession.hpp
+++ b/wsd/ClientSession.hpp
@@ -35,6 +35,8 @@ public:
 void setReadOnly();
 bool isReadOnly() const { return _isReadOnly; }
 
+bool isLoaded() const;
+
 /// Create and connect Prisoner Session between DocumentBroker and us.
 void bridgePrisonerSession();
 std::shared_ptr getPeer() const { return _peer; }
@@ -147,6 +149,8 @@ private:
 
 int _loadPart;
 
+bool _isLoadRequested;
+
 /// Wopi FileInfo object
 std::unique_ptr _wopiFileInfo;
 
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 7d7bfee..f1db30b 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -949,6 +949,7 @@ bool DocumentBroker::startDestroy(const std::string& id)
 for (const auto& it : _sessions)
 {
 if (it.second->getId() != id &&
+it.second->isLoaded() &&
 !it.second->isReadOnly())
 {
 // Found another editable.
diff --git a/wsd/PrisonerSession.cpp b/wsd/PrisonerSession.cpp
index 1848413..16cb760 100644
--- a/wsd/PrisonerSession.cpp
+++ b/wsd/PrisonerSession.cpp
@@ -37,7 +37,8 @@ 
PrisonerSession::PrisonerSession(std::shared_ptr clientSession,
 Session("ToPrisoner-" + clientSession->getId(), clientSession->getId(), 
nullptr),
 _docBroker(std::move(docBroker)),
 _peer(clientSession),
-_curPart(0)
+_curPart(0),
+_gotStatus(false)
 {
 LOG_INF("PrisonerSession ctor [" << getName() << "].");
 }
@@ -170,6 +171,7 @@ bool PrisonerSession::_handleInput(const char *buffer, int 
length)
 }
 else if (tokens[0] == "status:")
 {
+_gotStatus = true;
 _docBroker->setLoaded();
 
 // Forward the status response to the client.
diff --git a/wsd/PrisonerSession.hpp b/wsd/PrisonerSession.hpp
index 4085fb3..5a333a2 100644
--- a/wsd/PrisonerSession.hpp
+++ b/wsd/PrisonerSession.hpp
@@ -27,6 +27,9 @@ public:
 
 virtual ~PrisonerSession();
 
+/// Returns true if we've got status message.
+bool gotStatus() const { return _gotStatus; }
+
 private:
 /// Handle messages from the Kit to the client.
 virtual bool _handleInput(const char* buffer, int length) override;
@@ -38,6 +41,7 @@ private:
 std::shared_ptr _docBroker;
 std::weak_ptr _peer;
 int _curPart;
+bool _gotStatus;
 };
 
 #endif
___
Libreoffice-commit