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

Ashod Nakashian ashod.nakashian at collabora.co.uk
Sat Mar 26 17:03:17 UTC 2016


 loolwsd/DocumentBroker.cpp |   21 ++++++++++++++++++++-
 loolwsd/DocumentBroker.hpp |    1 +
 loolwsd/LOOLWSD.cpp        |    1 -
 loolwsd/TileCache.cpp      |   29 +++++++++++++++--------------
 loolwsd/TileCache.hpp      |    9 +++++++--
 5 files changed, 43 insertions(+), 18 deletions(-)

New commits:
commit 8b34e75722d4ca3a15d88322cebcd40dde45e5b2
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Sat Mar 26 07:50:13 2016 -0400

    loolwsd: cache directory path moved to DocumentBroker
    
    Change-Id: Ic7733bf4f35243afeb34d0ac2d85b619b8f49457
    Reviewed-on: https://gerrit.libreoffice.org/23533
    Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
    Tested-by: Ashod Nakashian <ashnakash at gmail.com>

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index d5af7f6..82dc71f 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -8,11 +8,29 @@
  */
 
 #include <Poco/Path.h>
+#include <Poco/SHA1Engine.h>
 
+#include "LOOLWSD.hpp"
 #include "DocumentBroker.hpp"
 #include "Storage.hpp"
 #include "TileCache.hpp"
 
+namespace
+{
+
+/// Returns the cache path for a given document URI.
+std::string getCachePath(const std::string& uri)
+{
+    Poco::SHA1Engine digestEngine;
+
+    digestEngine.update(uri.c_str(), uri.size());
+
+    return (LOOLWSD::Cache + "/" +
+            Poco::DigestEngine::digestToHex(digestEngine.digest()).insert(3, "/").insert(2, "/").insert(1, "/"));
+}
+
+}
+
 Poco::URI DocumentBroker::sanitizeURI(std::string uri)
 {
     // The URI of the document should be url-encoded.
@@ -48,6 +66,7 @@ DocumentBroker::DocumentBroker(const Poco::URI& uriPublic,
     _uriPublic(uriPublic),
     _docKey(docKey),
     _childRoot(childRoot),
+    _cacheRoot(getCachePath(uriPublic.toString())),
     _sessionsCount(0)
 {
     assert(!_docKey.empty());
@@ -86,7 +105,7 @@ bool DocumentBroker::load(const std::string& jailId)
     Log::info("jailPath: " + jailPath.toString() + ", jailRoot: " + jailRoot);
 
     const std::string timestamp = ""; //FIXME: Should come from load options.
-    _tileCache.reset(new TileCache(_uriPublic.toString(), timestamp));
+    _tileCache.reset(new TileCache(_uriPublic.toString(), timestamp, _cacheRoot));
 
     _storage = createStorage(jailRoot, jailPath.toString(), _uriPublic);
 
diff --git a/loolwsd/DocumentBroker.hpp b/loolwsd/DocumentBroker.hpp
index 8871e39..c2fa43b 100644
--- a/loolwsd/DocumentBroker.hpp
+++ b/loolwsd/DocumentBroker.hpp
@@ -72,6 +72,7 @@ private:
     const Poco::URI _uriPublic;
     const std::string _docKey;
     const std::string _childRoot;
+    const std::string _cacheRoot;
     Poco::URI _uriJailed;
     std::string _jailId;
     std::string _filename;
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index b0dcde6..bec5a1d 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -150,7 +150,6 @@ using Poco::Net::WebSocketException;
 using Poco::Path;
 using Poco::Process;
 using Poco::ProcessHandle;
-using Poco::Random;
 using Poco::Runnable;
 using Poco::StreamCopier;
 using Poco::StringTokenizer;
diff --git a/loolwsd/TileCache.cpp b/loolwsd/TileCache.cpp
index 120f985..5f2e70e 100644
--- a/loolwsd/TileCache.cpp
+++ b/loolwsd/TileCache.cpp
@@ -23,7 +23,6 @@
 #include <Poco/Exception.h>
 #include <Poco/File.h>
 #include <Poco/Path.h>
-#include <Poco/SHA1Engine.h>
 #include <Poco/StringTokenizer.h>
 #include <Poco/Timestamp.h>
 #include <Poco/URI.h>
@@ -37,7 +36,6 @@
 using Poco::DigestEngine;
 using Poco::DirectoryIterator;
 using Poco::File;
-using Poco::SHA1Engine;
 using Poco::StringTokenizer;
 using Poco::SyntaxException;
 using Poco::Timestamp;
@@ -45,14 +43,25 @@ using Poco::URI;
 
 using namespace LOOLProtocol;
 
-TileCache::TileCache(const std::string& docURL, const std::string& timestamp) :
+TileCache::TileCache(const std::string& docURL,
+                     const std::string& timestamp,
+                     const std::string& rootCacheDir) :
     _docURL(docURL),
+    _rootCacheDir(rootCacheDir),
+    _persCacheDir(Poco::Path(rootCacheDir, "persistent").toString()),
+    _editCacheDir(Poco::Path(rootCacheDir, "editing").toString()),
     _isEditing(false),
     _hasUnsavedChanges(false)
 {
+    Log::info("TileCache ctor.");
     setup(timestamp);
 }
 
+TileCache::~TileCache()
+{
+    Log::info("~TileCache dtor.");
+}
+
 std::unique_ptr<std::fstream> TileCache::lookupTile(int part, int width, int height, int tilePosX, int tilePosY, int tileWidth, int tileHeight)
 {
     std::string cachedName = cacheFileName(part, width, height, tilePosX, tilePosY, tileWidth, tileHeight);
@@ -290,20 +299,12 @@ void TileCache::removeFile(const std::string fileName)
 
 std::string TileCache::toplevelCacheDirName()
 {
-    SHA1Engine digestEngine;
-
-    digestEngine.update(_docURL.c_str(), _docURL.size());
-
-    return (LOOLWSD::Cache + "/" +
-            DigestEngine::digestToHex(digestEngine.digest()).insert(3, "/").insert(2, "/").insert(1, "/"));
+    return _rootCacheDir;
 }
 
-std::string TileCache::cacheDirName(bool useEditingCache)
+std::string TileCache::cacheDirName(const bool useEditingCache)
 {
-    if (useEditingCache)
-        return toplevelCacheDirName() + "/editing";
-    else
-        return toplevelCacheDirName() + "/persistent";
+    return (useEditingCache ? _editCacheDir : _persCacheDir);
 }
 
 std::string TileCache::cacheFileName(int part, int width, int height, int tilePosX, int tilePosY, int tileWidth, int tileHeight)
diff --git a/loolwsd/TileCache.hpp b/loolwsd/TileCache.hpp
index e5b3aad..8b08681 100644
--- a/loolwsd/TileCache.hpp
+++ b/loolwsd/TileCache.hpp
@@ -34,7 +34,8 @@ public:
     /// When the docURL is a non-file:// url, the timestamp has to be provided by the caller.
     /// For file:// url's, it's ignored.
     /// When it is missing for non-file:// url, it is assumed the document must be read, and no cached value used.
-    TileCache(const std::string& docURL, const std::string& timestamp);
+    TileCache(const std::string& docURL, const std::string& timestamp, const std::string& rootCacheDir);
+    ~TileCache();
 
     TileCache(const TileCache&) = delete;
 
@@ -88,7 +89,11 @@ private:
     /// For non-file:// protocols, the timestamp has to be provided externally.
     void setup(const std::string& timestamp);
 
-    const std::string& _docURL;
+private:
+    const std::string _docURL;
+    const std::string _rootCacheDir;
+    const std::string _persCacheDir;
+    const std::string _editCacheDir;
 
     /// The document is being edited.
     bool _isEditing;


More information about the Libreoffice-commits mailing list