Merge lp:~charlesk/indicator-transfer/lp-1378941-throttle-download-status-updates into lp:indicator-transfer/14.10

Proposed by Charles Kerr
Status: Merged
Approved by: Ted Gould
Approved revision: 23
Merged at revision: 24
Proposed branch: lp:~charlesk/indicator-transfer/lp-1378941-throttle-download-status-updates
Merge into: lp:indicator-transfer/14.10
Diff against target: 118 lines (+29/-9)
1 file modified
src/world-dbus.cpp (+29/-9)
To merge this branch: bzr merge lp:~charlesk/indicator-transfer/lp-1378941-throttle-download-status-updates
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Ted Gould (community) Approve
Review via email: mp+237683@code.launchpad.net

Commit message

Throttle how frequently a transfer item updates its action state and menuitem.

Description of the change

Throttle how frequently a transfer item updates its action state and menuitem.

This is currently necessary because ubuntu-download-manager sends out a *lot* of progress update signals. In my tests for the 7digital.com download, it was around ten per second. indicator-transfer passes this flood along to unity8 -- in fact it doubles it by cascading this progress change into menu changes AND action state changes.

This fix throttles back the update broadcasts to a maximum of once per second so that the flood of changes can be sent to unity8 in a batch.

Fix tested on mako + r274 + the armhf .debs in Elleo's mikeasoft.com link in-ticket.

See also bug #1379026 for the u-d-m bug report.

To post a comment you must log in.
23. By Charles Kerr

fix minor memory leak spotted while tracking down this bug

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Ted Gould (ted) wrote :

Looks good. Standard delay tactics.

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/world-dbus.cpp'
--- src/world-dbus.cpp 2014-08-26 20:51:10 +0000
+++ src/world-dbus.cpp 2014-10-08 20:41:48 +0000
@@ -72,6 +72,9 @@
7272
73 ~DBusTransfer()73 ~DBusTransfer()
74 {74 {
75 if (m_changed_tag)
76 g_source_remove(m_changed_tag);
77
75 g_cancellable_cancel(m_cancellable);78 g_cancellable_cancel(m_cancellable);
76 g_clear_object(&m_cancellable);79 g_clear_object(&m_cancellable);
77 g_clear_object(&m_bus);80 g_clear_object(&m_bus);
@@ -239,7 +242,19 @@
239 g_clear_pointer(&v, g_variant_unref);242 g_clear_pointer(&v, g_variant_unref);
240 }243 }
241244
242 void emit_changed() { changed()(); }245 void emit_changed_soon()
246 {
247 if (m_changed_tag == 0)
248 m_changed_tag = g_timeout_add_seconds(1, emit_changed_now, this);
249 }
250
251 static gboolean emit_changed_now(gpointer gself)
252 {
253 auto self = static_cast<DBusTransfer*>(gself);
254 self->m_changed_tag = 0;
255 self->m_changed();
256 return G_SOURCE_REMOVE;
257 }
243258
244 /* The 'started', 'paused', 'resumed', and 'canceled' signals259 /* The 'started', 'paused', 'resumed', and 'canceled' signals
245 from com.canonical.applications.Download all have a single260 from com.canonical.applications.Download all have a single
@@ -337,7 +352,7 @@
337 }352 }
338353
339 if (changed)354 if (changed)
340 emit_changed();355 emit_changed_soon();
341 }356 }
342357
343 void set_state(State state_in)358 void set_state(State state_in)
@@ -352,7 +367,7 @@
352 m_history.clear();367 m_history.clear();
353 }368 }
354 369
355 emit_changed();370 emit_changed_soon();
356 }371 }
357 }372 }
358373
@@ -363,7 +378,7 @@
363 {378 {
364 g_debug("changing '%s' error to '%s'", m_ccad_path.c_str(), tmp.c_str());379 g_debug("changing '%s' error to '%s'", m_ccad_path.c_str(), tmp.c_str());
365 error_string = tmp;380 error_string = tmp;
366 emit_changed();381 emit_changed_soon();
367 }382 }
368 }383 }
369384
@@ -374,7 +389,7 @@
374 {389 {
375 g_debug("changing '%s' path to '%s'", m_ccad_path.c_str(), tmp.c_str());390 g_debug("changing '%s' path to '%s'", m_ccad_path.c_str(), tmp.c_str());
376 local_path = tmp;391 local_path = tmp;
377 emit_changed();392 emit_changed_soon();
378 }393 }
379394
380 // If we don't already have a title,395 // If we don't already have a title,
@@ -394,7 +409,7 @@
394 {409 {
395 g_debug("changing '%s' title to '%s'", m_ccad_path.c_str(), tmp.c_str());410 g_debug("changing '%s' title to '%s'", m_ccad_path.c_str(), tmp.c_str());
396 title = tmp;411 title = tmp;
397 emit_changed();412 emit_changed_soon();
398 }413 }
399 }414 }
400415
@@ -460,7 +475,7 @@
460 {475 {
461 g_debug("changing '%s' icon to '%s'", m_ccad_path.c_str(), tmp.c_str());476 g_debug("changing '%s' icon to '%s'", m_ccad_path.c_str(), tmp.c_str());
462 app_icon = tmp;477 app_icon = tmp;
463 emit_changed();478 emit_changed_soon();
464 }479 }
465 }480 }
466481
@@ -589,6 +604,7 @@
589604
590 core::Signal<> m_changed;605 core::Signal<> m_changed;
591606
607 uint32_t m_changed_tag = 0;
592 uint64_t m_received = 0;608 uint64_t m_received = 0;
593 uint64_t m_total_size = 0;609 uint64_t m_total_size = 0;
594 struct DownloadProgress {610 struct DownloadProgress {
@@ -763,7 +779,9 @@
763 const gchar* signal_name,779 const gchar* signal_name,
764 GVariant* parameters)780 GVariant* parameters)
765 {781 {
766 g_debug("transfer signal: %s %s %s", cucdt_path, signal_name, g_variant_print(parameters, TRUE));782 gchar* variant_str = g_variant_print(parameters, TRUE);
783 g_debug("transfer signal: %s %s %s", cucdt_path, signal_name, variant_str);
784 g_free(variant_str);
767785
768 if (!g_strcmp0(signal_name, "DownloadIdChanged"))786 if (!g_strcmp0(signal_name, "DownloadIdChanged"))
769 {787 {
@@ -792,7 +810,9 @@
792 GVariant* parameters,810 GVariant* parameters,
793 gpointer gself)811 gpointer gself)
794 {812 {
795 g_debug("download signal: %s %s %s", ccad_path, signal_name, g_variant_print(parameters, TRUE));813 gchar* variant_str = g_variant_print(parameters, TRUE);
814 g_debug("download signal: %s %s %s", ccad_path, signal_name, variant_str);
815 g_free(variant_str);
796816
797 // Route this signal to the DBusTransfer for processing 817 // Route this signal to the DBusTransfer for processing
798 auto self = static_cast<Impl*>(gself);818 auto self = static_cast<Impl*>(gself);

Subscribers

People subscribed via source and target branches