diff options
| author | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2013-11-14 16:51:37 +0000 |
|---|---|---|
| committer | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2014-01-29 19:28:30 +0000 |
| commit | 1e1ba5f4fef9ee83411d55e376f0f5fec0a6e892 (patch) | |
| tree | 63a770ba723346785ff038b507b7b7fbfb0f8096 | |
| parent | 03c99601d7a76fbc49ed376cd9c30ca631bc085f (diff) | |
McdStorage: when acting on one account, only store it in its plugin
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=27727
| -rw-r--r-- | src/mcd-storage.c | 68 |
1 files changed, 41 insertions, 27 deletions
diff --git a/src/mcd-storage.c b/src/mcd-storage.c index dffc498f..07d07f3d 100644 --- a/src/mcd-storage.c +++ b/src/mcd-storage.c @@ -1245,13 +1245,14 @@ update_storage (McdStorage *self, const gchar *key, GVariant *variant) { - GList *store; McpAccountManager *ma = MCP_ACCOUNT_MANAGER (self); gboolean updated = FALSE; + McpAccountStorage *plugin; - for (store = stores; store != NULL; store = g_list_next (store)) + plugin = g_hash_table_lookup (self->accounts, account); + + if (plugin != NULL) { - McpAccountStorage *plugin = store->data; const gchar *pn = mcp_account_storage_name (plugin); McpAccountStorageSetResult res; @@ -1268,8 +1269,6 @@ update_storage (McdStorage *self, DEBUG ("MCP:%s -> store %s %s.%s", pn, parameter ? "parameter" : "attribute", account, key); updated = TRUE; - /* set it to NULL in all lower-priority stores */ - variant = NULL; break; case MCP_ACCOUNT_STORAGE_SET_RESULT_FAILED: @@ -1286,6 +1285,10 @@ update_storage (McdStorage *self, g_warn_if_reached (); } } + else + { + g_assert_not_reached (); + } return updated; } @@ -1809,24 +1812,29 @@ void mcd_storage_delete_account (McdStorage *self, const gchar *account) { - GList *store; McpAccountManager *ma = MCP_ACCOUNT_MANAGER (self); + McpAccountStorage *plugin; g_return_if_fail (MCD_IS_STORAGE (self)); g_return_if_fail (account != NULL); - g_hash_table_remove (self->accounts, account); + plugin = g_hash_table_lookup (self->accounts, account); - for (store = stores; store != NULL; store = g_list_next (store)) + if (plugin == NULL) { - McpAccountStorage *plugin = store->data; - - /* FIXME: when we know which plugin owns the account, we can stop - * ignoring the error (if any), and make this method async - * in order to pass the error up to McdAccount */ - mcp_account_storage_delete_async (plugin, ma, account, - delete_cb, g_strdup (account)); + /* we wanted no account, we got no account, I call that success! */ + return; } + + g_object_ref (plugin); + g_hash_table_remove (self->accounts, account); + + /* FIXME: stop ignoring the error (if any), and make this method async + * in order to pass the error up to McdAccount */ + mcp_account_storage_delete_async (plugin, ma, account, + delete_cb, g_strdup (account)); + + g_object_unref (plugin); } /* @@ -1842,24 +1850,30 @@ mcd_storage_commit (McdStorage *self, const gchar *account) { GList *store; McpAccountManager *ma = MCP_ACCOUNT_MANAGER (self); + McpAccountStorage *plugin; + const gchar *pname; g_return_if_fail (MCD_IS_STORAGE (self)); + if (account != NULL) + { + plugin = g_hash_table_lookup (self->accounts, account); + g_return_val_if_fail (plugin != NULL, FALSE); + + pname = mcp_account_storage_name (plugin); + + DEBUG ("flushing plugin %s %s to long term storage", pname, account); + mcp_account_storage_commit (plugin, ma, account); + return; + } + for (store = stores; store != NULL; store = g_list_next (store)) { - McpAccountStorage *plugin = store->data; - const gchar *pname = mcp_account_storage_name (plugin); + plugin = store->data; + pname = mcp_account_storage_name (plugin); - if (account != NULL) - { - DEBUG ("flushing plugin %s %s to long term storage", pname, account); - mcp_account_storage_commit (plugin, ma, account); - } - else - { - DEBUG ("flushing plugin %s to long term storage", pname); - mcp_account_storage_commit (plugin, ma, NULL); - } + DEBUG ("flushing plugin %s to long term storage", pname); + mcp_account_storage_commit (plugin, ma, NULL); } } |
