After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 676484 - ephy-downloads: decide_action_from_mime() is a mess
ephy-downloads: decide_action_from_mime() is a mess
Status: RESOLVED FIXED
Product: epiphany
Classification: Core
Component: Downloads
git master
Other Linux
: Normal normal
: ---
Assigned To: Epiphany Maintainers
Epiphany Maintainers
: 677440 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2012-05-21 11:02 UTC by Claudio Saavedra
Modified: 2012-06-14 11:45 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
e-download: simplify decide_action_from_mime (2.08 KB, patch)
2012-05-26 22:39 UTC, Diego Escalante Urrelo (not reading bugmail)
none Details | Review
Updated patch (2.83 KB, patch)
2012-06-05 09:27 UTC, Carlos Garcia Campos
reviewed Details | Review
Updated patch (2.71 KB, patch)
2012-06-13 12:22 UTC, Carlos Garcia Campos
committed Details | Review

Description Claudio Saavedra 2012-05-21 11:02:52 UTC
- mime_description is leaked
- the final comment is confusing (it talks about DOWNLOAD_ACTION_DOWNLOAD but this is never used. Does it mean that this is the default value of action?)
- the two final assignations could be joined into one, but then it would make sense to set action to EPHY_DOWNLOAD_ACTION_BROWSE_TO as its default value instead?

Rewrite the whole thing in one go, since right now it looks all patched.
Comment 1 Xan Lopez 2012-05-24 10:03:52 UTC
(In reply to comment #0)
> - mime_description is leaked
> - the final comment is confusing (it talks about DOWNLOAD_ACTION_DOWNLOAD but
> this is never used. Does it mean that this is the default value of action?)

It means the action is not changed to OPEN because there was no helper app. Then the code proceeds to change it to BROWSE_TO, which makes sense.

> - the two final assignations could be joined into one, but then it would make
> sense to set action to EPHY_DOWNLOAD_ACTION_BROWSE_TO as its default value
> instead?

So what really does not make sense there is to change the mime_type when you are not going to use it anymore right? I think I'd just do if (!mime_type || !helper_app) action = BROWSE_TO; and be done with it. Just set the description to NULL at first and always g_free it at the end regardless.

That's what I'd do anyway.

> 
> Rewrite the whole thing in one go, since right now it looks all patched.
Comment 2 Diego Escalante Urrelo (not reading bugmail) 2012-05-26 22:39:08 UTC
Created attachment 215079 [details] [review]
e-download: simplify decide_action_from_mime

Remove some leftover logic from older versions of this function.
Add a gtk-doc comment explaining how the function works.
Comment 3 Carlos Garcia Campos 2012-06-05 09:09:07 UTC
*** Bug 677440 has been marked as a duplicate of this bug. ***
Comment 4 Carlos Garcia Campos 2012-06-05 09:11:49 UTC
Review of attachment 215079 [details] [review]:

::: embed/ephy-download.c
@@ +239,2 @@
    */
+  if (mime_description == NULL || helper_app == NULL)

mime_description is used here, but was freed already. helper_app is still leaked. We don't need the mime_description, since g_app_info_get_default_for_type() uses the content_type
Comment 5 Carlos Garcia Campos 2012-06-05 09:27:23 UTC
Created attachment 215623 [details] [review]
Updated patch

This is a merge of the patch I posted in bug #677440 and Diego's patch
Comment 6 Xan Lopez 2012-06-13 09:30:17 UTC
Review of attachment 215623 [details] [review]:

Code looks fine, just a nitpick.

::: embed/ephy-download.c
@@ +204,3 @@
+ *
+ * Returns: a default action for @download
+ **/

I don't really like full gtk-doc stuff for private methods. IIRC the scanner will parse them, which is annoying, and it's also somewhat confusing for humans reading the code (since at first it seems like a public method if you don't read carefully).
Comment 7 Carlos Garcia Campos 2012-06-13 11:00:18 UTC
Me neither, that was part of diego's patch, do you want me to remove it or convert it to a normal comment to clarify what the method does?
Comment 8 Xan Lopez 2012-06-13 11:44:59 UTC
(In reply to comment #7)
> Me neither, that was part of diego's patch, do you want me to remove it or
> convert it to a normal comment to clarify what the method does?

Normal comment is Ok.
Comment 9 Carlos Garcia Campos 2012-06-13 12:22:42 UTC
Created attachment 216268 [details] [review]
Updated patch
Comment 10 Xan Lopez 2012-06-14 10:09:29 UTC
Comment on attachment 216268 [details] [review]
Updated patch

OK.