853
854
if (priv->currentSize > webkit_download_get_total_size(download))
854
855
g_object_notify(G_OBJECT(download), "total-size");
856
gdouble lastProgress = webkit_download_get_progress(download);
858
857
// Throttle progress notification to not consume high amounts of
859
// CPU on fast links, except when the progress is >= 3%, or we
858
// CPU on fast links, except when the last notification occured
859
// in more then 0.7 secs from now, or the last notified progress
860
// is passed in 1% or we reached the end.
861
static gdouble lastProgress = 0;
861
862
static gdouble lastElapsed = 0;
862
863
gdouble currentElapsed = g_timer_elapsed(priv->timer, NULL);
864
gdouble currentProgress = webkit_download_get_progress(download);
865
&& (currentElapsed - lastElapsed) < 0.1
866
&& (webkit_download_get_progress(download) - lastProgress) < 0.03
867
&& webkit_download_get_progress(download) < 1.0) {
868
lastElapsed = currentElapsed;
868
&& (currentElapsed - lastElapsed) < 0.7
869
&& (currentProgress - lastProgress) < 0.01
870
&& currentProgress < 1.0) {
871
873
lastElapsed = currentElapsed;
874
lastProgress = currentProgress;
873
876
g_object_notify(G_OBJECT(download), "progress");
890
893
webkit_download_close_stream(download);
892
895
WebKitDownloadPrivate* priv = download->priv;
896
GRefPtr<WebKitDownload> protect(download);
894
898
g_timer_stop(priv->timer);
895
899
webkit_download_set_status(download, WEBKIT_DOWNLOAD_STATUS_ERROR);