[Libreoffice-commits] online.git: common/Unit.hpp test/UnitWOPI.cpp wsd/DocumentBroker.cpp wsd/DocumentBroker.hpp wsd/reference.txt wsd/Storage.cpp wsd/Storage.hpp
Jan Holesovsky
kendy at collabora.com
Tue Oct 3 10:04:36 UTC 2017
common/Unit.hpp | 6 ++++++
test/UnitWOPI.cpp | 16 ++++++++++++++++
wsd/DocumentBroker.cpp | 5 +++--
wsd/DocumentBroker.hpp | 2 +-
wsd/Storage.cpp | 1 +
wsd/Storage.hpp | 9 ++++++++-
wsd/reference.txt | 8 ++++++++
7 files changed, 43 insertions(+), 4 deletions(-)
New commits:
commit 7f49b1eba6402d3d06738e89f98110670e2b0743
Author: Jan Holesovsky <kendy at collabora.com>
Date: Tue Oct 3 11:59:39 2017 +0200
PutFile ext: X-LOOL-WOPI-IsAutosave header to indicate autosave + unit test.
Change-Id: I65ed711dae5100467fe6ed9902bd7bad8c7f8d68
Reviewed-on: https://gerrit.libreoffice.org/43074
Reviewed-by: Jan Holesovsky <kendy at collabora.com>
Tested-by: Jan Holesovsky <kendy at collabora.com>
diff --git a/common/Unit.hpp b/common/Unit.hpp
index f43b4d32..9885d073 100644
--- a/common/Unit.hpp
+++ b/common/Unit.hpp
@@ -214,6 +214,12 @@ public:
return false;
}
+ /// To force the save operation being handled as auto-save from a unit test.
+ virtual bool isAutosave()
+ {
+ return false;
+ }
+
// ---------------- WSD events ----------------
virtual void onChildConnected(const int /* pid */, const std::string& /* sessionId */) {}
/// When admin notify message is sent
diff --git a/test/UnitWOPI.cpp b/test/UnitWOPI.cpp
index 59f6282e..a8808d20 100644
--- a/test/UnitWOPI.cpp
+++ b/test/UnitWOPI.cpp
@@ -44,6 +44,12 @@ public:
{
}
+ bool isAutosave() override
+ {
+ // we fake autosave when saving the modified document
+ return _savingPhase == SavingPhase::Modified;
+ }
+
void assertCheckFileInfoRequest(const Poco::Net::HTTPRequest& /*request*/) override
{
// nothing to assert in CheckFileInfo
@@ -58,12 +64,22 @@ public:
{
if (_savingPhase == SavingPhase::Unmodified)
{
+ // the document is not modified
CPPUNIT_ASSERT_EQUAL(std::string("false"), request.get("X-LOOL-WOPI-IsModifiedByUser"));
+
+ // but the save action is an explicit user's request
+ CPPUNIT_ASSERT_EQUAL(std::string("false"), request.get("X-LOOL-WOPI-IsAutosave"));
+
_finishedSaveUnmodified = true;
}
else if (_savingPhase == SavingPhase::Modified)
{
+ // the document is modified
CPPUNIT_ASSERT_EQUAL(std::string("true"), request.get("X-LOOL-WOPI-IsModifiedByUser"));
+
+ // and this test fakes that it's an autosave
+ CPPUNIT_ASSERT_EQUAL(std::string("true"), request.get("X-LOOL-WOPI-IsAutosave"));
+
_finishedSaveModified = true;
}
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index ed76b2a6..6eff18bb 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -806,14 +806,14 @@ bool DocumentBroker::autoSave(const bool force)
timeSinceLastSaveMs >= autoSaveDurationMs)
{
LOG_TRC("Sending timed save command for [" << _docKey << "].");
- sent = sendUnoSave(savingSessionId);
+ sent = sendUnoSave(savingSessionId, /*dontTerminateEdit=*/ true, /*dontSaveIfUnmodified=*/ true, /*isAutosave=*/ true);
}
}
return sent;
}
-bool DocumentBroker::sendUnoSave(const std::string& sessionId, bool dontTerminateEdit, bool dontSaveIfUnmodified)
+bool DocumentBroker::sendUnoSave(const std::string& sessionId, bool dontTerminateEdit, bool dontSaveIfUnmodified, bool isAutosave)
{
assertCorrectThread();
@@ -856,6 +856,7 @@ bool DocumentBroker::sendUnoSave(const std::string& sessionId, bool dontTerminat
assert(_storage);
_storage->setUserModified(_isModified);
+ _storage->setIsAutosave(isAutosave || UnitWSD::get().isAutosave());
const auto saveArgs = oss.str();
LOG_TRC(".uno:Save arguments: " << saveArgs);
diff --git a/wsd/DocumentBroker.hpp b/wsd/DocumentBroker.hpp
index ecaaa30a..8756e0b5 100644
--- a/wsd/DocumentBroker.hpp
+++ b/wsd/DocumentBroker.hpp
@@ -337,7 +337,7 @@ public:
}
/// Sends the .uno:Save command to LoKit.
- bool sendUnoSave(const std::string& sessionId, bool dontTerminateEdit = true, bool dontSaveIfUnmodified = true);
+ bool sendUnoSave(const std::string& sessionId, bool dontTerminateEdit = true, bool dontSaveIfUnmodified = true, bool isAutosave = false);
/// Create copy of the file with a different name
void saveFileAs(const std::string& sessionId, const std::string& newFileName, const std::string& path);
diff --git a/wsd/Storage.cpp b/wsd/Storage.cpp
index 9003c75c..6a02649a 100644
--- a/wsd/Storage.cpp
+++ b/wsd/Storage.cpp
@@ -765,6 +765,7 @@ StorageBase::SaveResult WopiStorage::saveLocalFileToStorage(const Authorization&
Poco::DateTimeFormat::ISO8601_FRAC_FORMAT));
}
request.set("X-LOOL-WOPI-IsModifiedByUser", _isUserModified? "true": "false");
+ request.set("X-LOOL-WOPI-IsAutosave", _isAutosave? "true": "false");
request.setContentType("application/octet-stream");
request.setContentLength(size);
diff --git a/wsd/Storage.hpp b/wsd/Storage.hpp
index 31ab6c2f..6b3ce9af 100644
--- a/wsd/Storage.hpp
+++ b/wsd/Storage.hpp
@@ -79,7 +79,8 @@ public:
_fileInfo("", "lool", Poco::Timestamp::fromEpochTime(0), 0),
_isLoaded(false),
_forceSave(false),
- _isUserModified(false)
+ _isUserModified(false),
+ _isAutosave(false)
{
LOG_DBG("Storage ctor: " << uri.toString());
}
@@ -100,6 +101,9 @@ public:
/// To be able to set the WOPI extension header appropriately.
void setUserModified(bool isUserModified) { _isUserModified = isUserModified; }
+ /// To be able to set the WOPI 'is autosave?' header appropriately.
+ void setIsAutosave(bool isAutosave) { _isAutosave = isAutosave; }
+
/// Returns the basic information about the file.
const FileInfo& getFileInfo() const { return _fileInfo; }
@@ -138,6 +142,9 @@ protected:
/// The document has been modified by the user.
bool _isUserModified;
+ /// This save operation is an autosave.
+ bool _isAutosave;
+
static bool FilesystemEnabled;
static bool WopiEnabled;
/// Allowed/denied WOPI hosts, if any and if WOPI is enabled.
diff --git a/wsd/reference.txt b/wsd/reference.txt
index 90eedfc3..6c07d991 100644
--- a/wsd/reference.txt
+++ b/wsd/reference.txt
@@ -103,3 +103,11 @@ modification. The following header:
X-LOOL-WOPI-IsModifiedByUser
will have the value 'true' or 'false' accordingly.
+
+To distinguish autosave vs. explicit user requests to save, the following
+header:
+
+ X-LOOL-WOPI-IsAutosave
+
+will have the value 'true' when the PutFile is triggered by autosave, and
+'false' when triggered by explicit user operation (Save button or menu entry).
More information about the Libreoffice-commits
mailing list