Closed Bug 852034 Opened 12 years ago Closed 11 years ago

Replace restoreBookmarksFromJSONFile with importFromFile

Categories

(Toolkit :: Places, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla23

People

(Reporter: andreshm, Assigned: raymondlee)

References

Details

Attachments

(1 file, 6 obsolete files)

Replace PlacesUtils.restoreBookmarksFromJSONFile calls with BookmarkJSONUtils.importFromFile async call.
Depends on: 822200
Assignee: nobody → raymond
Should land the patch in Bug 852041 because this patch would touch some common files
Depends on: 852041
Attached patch v1 (obsolete) — Splinter Review
Attachment #727667 - Flags: review?(mak77)
Status: NEW → ASSIGNED
Blocks: 854288
Blocks: 854761
Attached patch v2 (obsolete) — Splinter Review
Updated this patch. This patch should be applied after the patch in bug 852041
Attachment #727667 - Attachment is obsolete: true
Attachment #727667 - Flags: review?(mak77)
Attachment #729427 - Flags: review?(mak77)
Comment on attachment 729427 [details] [diff] [review] v2 Review of attachment 729427 [details] [diff] [review]: ----------------------------------------------------------------- Due to lack of time I just skimmed through the patch quickly, a more complete review is still needed, so forwarding that to Mano ::: browser/components/places/content/places.js @@ +442,5 @@ > + } > + catch(ex) { > + PlacesOrganizer._showErrorAlert(PlacesUIUtils.getString("bookmarksRestoreParseError")); > + } > + }); could just use the failure then() callback, instead of a task ::: browser/components/places/tests/unit/test_browserGlue_prefs.js @@ +56,5 @@ > } > catch(ex) {} > > + // Give time for BrowserGlue._initPlaces to complete before next test. > + do_execute_soon(run_next_test); looks fragile, maybe we want a notification like places-browser-init-complete (see this patch I made some time ago for other reasons: https://bug839996.bugzilla.mozilla.org/attachment.cgi?id=715540) ?
Attachment #729427 - Flags: review?(mak77) → review?(mano)
Attachment #729427 - Flags: review?(mano)
Attached patch v3 (obsolete) — Splinter Review
(In reply to Marco Bonardo [:mak] (Away Mar 27 - Apr 2) from comment #4) > Comment on attachment 729427 [details] [diff] [review] > v2 > > Review of attachment 729427 [details] [diff] [review]: > ----------------------------------------------------------------- > > Due to lack of time I just skimmed through the patch quickly, a more > complete review is still needed, so forwarding that to Mano > > ::: browser/components/places/content/places.js > @@ +442,5 @@ > > + } > > + catch(ex) { > > + PlacesOrganizer._showErrorAlert(PlacesUIUtils.getString("bookmarksRestoreParseError")); > > + } > > + }); > > could just use the failure then() callback, instead of a task Done > > ::: browser/components/places/tests/unit/test_browserGlue_prefs.js > @@ +56,5 @@ > > } > > catch(ex) {} > > > > + // Give time for BrowserGlue._initPlaces to complete before next test. > > + do_execute_soon(run_next_test); > > looks fragile, maybe we want a notification like > places-browser-init-complete (see this patch I made some time ago for other > reasons: https://bug839996.bugzilla.mozilla.org/attachment.cgi?id=715540) ? Updated
Attachment #729427 - Attachment is obsolete: true
Attachment #730112 - Flags: review?(mano)
Comment on attachment 730112 [details] [diff] [review] v3 A couple of things: 1) In places.js, please adopt Task.spawn rather than postponing promise.resolve by main-thread self-dispatch. Please do so in both instances there. It'll result in a much more readable code. 2) Please also attach a -w diff.
Attachment #730112 - Flags: review?(mano) → feedback+
Attached patch v4 (obsolete) — Splinter Review
(In reply to Mano from comment #6) > Comment on attachment 730112 [details] [diff] [review] > v3 > > A couple of things: > 1) In places.js, please adopt Task.spawn rather than postponing > promise.resolve by main-thread self-dispatch. Please do so in both instances > there. It'll result in a much more readable code. Done. > 2) Please also attach a -w diff. This s a -w diff
Attachment #730112 - Attachment is obsolete: true
Attachment #735629 - Flags: review?(mano)
Comment on attachment 735629 [details] [diff] [review] v4 >- try { >- PlacesUtils.restoreBookmarksFromJSONFile(aFile); >- } >- catch(ex) { >- this._showErrorAlert(PlacesUIUtils.getString("bookmarksRestoreParseError")); >- } >+ Task.spawn(function() { >+ yield BookmarkJSONUtils.importFromFile(aFile, true); >+ }).then(null, function() { >+ PlacesOrganizer._showErrorAlert(PlacesUIUtils.getString("bookmarksRestoreParseError")); >+ }); > }, Hrm, why not: Task.spawn(function() { try { yield BookmarkJSONUtils.importFromFile(aFile, true); } catch(ex) { PlacesOrganizer._showErrorAlert(PlacesUIUtils.getString("bookmarksRestoreParseError")); } });
Also, it seems you're using |yield| which are probably not yet using the Task system (unless that's the default now).
Attached patch v5 (obsolete) — Splinter Review
(In reply to Mano from comment #8) > Comment on attachment 735629 [details] [diff] [review] > v4 > > > >- try { > >- PlacesUtils.restoreBookmarksFromJSONFile(aFile); > >- } > >- catch(ex) { > >- this._showErrorAlert(PlacesUIUtils.getString("bookmarksRestoreParseError")); > >- } > >+ Task.spawn(function() { > >+ yield BookmarkJSONUtils.importFromFile(aFile, true); > >+ }).then(null, function() { > >+ PlacesOrganizer._showErrorAlert(PlacesUIUtils.getString("bookmarksRestoreParseError")); > >+ }); > > }, > > Hrm, why not: > > Task.spawn(function() { > try { > yield BookmarkJSONUtils.importFromFile(aFile, true); > } > catch(ex) { > > PlacesOrganizer._showErrorAlert(PlacesUIUtils. > getString("bookmarksRestoreParseError")); > } > }); Either way works so I have updated the patch to what you suggested :-) (In reply to Mano from comment #9) > Also, it seems you're using |yield| which are probably not yet using the > Task system (unless that's the default now). As far as I know, |yield| works with Task system. @marco: can you comment on that please?
Attachment #735653 - Flags: review?
Flags: needinfo?(mak77)
Attachment #735653 - Flags: review? → review?(mano)
Attachment #735629 - Attachment is obsolete: true
Attachment #735629 - Flags: review?(mano)
Sorry, I meant that I'm not sure these tests are using the Task system already.
importFromFile: function(aFile, aReplace) still uses main-thread dispatching rather than Task.spawn.
not sure which was the exact question, though xpcshell-tests use task (and can use yield) if they use add_task to add sub tests. In any other case (included mochitests) there is not yet any centralized helper.
Flags: needinfo?(mak77)
Right, and as far as I can tell, most (if not all) of the tests touched here didn't adopt add_task yet.
Attachment #735653 - Flags: review?(mano) → review-
(In reply to Mano from comment #14) > Right, and as far as I can tell, most (if not all) of the tests touched here > didn't adopt add_task yet. You have to apply patches for bug 852041 first. Those tests touched by this patch would already using yield with either add_task or do_test_pending() and do_test_finished().
(In reply to Mano from comment #12) > importFromFile: function(aFile, aReplace) still uses main-thread dispatching > rather than Task.spawn. I think we can even don't need to use main-thread dispatching and Task.spawn. Let me create another patch.
Attached patch v6 (obsolete) — Splinter Review
Attachment #735653 - Attachment is obsolete: true
Attachment #735760 - Flags: review?(mano)
This bug is blocking other bugs we are trying to land. mano: could you review the latest patch if you have a chance please? thanks
Comment on attachment 735760 [details] [diff] [review] v6 Review of attachment 735760 [details] [diff] [review]: ----------------------------------------------------------------- ::: toolkit/components/places/BookmarkJSONUtils.jsm @@ +84,5 @@ > + */ > + importFromFile: function(aFile, aReplace) { > + if (aFile.exists()) { > + return this.importFromURL(NetUtil.newURI(aFile).spec, aReplace); > + } else { no |else| after return. I still think that using Task.spawn is the most safe & readable approach, but it's your call. @@ +91,5 @@ > + > + notifyObservers(PlacesUtils.TOPIC_BOOKMARKS_RESTORE_FAILED); > + deferred.reject(new Error("File does not exist.")); > + > + return deferred.promise; Hrm, does this actually work? I mean, isn't the promise rejected before it's returned? This stuff is new for me too.
Attachment #735760 - Flags: review?(mano) → review+
(In reply to Mano from comment #19) > Comment on attachment 735760 [details] [diff] [review] > v6 > > Review of attachment 735760 [details] [diff] [review]: > ----------------------------------------------------------------- > > ::: toolkit/components/places/BookmarkJSONUtils.jsm > @@ +84,5 @@ > > + */ > > + importFromFile: function(aFile, aReplace) { > > + if (aFile.exists()) { > > + return this.importFromURL(NetUtil.newURI(aFile).spec, aReplace); > > + } else { > > no |else| after return. > > I still think that using Task.spawn is the most safe & readable approach, > but it's your call. > > @@ +91,5 @@ > > + > > + notifyObservers(PlacesUtils.TOPIC_BOOKMARKS_RESTORE_FAILED); > > + deferred.reject(new Error("File does not exist.")); > > + > > + return deferred.promise; > > Hrm, does this actually work? I mean, isn't the promise rejected before it's > returned? > > This stuff is new for me too. Lets ask marco's input. marco: what do you think about the above code? Shall we wrap the deferred.rejected(new Error("File does not exist.")) with Task.spawn?
Flags: needinfo?(mak77)
If you use Task.spawn you don't need to create the promise yourself.
Attached patch v7Splinter Review
(In reply to Raymond Lee [:raymondlee] from comment #20) > > > > @@ +91,5 @@ > > > + > > > + notifyObservers(PlacesUtils.TOPIC_BOOKMARKS_RESTORE_FAILED); > > > + deferred.reject(new Error("File does not exist.")); > > > + > > > + return deferred.promise; > > > > Hrm, does this actually work? I mean, isn't the promise rejected before it's > > returned? > > > > This stuff is new for me too. > > Lets ask marco's input. > > marco: what do you think about the above code? Shall we wrap the > deferred.rejected(new Error("File does not exist.")) with Task.spawn? I have updated it as below. + if (aFile.exists()) { + return this.importFromURL(NetUtil.newURI(aFile).spec, aReplace); + } + + notifyObservers(PlacesUtils.TOPIC_BOOKMARKS_RESTORE_BEGIN); + + return Task.spawn(function() { + notifyObservers(PlacesUtils.TOPIC_BOOKMARKS_RESTORE_FAILED); + throw new Error("File does not exist."); + }); Pushed to try and waiting for results https://tbpl.mozilla.org/?tree=Try&rev=3629b2329d39
Attachment #735760 - Attachment is obsolete: true
Blocks: 855638
Flags: needinfo?(mak77)
Keywords: checkin-needed
Status: ASSIGNED → RESOLVED
Closed: 11 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla23
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: