Merge lp:~indicator-applet-developers/hud/simplify-app-source-refcounting into lp:hud/13.10

Proposed by Pete Woods
Status: Merged
Approved by: Antti Kaijanmäki
Approved revision: 338
Merged at revision: 338
Proposed branch: lp:~indicator-applet-developers/hud/simplify-app-source-refcounting
Merge into: lp:hud/13.10
Diff against target: 167 lines (+39/-45)
2 files modified
src/application-list.c (+35/-44)
src/application-source.c (+4/-1)
To merge this branch: bzr merge lp:~indicator-applet-developers/hud/simplify-app-source-refcounting
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Needs Fixing
Antti Kaijanmäki (community) Approve
Indicator Applet Developers Pending
Review via email: mp+190986@code.launchpad.net

Commit message

Fix the ref counting of application sources

The application sources are now entirely owned by the application-list's hash table

Description of the change

Fix the ref counting of application sources

The application sources are now entirely owned by the application-list's hash table

To post a comment you must log in.
338. By Pete Woods

Fix a missing clear

Revision history for this message
Antti Kaijanmäki (kaijanmaki) wrote :

approved.

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/application-list.c'
2--- src/application-list.c 2013-10-11 15:58:52 +0000
3+++ src/application-list.c 2013-10-14 15:48:19 +0000
4@@ -229,11 +229,9 @@
5
6 if (self->priv->used_source != NULL) {
7 hud_source_unuse(self->priv->used_source);
8- g_clear_object(&self->priv->used_source);
9+ self->priv->used_source = NULL;
10 }
11
12- g_clear_object(&self->priv->last_focused_main_stage_source);
13-
14 if (self->priv->matcher_app_sig != 0 && self->priv->window_stack != NULL) {
15 g_signal_handler_disconnect(self->priv->window_stack, self->priv->matcher_app_sig);
16 }
17@@ -353,7 +351,7 @@
18 }
19
20 /* Clear the last source, as we've obviously changed */
21- g_clear_object(&list->priv->last_focused_main_stage_source);
22+ list->priv->last_focused_main_stage_source = NULL;
23
24 HudApplicationSource *source = application_info_to_source(list, window);
25
26@@ -383,7 +381,7 @@
27 return;
28 }
29
30- list->priv->last_focused_main_stage_source = g_object_ref(source);
31+ list->priv->last_focused_main_stage_source = source;
32
33 hud_application_source_focus(source, window, window);
34
35@@ -399,6 +397,7 @@
36 static void
37 view_opened (DBusWindowStack * window_stack, guint window_id, const gchar *app_id, gpointer user_data)
38 {
39+ g_debug("view_opened(%d, %s)", window_id, app_id);
40 HudApplicationList * list = HUD_APPLICATION_LIST(user_data);
41
42 HudWindowInfo *window = hud_window_info_new(list->priv->window_stack,
43@@ -421,44 +420,37 @@
44 static void
45 view_closed (DBusWindowStack * window_stack, guint window_id, const gchar *app_id, gpointer user_data)
46 {
47- g_debug("Closing Window: %d", window_id);
48+ g_debug("view_closed(%d, %s)", window_id, app_id);
49
50 HudApplicationList * list = HUD_APPLICATION_LIST(user_data);
51-
52- GList * sources = g_hash_table_get_values(list->priv->applications);
53- GList * lsource = NULL;
54-
55- for (lsource = sources; lsource != NULL; lsource = g_list_next(lsource)) {
56- HudApplicationSource * appsource = HUD_APPLICATION_SOURCE(lsource->data);
57- if (appsource == NULL) continue;
58-
59- if (hud_application_source_has_xid(appsource, window_id)) {
60- hud_application_source_window_closed(appsource, window_id);
61- }
62-
63- /* If the application source has become empty it means that it
64- * the correspongind app has terminated and it's time to do the
65- * cleanup.
66- */
67- if (hud_application_source_is_empty (appsource)) {
68- if ((gpointer)appsource == (gpointer)list->priv->used_source) {
69- hud_source_unuse(HUD_SOURCE(appsource));
70- g_clear_object(&list->priv->used_source);
71- }
72-
73- gchar * id = g_strdup(hud_application_source_get_id(appsource));
74-
75- g_debug("Removing application %s", id);
76- g_hash_table_remove(list->priv->applications, id);
77- g_free(id);
78- }
79-
80- hud_source_changed(HUD_SOURCE(list));
81- }
82-
83-
84-
85- return;
86+ HudSource *source = source_get(HUD_SOURCE(user_data), app_id);
87+
88+ if (source == NULL) {
89+ g_warning("Window closed for unknown app: %s", app_id);
90+ return;
91+ }
92+
93+ HudApplicationSource *appsource = HUD_APPLICATION_SOURCE(source);
94+
95+ if (hud_application_source_has_xid(appsource, window_id)) {
96+ hud_application_source_window_closed(appsource, window_id);
97+ }
98+
99+ /* If the application source has become empty it means that
100+ * the corresponding app has terminated and it's time to do the
101+ * cleanup.
102+ */
103+ if (hud_application_source_is_empty (appsource)) {
104+ if ((gpointer)appsource == (gpointer)list->priv->used_source) {
105+ hud_source_unuse(HUD_SOURCE(appsource));
106+ list->priv->used_source = NULL;
107+ }
108+
109+ g_debug("Removing application %s", app_id);
110+ g_hash_table_remove(list->priv->applications, app_id);
111+ }
112+
113+ hud_source_changed(HUD_SOURCE(list));
114 }
115
116 /* Source interface using this source */
117@@ -480,10 +472,9 @@
118
119 if (list->priv->used_source != NULL) {
120 hud_source_unuse(list->priv->used_source);
121- g_clear_object(&list->priv->used_source);
122 }
123
124- list->priv->used_source = g_object_ref(source);
125+ list->priv->used_source = HUD_SOURCE(source);
126
127 hud_source_use(HUD_SOURCE(source));
128
129@@ -500,7 +491,7 @@
130 g_return_if_fail(list->priv->used_source != NULL);
131
132 hud_source_unuse(list->priv->used_source);
133- g_clear_object(&list->priv->used_source);
134+ list->priv->used_source = NULL;
135
136 return;
137 }
138
139=== modified file 'src/application-source.c'
140--- src/application-source.c 2013-10-09 13:24:58 +0000
141+++ src/application-source.c 2013-10-14 15:48:19 +0000
142@@ -166,6 +166,8 @@
143 {
144 HudApplicationSource * self = HUD_APPLICATION_SOURCE(object);
145
146+ g_debug("hud_application_source_dispose %s", self->priv->app_id);
147+
148 if (self->priv->skel != NULL) {
149 g_dbus_interface_skeleton_unexport(G_DBUS_INTERFACE_SKELETON(self->priv->skel));
150 g_clear_object(&self->priv->skel);
151@@ -418,6 +420,8 @@
152 HudApplicationSource *
153 hud_application_source_new_for_id (const gchar * id)
154 {
155+ g_debug("hud_application_source_new_for_id: %s", id);
156+
157 HudApplicationSource * source = g_object_new(HUD_TYPE_APPLICATION_SOURCE, NULL);
158
159 source->priv->app_id = g_strdup(id);
160@@ -521,7 +525,6 @@
161 connection_watcher_t * watcher = g_hash_table_lookup(app->priv->connections, sender);
162 if (watcher == NULL) {
163 watcher = g_new0(connection_watcher_t, 1);
164- g_object_ref(app);
165 watcher->watch = g_bus_watch_name_on_connection(session, sender, G_BUS_NAME_WATCHER_FLAGS_NONE, NULL, connection_lost, app, NULL);
166 g_hash_table_insert(app->priv->connections, g_strdup(sender), watcher);
167 }

Subscribers

People subscribed via source and target branches

to all changes: