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 695118 - Avoid gtk_dialog_run() in goa_oauth2_provider_add_account()
Avoid gtk_dialog_run() in goa_oauth2_provider_add_account()
Status: RESOLVED OBSOLETE
Product: gnome-online-accounts
Classification: Core
Component: general
unspecified
Other Linux
: Normal normal
: ---
Assigned To: GNOME Online Accounts maintainer(s)
GNOME Online Accounts maintainer(s)
Depends on:
Blocks:
 
 
Reported: 2013-03-04 12:09 UTC by Emanuele Aina
Modified: 2021-07-05 10:58 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
oauth2: Removed redundant initialization assignment (893 bytes, patch)
2013-03-04 12:11 UTC, Emanuele Aina
rejected Details | Review
oauth2: Make obvious which recursive mainloop we're operating on (3.12 KB, patch)
2013-03-04 12:11 UTC, Emanuele Aina
none Details | Review
oauth2: Drop a recursive mainloop that was never run (1.39 KB, patch)
2013-03-04 12:11 UTC, Emanuele Aina
none Details | Review
oauth2: Move recursive mainloop instantion close to where it's run (1.26 KB, patch)
2013-03-04 12:11 UTC, Emanuele Aina
none Details | Review
oauth2: Simplify objects lifecycles by using a single private struct (24.53 KB, patch)
2013-03-04 12:11 UTC, Emanuele Aina
reviewed Details | Review
oauth2: Internally use private data fields instead of out parameters (11.87 KB, patch)
2013-03-04 12:11 UTC, Emanuele Aina
reviewed Details | Review
oauth2: Coalesce credentials GVariant building in a single place (4.05 KB, patch)
2013-03-04 12:11 UTC, Emanuele Aina
accepted-commit_now Details | Review
oauth2: Pivot get_tokens_and_identity() on gtk_dialog_run() (3.28 KB, patch)
2013-03-04 12:11 UTC, Emanuele Aina
none Details | Review
oauth2: Push the call to gtk_dialog_run() higher in the stack (3.06 KB, patch)
2013-03-04 12:11 UTC, Emanuele Aina
none Details | Review
oauth2: Coalesce the free'ing of token data in a single place (2.52 KB, patch)
2013-03-04 12:12 UTC, Emanuele Aina
none Details | Review
oauth2: Free token and identity data as soon as they're no longer needed (1.32 KB, patch)
2013-03-04 12:12 UTC, Emanuele Aina
none Details | Review
oauth2: Keep a ref to the GoaClient during account creation/refresh (4.54 KB, patch)
2013-03-04 12:12 UTC, Emanuele Aina
none Details | Review
oauth2: Move account creation out of goa_oauth2_provider_add_account() (2.75 KB, patch)
2013-03-04 12:12 UTC, Emanuele Aina
none Details | Review
oauth2: Define _add_account() in terms of async operations (5.24 KB, patch)
2013-03-04 12:12 UTC, Emanuele Aina
none Details | Review
oauth2: Drop a recursive mainloop that was never run (1.35 KB, patch)
2013-04-23 13:12 UTC, Debarshi Ray
committed Details | Review
oauth2: Move recursive mainloop instantion close to where it's run (1.23 KB, patch)
2013-04-23 13:59 UTC, Debarshi Ray
committed Details | Review
oauth2: Simplify object's lifecycle by using a single private struct (25.35 KB, patch)
2013-04-23 14:01 UTC, Debarshi Ray
committed Details | Review
oauth2: Internally use private data fields instead of out parameters (12.07 KB, patch)
2013-04-23 14:57 UTC, Debarshi Ray
committed Details | Review
oauth2: Coalesce credentials GVariant building in a single place (4.12 KB, patch)
2013-04-23 14:58 UTC, Debarshi Ray
none Details | Review
oauth2: Coalesce credentials GVariant building in a single place (4.11 KB, patch)
2013-04-23 15:17 UTC, Debarshi Ray
committed Details | Review

Description Emanuele Aina 2013-03-04 12:09:10 UTC
Since gtk_dialog_run() runs an internal mainloop it often leads to undesirable behaviours. For instance, in the gnome-control-center online-accounts DBus-activation patches _add_account() is called in a property setter and the dialog is show before the parent window has been updated.
Comment 1 Emanuele Aina 2013-03-04 12:11:11 UTC
Created attachment 237955 [details] [review]
oauth2: Removed redundant initialization assignment
Comment 2 Emanuele Aina 2013-03-04 12:11:15 UTC
Created attachment 237956 [details] [review]
oauth2: Make obvious which recursive mainloop we're operating on
Comment 3 Emanuele Aina 2013-03-04 12:11:21 UTC
Created attachment 237957 [details] [review]
oauth2: Drop a recursive mainloop that was never run
Comment 4 Emanuele Aina 2013-03-04 12:11:27 UTC
Created attachment 237958 [details] [review]
oauth2: Move recursive mainloop instantion close to where it's run
Comment 5 Emanuele Aina 2013-03-04 12:11:32 UTC
Created attachment 237959 [details] [review]
oauth2: Simplify objects lifecycles by using a single private struct
Comment 6 Emanuele Aina 2013-03-04 12:11:38 UTC
Created attachment 237960 [details] [review]
oauth2: Internally use private data fields instead of out parameters
Comment 7 Emanuele Aina 2013-03-04 12:11:44 UTC
Created attachment 237961 [details] [review]
oauth2: Coalesce credentials GVariant building in a single place
Comment 8 Emanuele Aina 2013-03-04 12:11:49 UTC
Created attachment 237962 [details] [review]
oauth2: Pivot get_tokens_and_identity() on gtk_dialog_run()

Split the setup code before gtk_dialog_run() and the result handling
after it in separate functions to prepare them to be used even when
gtk_dialog_run() will not be used.
Comment 9 Emanuele Aina 2013-03-04 12:11:56 UTC
Created attachment 237963 [details] [review]
oauth2: Push the call to gtk_dialog_run() higher in the stack

Having the call to gtk_dialog_run() exposed in top-level functions
should make reasoning about its removal easier.
Comment 10 Emanuele Aina 2013-03-04 12:12:01 UTC
Created attachment 237964 [details] [review]
oauth2: Coalesce the free'ing of token data in a single place
Comment 11 Emanuele Aina 2013-03-04 12:12:06 UTC
Created attachment 237965 [details] [review]
oauth2: Free token and identity data as soon as they're no longer needed
Comment 12 Emanuele Aina 2013-03-04 12:12:13 UTC
Created attachment 237966 [details] [review]
oauth2: Keep a ref to the GoaClient during account creation/refresh
Comment 13 Emanuele Aina 2013-03-04 12:12:19 UTC
Created attachment 237967 [details] [review]
oauth2: Move account creation out of goa_oauth2_provider_add_account()

Split the account creation code in a separate function to be able to
re-use it when gtk_dialog_run() will be no longer needed.
Comment 14 Emanuele Aina 2013-03-04 12:12:26 UTC
Created attachment 237968 [details] [review]
oauth2: Define _add_account() in terms of async operations
Comment 15 Emanuele Aina 2013-03-04 12:18:33 UTC
Getting rid of IdentifyData turned out to be a bit premature as GTask would benefit from it being available and would take care of its lifecycle, so the  patches after "Simplify objects lifecycles by using a single private struct" need to be reworked a bit. Also I didn't take care of _refresh_account() as I don't know how to test it (suggestions welcome).

However I think that the mainloop-related patches should be already acceptable, and the remaining ones should at least validate the approach. Any feedback welcome!
Comment 16 Emanuele Aina 2013-03-04 12:27:42 UTC
Getting rid of IdentifyData turned out to be a bit premature as GTask would benefit from it being available and would take care of its lifecycle, so the  patches after "Simplify objects lifecycles by using a single private struct" need to be reworked a bit. Also I didn't take care of _refresh_account() as I don't know how to test it (suggestions welcome).

However I think that the mainloop-related patches should be already acceptable, and the remaining ones should at least validate the approach. Any feedback welcome!
Comment 17 Debarshi Ray 2013-03-05 00:53:03 UTC
Can't these two be replaced by a single patch that deletes the mainloop that was never run?
 - oauth2: Make obvious which recursive mainloop we're operating on
 - oauth2: Drop a recursive mainloop that was never run

If we have only one mainloop left, then we don't need to rename it either.
Comment 18 Emanuele Aina 2013-03-05 07:39:43 UTC
(In reply to comment #17)

> Can't these two be replaced by a single patch that deletes the mainloop that
> was never run?
>  - oauth2: Make obvious which recursive mainloop we're operating on
>  - oauth2: Drop a recursive mainloop that was never run
> 
> If we have only one mainloop left, then we don't need to rename it either.

Yup, but until I renamed the patches it wasn't entirely obvious one of them was not needed at all. :)
I kept the patches separated to keep the obviousness during review, otherwise you'd only see some data->loop deletions without being sure which loop was being deleted, but if you prefer I can merge the two without too much problem (or I can just rename the mainloop that will be deleted, to avoid churn on the lines that will be kept).
Comment 19 Debarshi Ray 2013-04-23 13:12:42 UTC
Created attachment 242219 [details] [review]
oauth2: Drop a recursive mainloop that was never run
Comment 20 Debarshi Ray 2013-04-23 13:17:26 UTC
Review of attachment 237959 [details] [review]:

::: src/goabackend/goaoauth2provider.c
@@ +956,3 @@
+  g_free (priv->authorization_code);
+  g_free (priv->access_token);
+  g_free (priv->refresh_token);

Wouldn't it be safer to use g_clear_pointer so that the pointers are not left pointing to invalid memory?

@@ +1762,3 @@
+  g_free (priv->access_token);
+  g_free (priv->refresh_token);
+}

Strictly speaking this should be a finalize because there aren't any GObjects. Well, the main loop is ref counted, but I won't mind if we cheat a bit. :-)

In case you want to keep it as dispose, then those g_free's should be replaced by g_clear_pointer because a dispose can be called more than once.

And, you forgot to chain up.

@@ +1770,2 @@
 }
 

Lets use provider instead of self for consistency with the rest of the file. However, I agree that using self and self->priv is much better and we should fix it in a separate commit for the whole code base.
Comment 21 Debarshi Ray 2013-04-23 13:59:32 UTC
Created attachment 242225 [details] [review]
oauth2: Move recursive mainloop instantion close to where it's run

Adjust the patch for the name of the "loop".
Comment 22 Debarshi Ray 2013-04-23 14:01:20 UTC
Created attachment 242226 [details] [review]
oauth2: Simplify object's lifecycle by using a single private struct

Incorporate the minor issues from the review.
Comment 23 Debarshi Ray 2013-04-23 14:03:49 UTC
Review of attachment 237955 [details] [review]:

Do you really want to remove them? The whole code base follows this pattern where everything that cleaned up at the end is initialized at the top of the function to simplify shortcuts via goto.
Comment 24 Debarshi Ray 2013-04-23 14:47:57 UTC
Review of attachment 237960 [details] [review]:

Looks good, but needs to be adjusted for latest code in master.

::: src/goabackend/goaoauth2provider.c
@@ +1173,3 @@
    */
   if (!goa_utils_check_duplicate (client,
+                                  priv->identity,

You need to pass priv->presentation_identity in master now.
Comment 25 Debarshi Ray 2013-04-23 14:54:16 UTC
Review of attachment 237961 [details] [review]:

Looks good.
Comment 26 Debarshi Ray 2013-04-23 14:57:38 UTC
Created attachment 242233 [details] [review]
oauth2: Internally use private data fields instead of out parameters

Adjust for current master as stated in the review.
Comment 27 Debarshi Ray 2013-04-23 14:58:56 UTC
Created attachment 242234 [details] [review]
oauth2: Coalesce credentials GVariant building in a single place

Rebased on master.
Comment 28 Emanuele Aina 2013-04-23 15:12:43 UTC
(In reply to comment #23)
> Do you really want to remove them? The whole code base follows this pattern
> where everything that cleaned up at the end is initialized at the top of the
> function to simplify shortcuts via goto.

In my eyes they didn't seem to add much value since the variables are assigned just a couple of lines below. Feel free to drop the patch. :)
Comment 29 Debarshi Ray 2013-04-23 15:17:23 UTC
Created attachment 242238 [details] [review]
oauth2: Coalesce credentials GVariant building in a single place

Fix typo introduced while rebasing.
Comment 30 Debarshi Ray 2013-04-23 16:44:48 UTC
One thing to bear in mind. These changes need to be replicated for the OAuth provider class too.
Comment 31 GNOME Infrastructure Team 2021-07-05 10:58:54 UTC
GNOME is going to shut down bugzilla.gnome.org in favor of gitlab.gnome.org.
As part of that, we are mass-closing older open tickets in bugzilla.gnome.org
which have not seen updates for a longer time (resources are unfortunately
quite limited so not every ticket can get handled).

If you can still reproduce the situation described in this ticket in a recent
and supported software version, then please follow
  https://wiki.gnome.org/GettingInTouch/BugReportingGuidelines
and create a new ticket at
  https://gitlab.gnome.org/GNOME/gnome-online-accounts/-/issues/

Thank you for your understanding and your help.