Merge lp:~rye/ubuntuone-client/stop-killing-thumbnails into lp:ubuntuone-client

Proposed by Roman Yepishev
Status: Merged
Approved by: Rick McBride
Approved revision: not available
Merged at revision: not available
Proposed branch: lp:~rye/ubuntuone-client/stop-killing-thumbnails
Merge into: lp:ubuntuone-client
Prerequisite: lp:~rye/ubuntuone-client/bring-emblems-back
Diff against target: 172 lines (+73/-6)
1 file modified
nautilus/ubuntuone-nautilus.c (+73/-6)
To merge this branch: bzr merge lp:~rye/ubuntuone-client/stop-killing-thumbnails
Reviewer Review Type Date Requested Status
Rick McBride (community) Approve
dobey (community) Approve
Review via email: mp+16315@code.launchpad.net

Commit message

Removed emblem updating by utime, keeping references to NautilusFileInfo and invalidating the file info

To post a comment you must log in.
Revision history for this message
Roman Yepishev (rye) wrote :

Depends on emblems code fixup otherwise the the code that updates the files would not get called.

Revision history for this message
Vincenzo Di Somma (vds) wrote :

Could you please describe what this branch does?

Revision history for this message
Roman Yepishev (rye) wrote :

> Could you please describe what this branch does?

This branch fixes #491777 by creating internal hash for all file objects that were handled to us by Nautilus in ubuntuone_nautilus_update_file_info. Later on this info is used to request nautilus to invalidate extension date (in our case - emblems). After the call tonautilus_file_info_invalidate_extension_info the emblems get cleared and a call of ubuntuone_nautilus_update_file_info is performed.
The old method, updating the modification time for a file caused the thumbnails to be regenerated and is a pretty nasty practice, since other applications might use these timestamps for their purposes.

Revision history for this message
dobey (dobey) wrote :

This depends on https://edge.launchpad.net/~romdel/ubuntuone-client/bring-emblems-back/+merge/16314 as one of the changes there is needed for this branch to merge correctly. I'm going to set my review to Needs Fixing as a method of noting this, until that branch can be landed.

review: Needs Fixing
Revision history for this message
Roman Yepishev (rye) wrote :

Just a reminder.

Since the branch https://edge.launchpad.net/~rtgz/ubuntuone-client/bring-emblems-back/+merge/16314 has been merged, this can be merged as well.

Revision history for this message
dobey (dobey) wrote :

I think here you need to do the weak_ref before inserting into the hash table.

70 + g_hash_table_insert (uon->observed, g_strdup (path), file);
71 + g_object_weak_ref (G_OBJECT(file),
72 + (GWeakNotify)ubuntuone_nautilus_observed_file_unref,
73 + uon);

And I think here, you need to specify g_object_weak_unref as the destroy callback for the data.

+ uon->observed = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);

I may be totally wrong on the second one (as weak refs are a little vague), but the first change definitely improves the readability of the code (makes more sense to ref before doing more stuff). Thanks for looking into this.

review: Needs Fixing
298. By Roman Yepishev

Reversed the order of weak ref callback registration and hash insert

Revision history for this message
Roman Yepishev (rye) wrote :

Reversed the order of the statements for the first item.

Unfortunately, it is not possible to call any destroy callback routine with custom arguments when uon->observer is destroyed. The callback accepts value pointer only and therefore our uon object cannot be easily accessed.

It is possible to add code that runs through the hash and removes all references, however it looks like nautilus keeps additional reference to NAUTILUS_TYPE_INFO_PROVIDER module (looks like ubuntuone-nautilus and nautilus-share are affected). Our shutdown and finalize routines are never called so I would rather not write code blindly :)

I am investigating this nautilus bug at the moment and will file a bug when I get some useful info.

Revision history for this message
Roman Yepishev (rye) wrote :

Okay, I found the guilty extension - nautilus-open-terminal.
https://bugzilla.gnome.org/show_bug.cgi?id=605390

Will comment here once I check the behavior of the finalize code regarding these weak references.

299. By Roman Yepishev

Added weak reference cleanup

All weak reference callbacks for existing file items are now removed prior to
hash destruction.

Revision history for this message
dobey (dobey) wrote :

Looks ok to me now. Thanks for working on this.

review: Approve
Revision history for this message
Rick McBride (rmcbride) wrote :

Very nice!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'nautilus/ubuntuone-nautilus.c'
2--- nautilus/ubuntuone-nautilus.c 2009-12-18 22:24:01 +0000
3+++ nautilus/ubuntuone-nautilus.c 2009-12-30 21:32:14 +0000
4@@ -43,7 +43,6 @@
5 #include <string.h>
6 #include <sys/stat.h>
7 #include <sys/types.h>
8-#include <utime.h>
9
10 /* The header is generated from ubuntuone-marshallers.list */
11 #include "ubuntuone-marshallers.h"
12@@ -80,6 +79,8 @@
13 /* Lists of sync/unsync'd files */
14 GHashTable * updated;
15 GHashTable * needsupdating;
16+ /* List of files that are observed for changes */
17+ GHashTable * observed;
18
19 /* Extra data we need to free on finalization */
20 ShareCBData * share_cb_data;
21@@ -94,6 +95,17 @@
22 static GType ubuntuone_nautilus_get_type (void);
23 static void ubuntuone_nautilus_register_type (GTypeModule * module);
24
25+/* Utility functions */
26+static void ubuntuone_nautilus_reset_emblem (UbuntuOneNautilus * uon,
27+ const char * path);
28+
29+static void ubuntuone_nautilus_observed_file_unref (gpointer user_data,
30+ GObject *where_the_object_was);
31+
32+static void ubuntuone_nautilus_observed_file_foreach_unref (gpointer key,
33+ gpointer value,
34+ gpointer user_data);
35+
36 /* DBus signal and async method call handlers */
37 static void ubuntuone_nautilus_update_meta (DBusGProxy * proxy,
38 DBusGProxyCall * call_id,
39@@ -132,6 +144,46 @@
40
41 static GObjectClass * parent_class = NULL;
42
43+static void ubuntuone_nautilus_reset_emblem (UbuntuOneNautilus * uon,
44+ const char * path) {
45+
46+ NautilusFileInfo *file = g_hash_table_lookup (uon->observed, path);
47+ if (file)
48+ nautilus_file_info_invalidate_extension_info (file);
49+}
50+
51+/* Called when NautilusFileInfo is unreferenced */
52+static void ubuntuone_nautilus_observed_file_unref (gpointer user_data,
53+ GObject *where_the_object_was) {
54+ UbuntuOneNautilus * uon;
55+ NautilusFileInfo * file;
56+ gchar * path = NULL;
57+
58+ uon = UBUNTUONE_NAUTILUS(user_data);
59+ file = NAUTILUS_FILE_INFO(where_the_object_was);
60+ path = g_filename_from_uri (nautilus_file_info_get_uri (file), NULL, NULL);
61+
62+ if (g_hash_table_lookup (uon->observed, path ))
63+ g_hash_table_remove (uon->observed, path);
64+
65+}
66+
67+/* Cleanup routine for weak reference callbacks */
68+static void ubuntuone_nautilus_observed_file_foreach_unref (gpointer key,
69+ gpointer value,
70+ gpointer user_data) {
71+ UbuntuOneNautilus * uon;
72+ NautilusFileInfo * file;
73+
74+ uon = UBUNTUONE_NAUTILUS(user_data);
75+ file = NAUTILUS_FILE_INFO(value);
76+
77+ g_object_weak_unref (G_OBJECT(file),
78+ (GWeakNotify)ubuntuone_nautilus_observed_file_unref,
79+ uon);
80+
81+}
82+
83 /* Are we in an Ubuntu One managed directory */
84 static gboolean ubuntuone_is_storagefs (UbuntuOneNautilus * uon,
85 const char * path) {
86@@ -171,6 +223,11 @@
87 if (!path || !ubuntuone_is_storagefs (uon, path))
88 goto updating_meta;
89
90+ g_object_weak_ref (G_OBJECT(file),
91+ (GWeakNotify)ubuntuone_nautilus_observed_file_unref,
92+ uon);
93+ g_hash_table_insert (uon->observed, g_strdup (path), file);
94+
95 if (!g_hash_table_lookup (uon->updated, path) &&
96 !g_hash_table_lookup (uon->needsupdating, path)) {
97 /* Add the synchronized emblem anyway, and update later */
98@@ -566,6 +623,7 @@
99 uon->shares = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
100 uon->updated = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
101 uon->needsupdating = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
102+ uon->observed = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
103
104 /* Magic bag of holding +10:
105 * We store some button widgets in a hash table here, so that we can
106@@ -733,6 +791,14 @@
107 g_hash_table_destroy (uon->needsupdating);
108 uon->needsupdating = NULL;
109
110+ /* We need to remove all weak reference callbacks */
111+ g_hash_table_foreach (uon->observed,
112+ (GHFunc)ubuntuone_nautilus_observed_file_foreach_unref,
113+ uon);
114+
115+ g_hash_table_destroy (uon->observed);
116+ uon->observed = NULL;
117+
118 g_hash_table_destroy (uon->buttons);
119 uon->buttons = NULL;
120 }
121@@ -833,7 +899,7 @@
122 g_hash_table_replace (uon->updated, new_path, new_path);
123 else
124 g_hash_table_replace (uon->needsupdating, new_path, new_path);
125- utime (new_path, NULL);
126+ ubuntuone_nautilus_reset_emblem (uon, new_path);
127 }
128
129 static void ubuntuone_nautilus_state_toggled (DBusGProxy * proxy,
130@@ -939,7 +1005,7 @@
131 if (!g_hash_table_lookup (uon->uploads, path)) {
132 gchar *new_path = g_strdup (path);
133 g_hash_table_insert (uon->uploads, new_path, new_path);
134- utime (path, NULL);
135+ ubuntuone_nautilus_reset_emblem (uon, path);
136 }
137 }
138
139@@ -955,7 +1021,7 @@
140 new_path = g_strdup (path);
141 g_hash_table_replace (uon->updated, new_path, new_path);
142
143- utime (path, NULL);
144+ ubuntuone_nautilus_reset_emblem (uon, path);
145 }
146
147 static void ubuntuone_nautilus_download_started (DBusGProxy * proxy,
148@@ -966,7 +1032,7 @@
149 if (!g_hash_table_lookup (uon->downloads, path)) {
150 gchar *new_path = g_strdup (path);
151 g_hash_table_insert (uon->downloads, new_path, new_path);
152- utime (path, NULL);
153+ ubuntuone_nautilus_reset_emblem (uon, path);
154 }
155 }
156
157@@ -983,7 +1049,7 @@
158 new_path = g_strdup (path);
159 g_hash_table_replace (uon->updated, new_path, new_path);
160
161- utime (path, NULL);
162+ ubuntuone_nautilus_reset_emblem (uon, path);
163 }
164
165 static void ubuntuone_nautilus_share_created (DBusGProxy * proxy,
166@@ -996,6 +1062,7 @@
167 if (!g_hash_table_lookup (uon->shares, path)) {
168 gchar *new_share = g_strdup (path);
169 g_hash_table_insert (uon->shares, new_share, new_share);
170+ ubuntuone_nautilus_reset_emblem (uon, new_share);
171 }
172 }
173

Subscribers

People subscribed via source and target branches