summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAshod Nakashian <ashod.nakashian@collabora.co.uk>2022-04-02 17:21:09 -0400
committerMichael Meeks <michael.meeks@collabora.com>2022-04-22 17:23:34 +0100
commite3045b513c8743caddf93c74619a9813698c9301 (patch)
tree7339b6a4316e7561c37cbfb2b50c498a076a5f86
parentwsd: add canUploadToStorage helper (diff)
downloadonline-e3045b513c8743caddf93c74619a9813698c9301.tar.gz
online-e3045b513c8743caddf93c74619a9813698c9301.zip
wsd: add canSaveToDisk helper
Change-Id: I8ad6c91ac05d60e29726a20d67799aa11714226a Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
-rw-r--r--wsd/DocumentBroker.cpp13
-rw-r--r--wsd/DocumentBroker.hpp32
2 files changed, 40 insertions, 5 deletions
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 596a66e77c..e77ba63bc6 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -1833,16 +1833,18 @@ bool DocumentBroker::autoSave(const bool force, const bool dontSaveIfUnmodified)
LOG_TRC("autoSave(): forceful? " << force
<< ", dontSaveIfUnmodified: " << dontSaveIfUnmodified);
- if (_sessions.empty() || !isLoaded() || (!isModified() && !force))
+
+ const CanSave canSave = canSaveToDisk();
+ if (canSave != CanSave::Yes)
{
- // Nothing to do.
- LOG_TRC("Nothing to autosave [" << _docKey << "].");
+ LOG_DBG("Cannot save to disk: " << name(canSave));
return false;
}
- if (_docState.isDisconnected())
+ if (!isModified() && !force)
{
- LOG_DBG("Cannot autosave when disconnected from Kit.");
+ // Nothing to do.
+ LOG_TRC("Nothing to autosave [" << _docKey << "].");
return false;
}
@@ -3515,6 +3517,7 @@ void DocumentBroker::dumpState(std::ostream& os)
os << "\n thread start: " << Util::getTimeForLog(now, _threadStart);
os << "\n modified?: " << isModified();
os << "\n possibly-modified: " << isPossiblyModified();
+ os << "\n canSave: " << name(canSaveToDisk());
os << "\n canUpload: " << name(canUploadToStorage());
os << "\n needToUpload: " << name(needToUploadToStorage());
os << "\n haveActivityAfterSaveRequest: " << haveActivityAfterSaveRequest();
diff --git a/wsd/DocumentBroker.hpp b/wsd/DocumentBroker.hpp
index f27dac4d75..544ab2f25c 100644
--- a/wsd/DocumentBroker.hpp
+++ b/wsd/DocumentBroker.hpp
@@ -514,6 +514,38 @@ private:
/// with the child and cleans up ChildProcess etc.
void terminateChild(const std::string& closeReason);
+ /// Encodes whether or not saving is possible
+ /// (regardless of whether we need to or not).
+ STATE_ENUM(
+ CanSave,
+ Yes, //< Saving is possible.
+ NoKit, //< There is no Kit.
+ NotLoaded, //< No document is loaded.
+ NoWriteSession, //< No available session can write.
+ );
+
+ /// Returns the state of whether saving is possible.
+ /// (regardless of whether we need to or not).
+ CanSave canSaveToDisk() const
+ {
+ if (_docState.isDisconnected() || getPid() <= 0)
+ {
+ return CanSave::NoKit;
+ }
+
+ if (!isLoaded())
+ {
+ return CanSave::NotLoaded;
+ }
+
+ if (_sessions.empty() || getWriteableSessionId().empty())
+ {
+ return CanSave::NoWriteSession;
+ }
+
+ return CanSave::Yes;
+ }
+
/// Encodes whether or not uploading is possible.
/// (regardless of whether we need to or not).
STATE_ENUM(