ladybird/Servers/ProtocolServer/Download.h
Andreas Kling eb85103271 ProtocolServer: Send the download payload to clients as a shared buffer
The DownloadFinished message from the server now includes a buffer ID
that can be mapped into the client program.

To avoid prematurely destroying the buffer, the server will hang on to
it until the client lets it know that they're all good. That's what the
ProtocolServer::DisownSharedBuffer message is about.

In the future it would be nice if the kernel had a mechanism to allow
passing ownership of a shared buffer along with an IPC message somehow.
2019-11-23 22:11:44 +01:00

38 lines
882 B
C++

#pragma once
#include <AK/RefCounted.h>
#include <AK/URL.h>
#include <AK/WeakPtr.h>
class PSClientConnection;
class Download : public RefCounted<Download> {
public:
virtual ~Download();
static Download* find_by_id(i32);
i32 id() const { return m_id; }
URL url() const { return m_url; }
size_t total_size() const { return m_total_size; }
size_t downloaded_size() const { return m_downloaded_size; }
const ByteBuffer& payload() const { return m_payload; }
void stop();
protected:
explicit Download(PSClientConnection&);
void did_finish(bool success);
void did_progress(size_t total_size, size_t downloaded_size);
void set_payload(const ByteBuffer&);
private:
i32 m_id;
URL m_url;
size_t m_total_size { 0 };
size_t m_downloaded_size { 0 };
ByteBuffer m_payload;
WeakPtr<PSClientConnection> m_client;
};