mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 05:27:45 +00:00
Everywhere: Correctly report progress of downloads larger than 4GiB
This commit changes the variables used to represent the size and progress of downloads from u32 to u64. This allows `pro` and `Browser` to report the total size and progress of a download correctly for downloads larger than 4GiB.
This commit is contained in:
parent
c5e0547377
commit
1a17e08f87
18 changed files with 40 additions and 42 deletions
|
@ -56,7 +56,7 @@ void NetworkJob::did_fail(Error error)
|
|||
shutdown(ShutdownMode::DetachFromSocket);
|
||||
}
|
||||
|
||||
void NetworkJob::did_progress(Optional<u32> total_size, u32 downloaded)
|
||||
void NetworkJob::did_progress(Optional<u64> total_size, u64 downloaded)
|
||||
{
|
||||
if (is_cancelled())
|
||||
return;
|
||||
|
|
|
@ -29,7 +29,7 @@ public:
|
|||
// Could fire twice, after Headers and after Trailers!
|
||||
Function<void(HashMap<DeprecatedString, DeprecatedString, CaseInsensitiveStringTraits> const& response_headers, Optional<u32> response_code)> on_headers_received;
|
||||
Function<void(bool success)> on_finish;
|
||||
Function<void(Optional<u32>, u32)> on_progress;
|
||||
Function<void(Optional<u64>, u64)> on_progress;
|
||||
|
||||
bool is_cancelled() const { return m_error == Error::Cancelled; }
|
||||
bool has_error() const { return m_error != Error::None; }
|
||||
|
@ -55,7 +55,7 @@ protected:
|
|||
NetworkJob(Stream&);
|
||||
void did_finish(NonnullRefPtr<NetworkResponse>&&);
|
||||
void did_fail(Error);
|
||||
void did_progress(Optional<u32> total_size, u32 downloaded);
|
||||
void did_progress(Optional<u64> total_size, u64 downloaded);
|
||||
|
||||
ErrorOr<size_t> do_write(ReadonlyBytes bytes) { return m_output_stream.write_some(bytes); }
|
||||
|
||||
|
|
|
@ -380,7 +380,7 @@ void Job::on_socket_connected()
|
|||
dbgln_if(JOB_DEBUG, "Content-Encoding {} detected, cannot stream output :(", value);
|
||||
m_can_stream_response = false;
|
||||
} else if (name.equals_ignoring_ascii_case("Content-Length"sv)) {
|
||||
auto length = value.to_uint();
|
||||
auto length = value.to_uint<u64>();
|
||||
if (length.has_value())
|
||||
m_content_length = length.value();
|
||||
}
|
||||
|
|
|
@ -74,7 +74,7 @@ protected:
|
|||
|
||||
size_t m_buffered_size { 0 };
|
||||
size_t m_received_size { 0 };
|
||||
Optional<u32> m_content_length;
|
||||
Optional<u64> m_content_length;
|
||||
Optional<ssize_t> m_current_chunk_remaining_size;
|
||||
Optional<size_t> m_current_chunk_total_size;
|
||||
bool m_can_stream_response { true };
|
||||
|
|
|
@ -88,7 +88,7 @@ void Request::set_should_buffer_all_input(bool value)
|
|||
m_internal_buffered_data->response_code = move(response_code);
|
||||
};
|
||||
|
||||
on_finish = [this](auto success, u32 total_size) {
|
||||
on_finish = [this](auto success, auto total_size) {
|
||||
auto output_buffer = ByteBuffer::create_uninitialized(m_internal_buffered_data->payload_stream.used_buffer_size()).release_value_but_fixme_should_propagate_errors();
|
||||
m_internal_buffered_data->payload_stream.read_until_filled(output_buffer).release_value_but_fixme_should_propagate_errors();
|
||||
on_buffered_request_finish(
|
||||
|
@ -102,7 +102,7 @@ void Request::set_should_buffer_all_input(bool value)
|
|||
stream_into(m_internal_buffered_data->payload_stream);
|
||||
}
|
||||
|
||||
void Request::did_finish(Badge<RequestClient>, bool success, u32 total_size)
|
||||
void Request::did_finish(Badge<RequestClient>, bool success, u64 total_size)
|
||||
{
|
||||
if (!on_finish)
|
||||
return;
|
||||
|
@ -110,7 +110,7 @@ void Request::did_finish(Badge<RequestClient>, bool success, u32 total_size)
|
|||
on_finish(success, total_size);
|
||||
}
|
||||
|
||||
void Request::did_progress(Badge<RequestClient>, Optional<u32> total_size, u32 downloaded_size)
|
||||
void Request::did_progress(Badge<RequestClient>, Optional<u64> total_size, u64 downloaded_size)
|
||||
{
|
||||
if (on_progress)
|
||||
on_progress(total_size, downloaded_size);
|
||||
|
|
|
@ -43,14 +43,14 @@ public:
|
|||
void set_should_buffer_all_input(bool);
|
||||
|
||||
/// Note: Must be set before `set_should_buffer_all_input(true)`.
|
||||
Function<void(bool success, u32 total_size, HashMap<DeprecatedString, DeprecatedString, CaseInsensitiveStringTraits> const& response_headers, Optional<u32> response_code, ReadonlyBytes payload)> on_buffered_request_finish;
|
||||
Function<void(bool success, u32 total_size)> on_finish;
|
||||
Function<void(Optional<u32> total_size, u32 downloaded_size)> on_progress;
|
||||
Function<void(bool success, u64 total_size, HashMap<DeprecatedString, DeprecatedString, CaseInsensitiveStringTraits> const& response_headers, Optional<u32> response_code, ReadonlyBytes payload)> on_buffered_request_finish;
|
||||
Function<void(bool success, u64 total_size)> on_finish;
|
||||
Function<void(Optional<u64> total_size, u64 downloaded_size)> on_progress;
|
||||
Function<void(HashMap<DeprecatedString, DeprecatedString, CaseInsensitiveStringTraits> const& response_headers, Optional<u32> response_code)> on_headers_received;
|
||||
Function<CertificateAndKey()> on_certificate_requested;
|
||||
|
||||
void did_finish(Badge<RequestClient>, bool success, u32 total_size);
|
||||
void did_progress(Badge<RequestClient>, Optional<u32> total_size, u32 downloaded_size);
|
||||
void did_finish(Badge<RequestClient>, bool success, u64 total_size);
|
||||
void did_progress(Badge<RequestClient>, Optional<u64> total_size, u64 downloaded_size);
|
||||
void did_receive_headers(Badge<RequestClient>, HashMap<DeprecatedString, DeprecatedString, CaseInsensitiveStringTraits> const& response_headers, Optional<u32> response_code);
|
||||
void did_request_certificates(Badge<RequestClient>);
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ bool RequestClient::set_certificate(Badge<Request>, Request& request, Deprecated
|
|||
return IPCProxy::set_certificate(request.id(), move(certificate), move(key));
|
||||
}
|
||||
|
||||
void RequestClient::request_finished(i32 request_id, bool success, u32 total_size)
|
||||
void RequestClient::request_finished(i32 request_id, bool success, u64 total_size)
|
||||
{
|
||||
RefPtr<Request> request;
|
||||
if ((request = m_requests.get(request_id).value_or(nullptr))) {
|
||||
|
@ -63,7 +63,7 @@ void RequestClient::request_finished(i32 request_id, bool success, u32 total_siz
|
|||
m_requests.remove(request_id);
|
||||
}
|
||||
|
||||
void RequestClient::request_progress(i32 request_id, Optional<u32> const& total_size, u32 downloaded_size)
|
||||
void RequestClient::request_progress(i32 request_id, Optional<u64> const& total_size, u64 downloaded_size)
|
||||
{
|
||||
if (auto request = const_cast<Request*>(m_requests.get(request_id).value_or(nullptr))) {
|
||||
request->did_progress({}, total_size, downloaded_size);
|
||||
|
|
|
@ -32,8 +32,8 @@ public:
|
|||
private:
|
||||
RequestClient(NonnullOwnPtr<Core::LocalSocket>);
|
||||
|
||||
virtual void request_progress(i32, Optional<u32> const&, u32) override;
|
||||
virtual void request_finished(i32, bool, u32) override;
|
||||
virtual void request_progress(i32, Optional<u64> const&, u64) override;
|
||||
virtual void request_finished(i32, bool, u64) override;
|
||||
virtual void certificate_requested(i32) override;
|
||||
virtual void headers_became_available(i32, HashMap<DeprecatedString, DeprecatedString, CaseInsensitiveStringTraits> const&, Optional<u32> const&) override;
|
||||
|
||||
|
|
|
@ -65,9 +65,9 @@ public:
|
|||
|
||||
virtual void stream_into(Stream&) = 0;
|
||||
|
||||
Function<void(bool success, u32 total_size, HashMap<DeprecatedString, DeprecatedString, CaseInsensitiveStringTraits> const& response_headers, Optional<u32> response_code, ReadonlyBytes payload)> on_buffered_request_finish;
|
||||
Function<void(bool success, u32 total_size)> on_finish;
|
||||
Function<void(Optional<u32> total_size, u32 downloaded_size)> on_progress;
|
||||
Function<void(bool success, u64 total_size, HashMap<DeprecatedString, DeprecatedString, CaseInsensitiveStringTraits> const& response_headers, Optional<u32> response_code, ReadonlyBytes payload)> on_buffered_request_finish;
|
||||
Function<void(bool success, u64 total_size)> on_finish;
|
||||
Function<void(Optional<u64> total_size, u64 downloaded_size)> on_progress;
|
||||
Function<CertificateAndKey()> on_certificate_requested;
|
||||
|
||||
protected:
|
||||
|
|
|
@ -24,13 +24,13 @@ RequestServerRequestAdapter::RequestServerRequestAdapter(NonnullRefPtr<Protocol:
|
|||
strong_this->on_buffered_request_finish(success, total_size, response_headers, response_code, move(payload));
|
||||
};
|
||||
|
||||
request->on_finish = [weak_this = make_weak_ptr()](bool success, u32 total_size) {
|
||||
request->on_finish = [weak_this = make_weak_ptr()](bool success, u64 total_size) {
|
||||
if (auto strong_this = weak_this.strong_ref())
|
||||
if (strong_this->on_finish)
|
||||
strong_this->on_finish(success, total_size);
|
||||
};
|
||||
|
||||
request->on_progress = [weak_this = make_weak_ptr()](Optional<u32> total_size, u32 downloaded_size) {
|
||||
request->on_progress = [weak_this = make_weak_ptr()](Optional<u64> total_size, u64 downloaded_size) {
|
||||
if (auto strong_this = weak_this.strong_ref())
|
||||
if (strong_this->on_progress)
|
||||
strong_this->on_progress(total_size, downloaded_size);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue