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
1=== modified file 'src/world-dbus.cpp'
2--- src/world-dbus.cpp 2014-08-26 20:51:10 +0000
3+++ src/world-dbus.cpp 2014-10-08 20:41:48 +0000
4@@ -72,6 +72,9 @@
5
6 ~DBusTransfer()
7 {
8+ if (m_changed_tag)
9+ g_source_remove(m_changed_tag);
10+
11 g_cancellable_cancel(m_cancellable);
12 g_clear_object(&m_cancellable);
13 g_clear_object(&m_bus);
14@@ -239,7 +242,19 @@
15 g_clear_pointer(&v, g_variant_unref);
16 }
17
18- void emit_changed() { changed()(); }
19+ void emit_changed_soon()
20+ {
21+ if (m_changed_tag == 0)
22+ m_changed_tag = g_timeout_add_seconds(1, emit_changed_now, this);
23+ }
24+
25+ static gboolean emit_changed_now(gpointer gself)
26+ {
27+ auto self = static_cast<DBusTransfer*>(gself);
28+ self->m_changed_tag = 0;
29+ self->m_changed();
30+ return G_SOURCE_REMOVE;
31+ }
32
33 /* The 'started', 'paused', 'resumed', and 'canceled' signals
34 from com.canonical.applications.Download all have a single
35@@ -337,7 +352,7 @@
36 }
37
38 if (changed)
39- emit_changed();
40+ emit_changed_soon();
41 }
42
43 void set_state(State state_in)
44@@ -352,7 +367,7 @@
45 m_history.clear();
46 }
47
48- emit_changed();
49+ emit_changed_soon();
50 }
51 }
52
53@@ -363,7 +378,7 @@
54 {
55 g_debug("changing '%s' error to '%s'", m_ccad_path.c_str(), tmp.c_str());
56 error_string = tmp;
57- emit_changed();
58+ emit_changed_soon();
59 }
60 }
61
62@@ -374,7 +389,7 @@
63 {
64 g_debug("changing '%s' path to '%s'", m_ccad_path.c_str(), tmp.c_str());
65 local_path = tmp;
66- emit_changed();
67+ emit_changed_soon();
68 }
69
70 // If we don't already have a title,
71@@ -394,7 +409,7 @@
72 {
73 g_debug("changing '%s' title to '%s'", m_ccad_path.c_str(), tmp.c_str());
74 title = tmp;
75- emit_changed();
76+ emit_changed_soon();
77 }
78 }
79
80@@ -460,7 +475,7 @@
81 {
82 g_debug("changing '%s' icon to '%s'", m_ccad_path.c_str(), tmp.c_str());
83 app_icon = tmp;
84- emit_changed();
85+ emit_changed_soon();
86 }
87 }
88
89@@ -589,6 +604,7 @@
90
91 core::Signal<> m_changed;
92
93+ uint32_t m_changed_tag = 0;
94 uint64_t m_received = 0;
95 uint64_t m_total_size = 0;
96 struct DownloadProgress {
97@@ -763,7 +779,9 @@
98 const gchar* signal_name,
99 GVariant* parameters)
100 {
101- g_debug("transfer signal: %s %s %s", cucdt_path, signal_name, g_variant_print(parameters, TRUE));
102+ gchar* variant_str = g_variant_print(parameters, TRUE);
103+ g_debug("transfer signal: %s %s %s", cucdt_path, signal_name, variant_str);
104+ g_free(variant_str);
105
106 if (!g_strcmp0(signal_name, "DownloadIdChanged"))
107 {
108@@ -792,7 +810,9 @@
109 GVariant* parameters,
110 gpointer gself)
111 {
112- g_debug("download signal: %s %s %s", ccad_path, signal_name, g_variant_print(parameters, TRUE));
113+ gchar* variant_str = g_variant_print(parameters, TRUE);
114+ g_debug("download signal: %s %s %s", ccad_path, signal_name, variant_str);
115+ g_free(variant_str);
116
117 // Route this signal to the DBusTransfer for processing
118 auto self = static_cast<Impl*>(gself);

Subscribers

People subscribed via source and target branches