summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAllison Ryan Lortie <desrt@desrt.ca>2015-12-16 10:04:13 -0500
committerAllison Ryan Lortie <desrt@desrt.ca>2015-12-16 11:31:01 -0500
commit4594876cd2b3c80a827cfe1526e0779b72777cc2 (patch)
tree6212c8e1895940feb0c4030d1fa0e7cdd12acae1
parenta4139891fa874197e945fe409698e16a5ba35ae3 (diff)
downloaddconf-4594876cd2b3c80a827cfe1526e0779b72777cc2.tar.gz
engine: add DCONF_READ_DEFAULT_VALUE flag
Add a flag that allows checking the default value without constructing a read_through queue. Make use of this new flag to simplify code in a couple of places. https://bugzilla.gnome.org/show_bug.cgi?id=759128
-rw-r--r--client/dconf-client.c30
-rw-r--r--common/dconf-enums.h1
-rw-r--r--engine/dconf-engine.c16
-rw-r--r--gsettings/dconfsettingsbackend.c19
4 files changed, 20 insertions, 46 deletions
diff --git a/client/dconf-client.c b/client/dconf-client.c
index e614256..0742748 100644
--- a/client/dconf-client.c
+++ b/client/dconf-client.c
@@ -245,34 +245,6 @@ dconf_client_read (DConfClient *client,
return dconf_engine_read (client->engine, DCONF_READ_FLAGS_NONE, NULL, key);
}
-/* This provides a "read through" queue that resets all of the keys.
- * This is a good way to get the default value for a key.
- *
- * We cache the value of this queue in a static instead of generating
- * and freeing it each time.
- */
-static GQueue *
-dconf_client_get_reset_queue (void)
-{
- static GQueue *reset_queue;
-
- if (g_once_init_enter (&reset_queue))
- {
- DConfChangeset *reset_all;
- GQueue *tmp;
-
- reset_all = dconf_changeset_new ();
- dconf_changeset_set (reset_all, "/", NULL);
- dconf_changeset_seal (reset_all);
-
- tmp = g_queue_new ();
- g_queue_push_tail (tmp, reset_all);
- g_once_init_leave (&reset_queue, tmp);
- }
-
- return reset_queue;
-}
-
/**
* dconf_client_read_default:
* @client: a #DConfClient
@@ -296,7 +268,7 @@ dconf_client_read_default (DConfClient *client,
{
g_return_val_if_fail (DCONF_IS_CLIENT (client), NULL);
- return dconf_engine_read (client->engine, DCONF_READ_FLAGS_NONE, dconf_client_get_reset_queue (), key);
+ return dconf_engine_read (client->engine, DCONF_READ_DEFAULT_VALUE, NULL, key);
}
/**
diff --git a/common/dconf-enums.h b/common/dconf-enums.h
index a2ac08a..2f10d1a 100644
--- a/common/dconf-enums.h
+++ b/common/dconf-enums.h
@@ -35,6 +35,7 @@ typedef enum
typedef enum
{
DCONF_READ_FLAGS_NONE = 0,
+ DCONF_READ_DEFAULT_VALUE = (1u << 0),
DCONF_READ_USER_VALUE = (1u << 1)
} DConfReadFlags;
diff --git a/engine/dconf-engine.c b/engine/dconf-engine.c
index ebd8ede..7a621c2 100644
--- a/engine/dconf-engine.c
+++ b/engine/dconf-engine.c
@@ -484,6 +484,12 @@ dconf_engine_read (DConfEngine *engine,
* visible (because of a lock). This includes any pending value
* that is in the read_through or pending queues.
*
+ * If DCONF_READ_DEFAULT_VALUE is given then we skip the writable
+ * database and the queues (including read_through, which is
+ * meaningless in this case) and skip directly to the non-writable
+ * databases. This is defined as the value that the user would see
+ * if they were to have just done a reset for that key.
+ *
* With respect to read_through and queued changed:
*
* We only consider read_through and queued changes in the event
@@ -575,8 +581,16 @@ dconf_engine_read (DConfEngine *engine,
{
gboolean found_key = FALSE;
+ /* If the user has requested the default value only, then ensure
+ * that we "find" a NULL value here. This is equivalent to the
+ * user having reset the key, which is the definition of this
+ * flag.
+ */
+ if (flags & DCONF_READ_DEFAULT_VALUE)
+ found_key = TRUE;
+
/* Step 2. Check read_through. */
- if (read_through)
+ if (!found_key && read_through)
found_key = dconf_engine_find_key_in_queue (read_through, key, &value);
/* Step 3. Check queued changes if we didn't find it in read_through.
diff --git a/gsettings/dconfsettingsbackend.c b/gsettings/dconfsettingsbackend.c
index 0e96f5e..752e013 100644
--- a/gsettings/dconfsettingsbackend.c
+++ b/gsettings/dconfsettingsbackend.c
@@ -44,23 +44,10 @@ dconf_settings_backend_read (GSettingsBackend *backend,
gboolean default_value)
{
DConfSettingsBackend *dcsb = (DConfSettingsBackend *) backend;
- GVariant *value;
- if (default_value)
- {
- GQueue *read_through;
-
- /* Mark the key as having been reset when trying to do the read... */
- read_through = g_queue_new ();
- g_queue_push_tail (read_through, dconf_changeset_new_write (key, NULL));
- value = dconf_engine_read (dcsb->engine, DCONF_READ_FLAGS_NONE, read_through, key);
- g_queue_free_full (read_through, (GDestroyNotify) dconf_changeset_unref);
- }
-
- else
- value = dconf_engine_read (dcsb->engine, DCONF_READ_FLAGS_NONE, NULL, key);
-
- return value;
+ return dconf_engine_read (dcsb->engine,
+ default_value ? DCONF_READ_DEFAULT_VALUE : 0,
+ NULL, key);
}
static GVariant *