Merge lp:~urbanape/bindwood/thorough-debugging into lp:bindwood
- thorough-debugging
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | John O'Brien |
Approved revision: | 14 |
Merged at revision: | not available |
Proposed branch: | lp:~urbanape/bindwood/thorough-debugging |
Merge into: | lp:bindwood |
Diff against target: | None lines |
To merge this branch: | bzr merge lp:~urbanape/bindwood/thorough-debugging |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
John O'Brien (community) | Approve | ||
dobey (community) | Approve | ||
Review via email: mp+10928@code.launchpad.net |
This proposal supersedes a proposal from 2009-08-28.
Commit message
This branch adds thorough debugging to the Bindwood functionality. However, it is only surfaced when there is a BINDWOOD_DEBUG key in the user's environment.
Description of the change
Zachery Bir (urbanape) wrote : Posted in a previous version of this proposal | # |
dobey (dobey) wrote : Posted in a previous version of this proposal | # |
The code/logging looks ok, but I think the packaging should go in a separate branch... like a source package branch at ~ubuntuone-
dobey (dobey) wrote : Posted in a previous version of this proposal | # |
Pull the packaging stuff, and then change the proposal's status to "Resubmit" to create a new proposal which supersedes this one. (Make sure it's the proposal status, and not a review requesting a resubmission, which people seem to get confused by.)
dobey (dobey) : | # |
John O'Brien (jdobrien) wrote : | # |
Looks good.
As mentioned in irc you may want to fix that scheduled pullBookmarks delay
- 15. By Zachery Bir
-
Resetting the time interval back to 30s
Preview Diff
1 | === modified file 'content/sync.js' |
2 | --- content/sync.js 2009-08-18 14:17:30 +0000 |
3 | +++ content/sync.js 2009-08-27 18:45:48 +0000 |
4 | @@ -4,16 +4,17 @@ |
5 | * This program is free software: you can redistribute it and/or modify it |
6 | * under the terms of the GNU General Public License version 3, as published |
7 | * by the Free Software Foundation. |
8 | - * |
9 | + * |
10 | * This program is distributed in the hope that it will be useful, but |
11 | * WITHOUT ANY WARRANTY; without even the implied warranties of |
12 | * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
13 | * PURPOSE. See the GNU General Public License for more details. |
14 | - * |
15 | + * |
16 | * You should have received a copy of the GNU General Public License along |
17 | * with this program. If not, see <http://www.gnu.org/licenses/>. |
18 | */ |
19 | /* Lots and lots of debugging information */ |
20 | + |
21 | var Bindwood = { |
22 | bookmarksService: Components.classes["@mozilla.org/browser/nav-bookmarks-service;1"] |
23 | .getService(Components.interfaces.nsINavBookmarksService), |
24 | @@ -27,16 +28,20 @@ |
25 | .getService(Components.interfaces.nsINavHistoryService), |
26 | ioService: Components.classes["@mozilla.org/network/io-service;1"] |
27 | .getService(Components.interfaces.nsIIOService), |
28 | + envService: Components.classes["@mozilla.org/process/environment;1"] |
29 | + .getService(Components.interfaces.nsIEnvironment), |
30 | |
31 | annotationKey: "bindwood/uuid", |
32 | uuidItemIdMap: {}, |
33 | |
34 | generateUUIDString: function() { |
35 | - return Bindwood.uuidService.generateUUID().toString(); |
36 | + var uuid = Bindwood.uuidService.generateUUID().toString(); |
37 | + Bindwood.writeMessage("Generated UUID: " + uuid); |
38 | + return uuid; |
39 | }, |
40 | |
41 | - annotateItemWithUUID: function(itemId, uuid) { |
42 | - var uuid = uuid ? uuid : Bindwood.generateUUIDString(); |
43 | + annotateItemWithUUID: function(itemId, seed_uuid) { |
44 | + var uuid = seed_uuid ? seed_uuid : Bindwood.generateUUIDString(); |
45 | Bindwood.annotationService.setItemAnnotation(itemId, Bindwood.annotationKey, uuid, 0, Bindwood.annotationService.EXPIRE_NEVER); |
46 | // Whenever we create a new UUID, stash it and the itemId in |
47 | // our local cache. |
48 | @@ -47,16 +52,24 @@ |
49 | itemIdForUUID: function(uuid) { |
50 | // First, try to look it up in our local cache, barring that |
51 | // (which shouldn't happen), look it up slowly. |
52 | + Bindwood.writeMessage("Looking up itemId for uuid: " + uuid); |
53 | var itemId = Bindwood.uuidItemIdMap[uuid]; |
54 | |
55 | if (!itemId) { |
56 | + Bindwood.writeMessage("Didn't find itemId, looking up annotations"); |
57 | var items = Bindwood.annotationService.getItemsWithAnnotation(Bindwood.annotationKey, {}); |
58 | + var num_items = items.length; |
59 | + Bindwood.writeMessage("Looking through " + num_items + "item" + (num_items != 1 ? "s" : "")); |
60 | for (var i = 0; i < items.length; i++) { |
61 | if (Bindwood.annotationService.getItemAnnotation(items[i], Bindwood.annotationKey) == uuid) { |
62 | Bindwood.uuidItemIdMap[uuid] = itemId = items[i]; |
63 | + Bindwood.writeMessage("Found the matching itemId: " + itemId); |
64 | break; |
65 | } |
66 | } |
67 | + if (!itemId) { |
68 | + Bindwood.writeMessage("XXX: Still haven't found the right itemId!"); |
69 | + } |
70 | } |
71 | return itemId; |
72 | }, |
73 | @@ -64,13 +77,15 @@ |
74 | uuidForItemId: function(itemId) { |
75 | // Try to look up the uuid, and failing that, assign a new one |
76 | // and return it. |
77 | + Bindwood.writeMessage("Looking up a UUID for itemId: " + itemId); |
78 | var uuid; |
79 | - var found = false; |
80 | try { |
81 | uuid = Bindwood.annotationService.getItemAnnotation(itemId, Bindwood.annotationKey); |
82 | - found = true; |
83 | + Bindwood.writeMessage("Found it: " + uuid); |
84 | } catch(e) { |
85 | + Bindwood.writeError("Didn't find a UUID for itemId: " + itemId, e); |
86 | uuid = Bindwood.annotateItemWithUUID(itemId, null); |
87 | + Bindwood.writeMessage("Didn't find it, so made it: " + uuid); |
88 | } |
89 | |
90 | return uuid; |
91 | @@ -78,15 +93,16 @@ |
92 | |
93 | writeMessage: function(aMessage) { |
94 | // convenience method for logging. Way better than alert()s. |
95 | - Bindwood.consoleService.logStringMessage("Bindwood: " + aMessage); |
96 | + if (Bindwood.envService.exists('BINDWOOD_DEBUG')) { |
97 | + Bindwood.consoleService.logStringMessage("Bindwood: " + aMessage); |
98 | + } |
99 | }, |
100 | |
101 | writeError: function(aMessage, e) { |
102 | - Bindwood.writeMessage(aMessage + "message: '" + e.message + "', reason: '" + e.reason + "', description: '" + e.description + "', error: '" + e.error + "'"); |
103 | + // This should fire whether we're in DEBUG or not |
104 | + Bindwood.consoleService.logStringMessage("Bindwood: " + aMessage + " message: '" + e.message + "', reason: '" + e.reason + "', description: '" + e.description + "', error: '" + e.error + "'"); |
105 | }, |
106 | |
107 | - |
108 | - |
109 | init: function() { |
110 | // Start the process and de-register ourself |
111 | // http://forums.mozillazine.org/viewtopic.php?f=19&t=657911&start=0 |
112 | @@ -95,7 +111,7 @@ |
113 | if(Components.classes["@mozilla.org/appshell/window-mediator;1"] |
114 | .getService(Components.interfaces.nsIWindowMediator) |
115 | .getEnumerator("").getNext() == window) { |
116 | - Bindwood.writeMessage("Getting a Couch Port"); |
117 | + Bindwood.writeMessage("First window opened. Getting a Couch Port"); |
118 | Bindwood.getCouchPortNumber(Bindwood.startProcess); |
119 | } |
120 | }, |
121 | @@ -107,10 +123,12 @@ |
122 | |
123 | // find OS temp dir to put the tempfile in |
124 | // https://developer.mozilla.org/index.php?title=File_I%2F%2FO#Getting_special_files |
125 | + Bindwood.writeMessage("Creating temp dir"); |
126 | var tmpdir = Components.classes["@mozilla.org/file/directory_service;1"] |
127 | .getService(Components.interfaces.nsIProperties) |
128 | .get("TmpD", Components.interfaces.nsIFile); |
129 | // create a randomly named tempfile in the tempdir |
130 | + Bindwood.writeMessage("Creating temp file"); |
131 | var tmpfile = Components.classes["@mozilla.org/file/local;1"] |
132 | .createInstance(Components.interfaces.nsILocalFile); |
133 | tmpfile.initWithPath(tmpdir.path + "/desktopcouch." + Math.random()); |
134 | @@ -130,13 +148,14 @@ |
135 | |
136 | // create an nsIProcess2 to execute this bash script |
137 | var process = Components.classes["@mozilla.org/process/util;1"] |
138 | - .createInstance(Components.interfaces.nsIProcess2); |
139 | + .createInstance(Components.interfaces.nsIProcess2); |
140 | process.init(nsifile); |
141 | |
142 | // Run the process, passing the tmpfile path |
143 | var args = [tmpfile.path]; |
144 | + Bindwood.writeMessage("Running dbus script"); |
145 | process.runAsync(args, args.length, { |
146 | - observe: function(process, finishState, data) { |
147 | + observe: function(process, finishState, unused_data) { |
148 | var port = 5984; |
149 | if (finishState == "process-finished") { |
150 | // read temp file to find port number |
151 | @@ -151,7 +170,7 @@ |
152 | let (str = {}) { |
153 | cstream.readString(-1, str); // read the whole file and put it in str.value |
154 | data = str.value; |
155 | - } |
156 | + }; |
157 | cstream.close(); // this closes fstream |
158 | data = data.replace(/^\s\s*/, '').replace(/\s\s*$/, ''); |
159 | if (/^[0-9]+$/.test(data)) { |
160 | @@ -173,11 +192,14 @@ |
161 | Bindwood.writeMessage("Starting process with Couch on port " + couchPortNumber); |
162 | CouchDB.PORT_NUMBER = couchPortNumber; |
163 | try { |
164 | + Bindwood.writeMessage("Pushing bookmarks"); |
165 | Bindwood.pushBookmarks(); |
166 | } catch(e) { |
167 | Bindwood.writeError("Error when calling pushBookmarks: ", e); |
168 | } |
169 | + Bindwood.writeMessage("Creating view, if it's not there already"); |
170 | Bindwood.createView(); |
171 | + Bindwood.writeMessage("Pulling initial bookmarks"); |
172 | Bindwood.pullBookmarks(); |
173 | }, |
174 | |
175 | @@ -231,7 +253,11 @@ |
176 | try { |
177 | couch.createDb(); |
178 | } catch (e) { |
179 | - Bindwood.writeError("Error when creating database in pushBookmarks (file_exists is OK here): ", e); |
180 | + if (e.error == 'file_exists') { |
181 | + Bindwood.writeMessage("Database already exists. We're okay."); |
182 | + } else { |
183 | + Bindwood.writeError("Error when creating database in pushBookmarks: ", e); |
184 | + } |
185 | } |
186 | |
187 | Bindwood.pushBookmarksFromList(Bindwood.bookmarksService.toolbarFolder, |
188 | @@ -252,10 +278,12 @@ |
189 | var node = rootNode.getChild(i); |
190 | if (Bindwood.bookmarksService.getItemType(node.itemId) != |
191 | Bindwood.bookmarksService.TYPE_BOOKMARK) { |
192 | + Bindwood.writeMessage("Got something that isn't a bookmark"); |
193 | continue; |
194 | } |
195 | |
196 | var title = Bindwood.bookmarksService.getItemTitle(node.itemId); |
197 | + Bindwood.writeMessage("Got title: " + title); |
198 | try { |
199 | var metadata = Bindwood.bookmarksService.getBookmarkURI(node.itemId); |
200 | } catch(e) { |
201 | @@ -263,6 +291,7 @@ |
202 | continue; |
203 | } |
204 | var uuid = Bindwood.uuidForItemId(node.itemId); |
205 | + Bindwood.writeMessage("Got uuid: " + uuid); |
206 | retval.push({ |
207 | title: title, |
208 | metadata: metadata, |
209 | @@ -274,13 +303,23 @@ |
210 | }, |
211 | |
212 | pushBookmarksFromList: function(bookmarksList, bookmarksListName, db) { |
213 | + Bindwood.writeMessage("Pushing bookmarks from " + bookmarksListName); |
214 | var bookmarkData = Bindwood.getBookmarksFromList(bookmarksList); |
215 | for (var i = 0; i < bookmarkData.length; i++) { |
216 | // find this bookmark in CouchDB |
217 | - var uuid = Bindwood.uuidForItemId(bookmarkData[i].id); |
218 | + Bindwood.writeMessage("Looking up this record in Couch"); |
219 | + var itemId = bookmarkData[i].id; |
220 | + var uuid = bookmarkData[i].uuid; |
221 | var uri = bookmarkData[i].metadata.spec; |
222 | var title = bookmarkData[i].title; |
223 | |
224 | + Bindwood.writeMessage("Bookmark itemId: " + itemId + |
225 | + " has uuid: " + uuid + |
226 | + " uri: " + uri + |
227 | + " and title: \"" + title + "\""); |
228 | + |
229 | + Bindwood.uuidItemIdMap[uuid] = itemId; |
230 | + |
231 | var results = db.query(function(doc) { |
232 | if (doc.application_annotations && |
233 | doc.application_annotations.Firefox && |
234 | @@ -293,6 +332,7 @@ |
235 | |
236 | if (results.rows.length === 0) { |
237 | // this bookmark is not in CouchDB, so write it |
238 | + Bindwood.writeMessage("No bookmark with uuid: " + uuid + ", so we're making one"); |
239 | var record = { |
240 | record_type: "http://example.com/bookmark", |
241 | uri: uri, |
242 | @@ -306,10 +346,12 @@ |
243 | }; |
244 | try { |
245 | db.save(record); |
246 | + Bindwood.writeMessage("Saved new bookmark to Couch."); |
247 | } catch(e) { |
248 | Bindwood.writeError("Problem saving bookmark to CouchDB; bookmark is " + JSON.stringify(record) + ": ", e); |
249 | } |
250 | } else { |
251 | + Bindwood.writeMessage("This bookmark (" + uuid + ") is already in Couch, skipping"); |
252 | // bookmark is already in CouchDB, so do nothing |
253 | } |
254 | } |
255 | @@ -326,12 +368,14 @@ |
256 | if (doc.record_type == "http://example.com/bookmark") { |
257 | emit(doc._id,doc); |
258 | } |
259 | - }); |
260 | + }); |
261 | + Bindwood.writeMessage("Pulled all bookmark records from Couch"); |
262 | } catch(e) { |
263 | Bindwood.writeError("Problem fetching all bookmarks from Couch: ", e); |
264 | } |
265 | for (var i = 0; i < rows.rows.length; i++) { |
266 | var recordid = rows.rows[i].id; |
267 | + Bindwood.writeMessage("Pulling record: " + recordid); |
268 | var bm = rows.rows[i].value; |
269 | if (bm.application_annotations && |
270 | bm.application_annotations.Firefox && |
271 | @@ -339,7 +383,7 @@ |
272 | // this bookmark has a uuid, so check its values haven't changed |
273 | // find the bookmark with this uuid |
274 | var couch_uuid = bm.application_annotations.Firefox.uuid; |
275 | - Bindwood.writeMessage("Row uuid: " + couch_uuid); |
276 | + Bindwood.writeMessage("This bookmark has a uuid: " + couch_uuid + " so we're looking it up locally"); |
277 | var itemId = Bindwood.itemIdForUUID(couch_uuid); |
278 | if (!itemId) { |
279 | // This bookmark has a uuid, but it's not one of ours. |
280 | @@ -348,24 +392,32 @@ |
281 | // make the uuids the same), or (b) it's a new one |
282 | // that happens to have been created on a different |
283 | // machine. |
284 | + Bindwood.writeMessage("We didn't find that uuid: " + couch_uuid + " in the ItemId map, so we'll need to search for it by URI"); |
285 | try { |
286 | var uri = Bindwood.ioService.newURI(bm.uri, null, null); |
287 | + Bindwood.writeMessage("Made a new URI from the bookmark's uri: " + bm.uri); |
288 | } catch(e) { |
289 | - Bindwood.writeError("Problem creating URI (" + bm.uri + ") for bookmark: ", e); |
290 | + Bindwood.writeError("Problem creating URI (" + bm.uri + ") for bookmark, skipping: ", e); |
291 | continue; |
292 | } |
293 | var ids = Bindwood.bookmarksService.getBookmarkIdsForURI(uri, {}); |
294 | if (ids.length > 1) { |
295 | + Bindwood.writeMessage("Wow, didn't expect that. Multiple (" + ids.length + ") bookmarks found locally for the same URI: " + bm.uri); |
296 | // punt for now, too many problems. |
297 | } else if (ids.length) { |
298 | // Found one local bookmark. Replace its uuid to |
299 | // be the one from Couch. |
300 | - var itemId = ids[0]; |
301 | + Bindwood.writeMessage("We found one bookmark with the URI from Couch, so we're going to stamp Couch's uuid on it"); |
302 | + itemId = ids[0]; |
303 | var old_uuid = Bindwood.uuidForItemId(itemId); |
304 | + Bindwood.writeMessage("Got the old uuid: " + old_uuid); |
305 | delete Bindwood.uuidItemIdMap[old_uuid]; |
306 | + Bindwood.writeMessage("Deleted the old uuid from the ItemId map"); |
307 | Bindwood.annotateItemWithUUID(itemId, couch_uuid); |
308 | + Bindwood.writeMessage("Annotated the local bookmark with the uuid from Couch: " + couch_uuid); |
309 | } else { |
310 | /// No local bookmarks |
311 | + Bindwood.writeMessage("No local bookmark found, must be a new entry in Couch. Creating locally."); |
312 | Bindwood.addLocalBookmark(bm, recordid, couch_uuid); |
313 | } |
314 | } else { |
315 | @@ -374,17 +426,22 @@ |
316 | // flagged for deletion by another Client. We |
317 | // want to respect that, and delete it |
318 | // locally. |
319 | + Bindwood.writeMessage("This bookmark exists on Couch, but has been flagged for deletion, so we're deleting it locally"); |
320 | Bindwood.bookmarksService.removeItem(itemId); |
321 | + Bindwood.writeMessage("Local copy deleted"); |
322 | } else { |
323 | var title = Bindwood.bookmarksService.getItemTitle(itemId); |
324 | var metadata = Bindwood.bookmarksService.getBookmarkURI(itemId); |
325 | if (title != bm.title) { |
326 | + Bindwood.writeMessage("Resetting local title to title from Couch"); |
327 | Bindwood.bookmarksService.setItemTitle(itemId, bm.title); |
328 | } |
329 | if (metadata.spec != bm.uri) { |
330 | + Bindwood.writeMessage("The URI from Couch (" + bm.uri + ") is different from local (" + metadata.spec + ")"); |
331 | try { |
332 | - metadata = Bindwood.ioService.newURI(bm.uri, null, null); |
333 | - Bindwood.bookmarksService.changeBookmarkURI(itemId, metadata); |
334 | + var new_uri = Bindwood.ioService.newURI(bm.uri, null, null); |
335 | + Bindowod.writeMessage("Creating a new URI for our local bookmark"); |
336 | + Bindwood.bookmarksService.changeBookmarkURI(itemId, new_uri); |
337 | } catch(e) { |
338 | Bindwood.writeError("Problem creating a new URI for bookmark: ", e); |
339 | } |
340 | @@ -393,18 +450,20 @@ |
341 | } |
342 | } else { |
343 | // This bookmark has no uuid, so create it from fresh |
344 | - // in Firefox. Passing in null to addLocalBookmar will |
345 | + // in Firefox. Passing in null to addLocalBookmark will |
346 | // generate a new uuid. |
347 | + Bindwood.writeMessage("This bookmark from Couch has no uuid (not sure how that happened - manual creation in Couch?), so we're creating it locally, and saving it back."); |
348 | Bindwood.addLocalBookmark(bm, recordid, null); |
349 | } |
350 | } |
351 | // reschedule ourself |
352 | - setTimeout(Bindwood.pullBookmarks, 30000); |
353 | + Bindwood.writeMessage("Successful run, rescheduling ourself"); |
354 | + setTimeout(Bindwood.pullBookmarks, 300000); |
355 | }, |
356 | |
357 | addLocalBookmark: function(bm, recordid, uuid) { |
358 | var couch = new CouchDB('bookmarks'); |
359 | - var list; |
360 | + var list = Bindwood.bookmarksService.toolbarFolder; |
361 | if (bm.application_annotations && |
362 | bm.application_annotations.Firefox && |
363 | bm.application_annotations.Firefox.list) { |
364 | @@ -416,28 +475,39 @@ |
365 | list = Bindwood.bookmarksService.bookmarksMenuFolder; |
366 | break; |
367 | default: |
368 | - list = Bindwood.bookmarksService.toolbarFolder; |
369 | break; |
370 | } |
371 | - } else { |
372 | - list = Bindwood.bookmarksService.toolbarFolder; |
373 | - } |
374 | - var metadata = Bindwood.ioService.newURI(bm.uri, null, null); |
375 | - |
376 | - var itemId = Bindwood.bookmarksService.insertBookmark(list, |
377 | - metadata, -1, bm.title); |
378 | + } |
379 | + Bindwood.writeMessage("Established the correct list for ths bookmark to reside"); |
380 | + |
381 | + try { |
382 | + var new_uri = Bindwood.ioService.newURI(bm.uri, null, null); |
383 | + Bindowod.writeMessage("Creating a new URI for our local bookmark"); |
384 | + Bindwood.bookmarksService.changeBookmarkURI(itemId, new_uri); |
385 | + } catch(e) { |
386 | + Bindwood.writeError("Problem creating a new URI for bookmark: ", e); |
387 | + } |
388 | + |
389 | + var itemId = Bindwood.bookmarksService.insertBookmark( |
390 | + list, new_uri, -1, bm.title); |
391 | + Bindwood.writeMessage("Inserting the new bookmark, locally"); |
392 | // and then write the new uuid back to the record |
393 | - var uuid = uuid ? uuid : Bindwood.uuidForItemId(itemId); |
394 | + var new_uuid = uuid ? uuid : Bindwood.uuidForItemId(itemId); |
395 | + Bindwood.writeMessage("Since it's a new bookmark, we have a new uuid: " + new_uuid); |
396 | var doc = couch.open(recordid); |
397 | if (!doc.application_annotations) { |
398 | + Bindwood.writeMessage("Adding a new Applications annotation"); |
399 | doc.application_annotations = {}; |
400 | } |
401 | if (!doc.application_annotations.Firefox) { |
402 | + Bindwood.writeMessage("Adding a new Firefox annotation"); |
403 | doc.application_annotations.Firefox = {}; |
404 | } |
405 | - doc.application_annotations.Firefox.uuid = uuid; |
406 | + Bindwood.writeMessage("Adding the new uuid to the Firefox annotation"); |
407 | + doc.application_annotations.Firefox.uuid = new_uuid; |
408 | try { |
409 | couch.save(doc); |
410 | + Bindwood.writeMessage("Saved the doc back to Couch"); |
411 | } catch(e) { |
412 | Bindwood.writeError("Problem writing record for new bookmark: ",e); |
413 | } |
414 | @@ -448,13 +518,17 @@ |
415 | onItemAdded: function(aItemId, aFolder, aIndex) { |
416 | // A bookmark has been added, so we create a blank entry |
417 | // in Couch with our local itemId attached. |
418 | + Bindwood.writeMessage("A new bookmark was created. Its id is: " + aItemId + |
419 | + " at location: " + aIndex + |
420 | + " in folder: " + aFolder ); |
421 | netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead UniversalBrowserWrite"); |
422 | |
423 | var couch = new CouchDB('bookmarks'); |
424 | |
425 | var uuid = Bindwood.uuidForItemId(aItemId); |
426 | + Bindwood.writeMessage("Determined uuid for new bookmark: " + uuid); |
427 | |
428 | - var list; |
429 | + var list = "toolbarFolder"; |
430 | switch(aFolder) { |
431 | case Bindwood.bookmarksService.toolbarFolder: |
432 | list = "toolbarFolder"; |
433 | @@ -463,7 +537,6 @@ |
434 | list = "bookmarksMenuFolder"; |
435 | break; |
436 | default: |
437 | - list = "toolbarFolder"; |
438 | break; |
439 | } |
440 | |
441 | @@ -477,8 +550,11 @@ |
442 | } |
443 | }; |
444 | |
445 | + Bindwood.writeMessage("Created a minimal record document with our uuid"); |
446 | + |
447 | try { |
448 | var result = couch.save(doc); |
449 | + Bindwood.writeMessage("Saved new, bare record to Couch."); |
450 | } catch(e) { |
451 | Bindwood.writeError("Problem saving new bookmark to Couch: ", e); |
452 | } |
453 | @@ -487,6 +563,7 @@ |
454 | // A bookmark has been removed. This is called before it's |
455 | // been removed locally, though we're passed the itemId, |
456 | // which we use to delete from Couch. |
457 | + Bindwood.writeMessage("Record " + aItemId + " is about to be removed locally."); |
458 | netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead UniversalBrowserWrite"); |
459 | |
460 | var couch = new CouchDB('bookmarks'); |
461 | @@ -515,25 +592,30 @@ |
462 | |
463 | try { |
464 | var result = couch.save(doc); |
465 | + Bindwood.writeMessage("Saved document back to Couch with deleted flag set."); |
466 | // Also remove from our local cache and remove |
467 | // annotation from service. |
468 | delete Bindwood.uuidItemIdMap[uuid]; |
469 | + Bindwood.writeMessage("Deleted local reference in the uuid-itemId mapping."); |
470 | } catch(e) { |
471 | Bindwood.writeError("Problem pushing deleted record to Couch: ", e); |
472 | } |
473 | }, |
474 | onItemRemoved: function(aItemId, aFolder, aIndex) { |
475 | Bindwood.annotationService.removeItemAnnotation(aItemId, Bindwood.annotationKey); |
476 | + Bindwood.writeMessage("Removed annotations from bookmark identified by: " + aItemId); |
477 | }, |
478 | onItemChanged: function(aBookmarkId, aProperty, aIsAnnotationProperty, aValue) { |
479 | // A property of a bookmark has changed. On multiple |
480 | // property updates, this will be called multiple times, |
481 | // once per property (i.e., for title and URI) |
482 | + Bindwood.writeMessage("A property (" + aProperty + ") on bookmark id: " + aBookmarkId + " has been set to: " + aValue); |
483 | netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead UniversalBrowserWrite"); |
484 | |
485 | var couch = new CouchDB('bookmarks'); |
486 | |
487 | var uuid = Bindwood.uuidForItemId(aBookmarkId); |
488 | + Bindwood.writeMessage("Determined uuid for this bookmark: " + aBookmarkId + " is: " + uuid); |
489 | |
490 | var results = couch.query(function(doc) { |
491 | if (doc.application_annotations && |
492 | @@ -552,9 +634,11 @@ |
493 | |
494 | var doc = couch.open(results.rows[0].id); |
495 | doc[aProperty.toString()] = aValue.toString(); |
496 | + Bindwood.writeMessage("Set the new property on the document from Couch."); |
497 | |
498 | try { |
499 | var result = couch.save(doc); |
500 | + Bindwood.writeMessage("Saved the document back to Couch"); |
501 | } catch(e) { |
502 | Bindwood.writeError("Problem saving updated bookmark to Couch: ", e); |
503 | } |
This branch adds copious debugging info to the error log, but only in the environmental presence of
$BINDWOOD_DEBUG. With this branch installed, and launching Firefox normally, you'll see precious
little info in the Error console (errors only, in fact).
If you launch Firefox from the CLI, setting BINDWOOD_DEBUG, thus:
$ BINDWOOD_DEBUG=1 firefox &
And you look in the error console under Messages, you'll see all the gory details of pushing and pulling bookmarks, as well as event handling their creation and modification.