[Libreoffice-commits] online.git: Branch 'distro/collabora/collabora-online-2-1' - 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 20:29:30 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 eec17f2189922c163a118f88935c870568b2f7e8
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/43073
Reviewed-by: pranavk <pranavk at collabora.co.uk>
Tested-by: pranavk <pranavk at collabora.co.uk>
diff --git a/common/Unit.hpp b/common/Unit.hpp
index 335a3c81..85139f8c 100644
--- a/common/Unit.hpp
+++ b/common/Unit.hpp
@@ -208,6 +208,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 e8cc862d..945e9f89 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -760,14 +760,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();
@@ -810,6 +810,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 1030237b..0bc29996 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);
/// Sends a message to all sessions
void broadcastMessage(const std::string& message);
diff --git a/wsd/Storage.cpp b/wsd/Storage.cpp
index dc2e6ac5..4d2ce0c5 100644
--- a/wsd/Storage.cpp
+++ b/wsd/Storage.cpp
@@ -685,6 +685,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 0d5a6cbb..12462b47 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());
}
@@ -98,6 +99,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; }
@@ -136,6 +140,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 0df894d6..c7a4d721 100644
--- a/wsd/reference.txt
+++ b/wsd/reference.txt
@@ -73,3 +73,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