aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorBastien Nocera <hadess@hadess.net>2013-03-14 17:11:27 +0800
committerBastien Nocera <hadess@hadess.net>2013-03-20 02:45:04 +0800
commit7eaba5831d5e339ee0ed114ff7478d50f1c255b4 (patch)
treed824607ecbcd6e2d49a1d948067601c4ba57d167 /lib
parent10f300b27a14c450c9a20b12c23f4e542942655c (diff)
downloadgsoc2013-epiphany-7eaba5831d5e339ee0ed114ff7478d50f1c255b4.tar
gsoc2013-epiphany-7eaba5831d5e339ee0ed114ff7478d50f1c255b4.tar.gz
gsoc2013-epiphany-7eaba5831d5e339ee0ed114ff7478d50f1c255b4.tar.bz2
gsoc2013-epiphany-7eaba5831d5e339ee0ed114ff7478d50f1c255b4.tar.lz
gsoc2013-epiphany-7eaba5831d5e339ee0ed114ff7478d50f1c255b4.tar.xz
gsoc2013-epiphany-7eaba5831d5e339ee0ed114ff7478d50f1c255b4.tar.zst
gsoc2013-epiphany-7eaba5831d5e339ee0ed114ff7478d50f1c255b4.zip
ephy-profile-migrator: Stop spinning when porting form passwords
Use atomic operations to manipulate the counter that tracks the number of operations we need to achieve, to ensure coherency when the results are received from different threads. Also use our own main loop rather than spinning on g_main_context_iteration() to avoid CPU burning when waiting for completion. Finally, fix the migrator never returning as the number of operations was not decreased on the ephy_form_auth_data_store() error path. https://bugzilla.gnome.org/show_bug.cgi?id=695828
Diffstat (limited to 'lib')
-rw-r--r--lib/ephy-profile-migrator.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/lib/ephy-profile-migrator.c b/lib/ephy-profile-migrator.c
index c3a69136b..934fc1143 100644
--- a/lib/ephy-profile-migrator.c
+++ b/lib/ephy-profile-migrator.c
@@ -55,6 +55,7 @@
static int do_step_n = -1;
static int version = -1;
static char *profile_dir = NULL;
+static GMainLoop *loop = NULL;
/*
* What to do to add new migration steps:
@@ -828,7 +829,8 @@ password_cleared_cb (SecretService *service,
{
secret_service_clear_finish (service, res, NULL);
- form_passwords_migrating--;
+ if (g_atomic_int_dec_and_test (&form_passwords_migrating))
+ g_main_loop_quit (loop);
}
static void
@@ -845,11 +847,15 @@ store_form_auth_data_cb (GObject *object,
goto out;
}
+ g_atomic_int_inc (&form_passwords_migrating);
secret_service_clear (NULL, NULL,
attributes, NULL, (GAsyncReadyCallback)password_cleared_cb,
NULL);
out:
+ if (g_atomic_int_dec_and_test (&form_passwords_migrating))
+ g_main_loop_quit (loop);
+
g_hash_table_unref (attributes);
}
@@ -885,7 +891,7 @@ load_collection_items_cb (SecretCollection *collection,
if (server &&
g_strstr_len (server, -1, "form%5Fusername") &&
g_strstr_len (server, -1, "form%5Fpassword")) {
- form_passwords_migrating++;
+ g_atomic_int_inc (&form_passwords_migrating);
/* This is one of the hackish ones that need to be migrated.
Fetch the rest of the data and take care of it. */
username = g_hash_table_lookup (attributes, "user");
@@ -914,7 +920,8 @@ load_collection_items_cb (SecretCollection *collection,
}
/* And decrease here so that we finish eventually. */
- form_passwords_migrating--;
+ if (g_atomic_int_dec_and_test (&form_passwords_migrating))
+ g_main_loop_quit (loop);
g_list_free_full (items, (GDestroyNotify)g_object_unref);
}
@@ -936,13 +943,13 @@ migrate_form_passwords_to_libsecret (void)
collections = secret_service_get_collections (service);
for (c = collections; c; c = c->next) {
- form_passwords_migrating++;
+ g_atomic_int_inc (&form_passwords_migrating);
secret_collection_load_items ((SecretCollection*)c->data, NULL, (GAsyncReadyCallback)load_collection_items_cb,
NULL);
}
- while (form_passwords_migrating)
- g_main_context_iteration (NULL, FALSE);
+ loop = g_main_loop_new (NULL, FALSE);
+ g_main_loop_run (loop);
g_list_free_full (collections, (GDestroyNotify)g_object_unref);
g_object_unref (service);