Simplify Document creation, and coupling to KitWebSocket.

Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
Change-Id: Iec7dfd3d33de2ae548ca73081d50361958672e4a
pull/8880/head
Michael Meeks 2024-04-25 12:59:24 +01:00 committed by Miklos Vajna
parent 7a75153290
commit 08e17a0388
5 changed files with 19 additions and 25 deletions

View File

@ -689,7 +689,6 @@ Document::Document(const std::shared_ptr<lok::Office>& loKit,
const std::string& docKey,
const std::string& docId,
const std::string& url,
std::shared_ptr<TileQueue> tileQueue,
const std::shared_ptr<WebSocketHandler>& websocketHandler,
unsigned mobileAppDocId)
: _loKit(loKit),
@ -698,7 +697,7 @@ Document::Document(const std::shared_ptr<lok::Office>& loKit,
_docId(docId),
_url(url),
_obfuscatedFileId(Util::getFilenameFromURL(docKey)),
_tileQueue(std::move(tileQueue)),
_tileQueue(std::make_shared<TileQueue>()),
_websocketHandler(websocketHandler),
_isBgSaveProcess(false),
_haveDocPassword(false),
@ -1082,7 +1081,7 @@ void Document::trimAfterInactivity()
assert(descriptor && "Null callback data.");
assert(descriptor->getDoc() && "Null Document instance.");
std::shared_ptr<TileQueue> tileQueue = descriptor->getDoc()->getTileQueue();
std::shared_ptr<TileQueue> tileQueue = descriptor->getDoc()->_tileQueue;
assert(tileQueue && "Null TileQueue.");
const std::string payload = p ? p : "(nil)";

View File

@ -50,6 +50,7 @@ bool globalPreinit(const std::string& loTemplate);
/// Wrapper around private Document::ViewCallback().
void documentViewCallback(const int type, const char* p, void* data);
class Document;
class DeltaGenerator;
class DocumentManagerInterface;
@ -57,18 +58,15 @@ class DocumentManagerInterface;
/// callback to a specific view.
struct CallbackDescriptor
{
CallbackDescriptor(DocumentManagerInterface* const doc, const int viewId)
: _doc(doc)
, _viewId(viewId)
CallbackDescriptor(Document* const doc, const int viewId)
: _doc(doc), _viewId(viewId)
{
}
DocumentManagerInterface* getDoc() const { return _doc; }
Document* getDoc() const { return _doc; }
int getViewId() const { return _viewId; }
private:
DocumentManagerInterface* const _doc;
Document* const _doc;
const int _viewId;
};
@ -215,8 +213,6 @@ public:
virtual std::string getObfuscatedFileId() = 0;
virtual std::shared_ptr<TileQueue>& getTileQueue() = 0;
virtual bool sendFrame(const char* buffer, int length, WSOpCode opCode = WSOpCode::Text) = 0;
virtual void alertAllUsers(const std::string& cmd, const std::string& kind) = 0;
@ -256,7 +252,6 @@ class Document final : public DocumentManagerInterface,
public:
Document(const std::shared_ptr<lok::Office>& loKit, const std::string& jailId,
const std::string& docKey, const std::string& docId, const std::string& url,
std::shared_ptr<TileQueue> tileQueue,
const std::shared_ptr<WebSocketHandler>& websocketHandler, unsigned mobileAppDocId);
virtual ~Document();
@ -325,8 +320,6 @@ private:
std::map<int, UserInfo> getViewInfo() override { return _sessionUserInfo; }
std::shared_ptr<TileQueue>& getTileQueue() override { return _tileQueue; }
int getEditorId() const override { return _editorId; }
bool isDocPasswordProtected() const override { return _isDocPasswordProtected; }
@ -375,6 +368,9 @@ private:
public:
bool processInputEnabled() const;
/// A new message from wsd for the queue
void queueMessage(const std::string &msg) { _tileQueue->put(msg); }
bool hasQueueItems() const { return _tileQueue && !_tileQueue->isEmpty(); }
// poll is idle, are we ?

View File

@ -77,7 +77,7 @@ void KitWebSocketHandler::handleMessage(const std::vector<char>& data)
if (!_document)
{
_document = std::make_shared<Document>(
_loKit, _jailId, _docKey, docId, url, _queue,
_loKit, _jailId, _docKey, docId, url,
std::static_pointer_cast<WebSocketHandler>(shared_from_this()), _mobileAppDocId);
_ksPoll->setDocument(_document);
@ -129,7 +129,7 @@ void KitWebSocketHandler::handleMessage(const std::vector<char>& data)
{
if (_document)
{
_queue->put(message);
_document->queueMessage(message);
}
else
{

View File

@ -36,7 +36,6 @@ public:
const std::string& jailId, std::shared_ptr<KitSocketPoll> ksPoll,
unsigned mobileAppDocId)
: WebSocketHandler(/* isClient = */ true, /* isMasking */ false)
, _queue(std::make_shared<TileQueue>())
, _socketName(socketName)
, _loKit(loKit)
, _jailId(jailId)

View File

@ -553,8 +553,9 @@ void WhiteBoxTests::testRegexListMatcher_Init()
LOK_ASSERT(matcher.match("192.168.."));
}
#if 0
/// A stub DocumentManagerInterface implementation for unit test purposes.
class DummyDocument : public DocumentManagerInterface
class DummyDocument : public Document
{
std::shared_ptr<TileQueue> _tileQueue;
std::mutex _mutex;
@ -614,11 +615,6 @@ public:
return std::string();
}
std::shared_ptr<TileQueue>& getTileQueue() override
{
return _tileQueue;
}
bool sendFrame(const char* /*buffer*/, int /*length*/, WSOpCode /*opCode*/) override
{
return true;
@ -675,13 +671,17 @@ public:
{
}
};
#endif
void WhiteBoxTests::testEmptyCellCursor()
{
DummyDocument document;
#if 0
auto office = std::make_shared<lok::Office>();
Document document(office, "", "", "", "", nullptr, 42);
CallbackDescriptor callbackDescriptor{&document, 0};
// This failed as stoi raised an std::invalid_argument exception.
documentViewCallback(LOK_CALLBACK_CELL_CURSOR, "EMPTY", &callbackDescriptor);
#endif
}
void WhiteBoxTests::testTileDesc()