Merge branch 'upstream' into tizen
[platform/upstream/glib.git] / gio / gdbusnamewatching.c
old mode 100644 (file)
new mode 100755 (executable)
index d4272e4..ef6481f
@@ -351,9 +351,6 @@ on_name_owner_changed (GDBusConnection *connection,
   if (client == NULL)
     return;
 
-  if (!client->initialized)
-    goto out;
-
   if (g_strcmp0 (object_path, "/org/freedesktop/DBus") != 0 ||
       g_strcmp0 (interface_name, "org.freedesktop.DBus") != 0 ||
       g_strcmp0 (sender_name, "org.freedesktop.DBus") != 0)
@@ -369,7 +366,7 @@ on_name_owner_changed (GDBusConnection *connection,
   if (g_strcmp0 (name, client->name) != 0)
     goto out;
 
-  if ((old_owner != NULL && strlen (old_owner) > 0) && client->name_owner != NULL)
+  if (old_owner != NULL && strlen (old_owner) > 0)
     {
       g_free (client->name_owner);
       client->name_owner = NULL;
@@ -378,12 +375,18 @@ on_name_owner_changed (GDBusConnection *connection,
 
   if (new_owner != NULL && strlen (new_owner) > 0)
     {
-      g_warn_if_fail (client->name_owner == NULL);
       g_free (client->name_owner);
       client->name_owner = g_strdup (new_owner);
       call_appeared_handler (client);
     }
 
+  /* initialized set to TRUE means that signal was delivered and processed.
+   * Now, if we receive a reply to GetNameOwner call, we may just ignore it as it carries the same
+   * information as the current signal, or if something changed in the meantime we will
+   * get next signal very soon.
+   */
+  client->initialized = TRUE;
+
  out:
   client_unref (client);
 }
@@ -405,6 +408,13 @@ get_name_owner_cb (GObject      *source_object,
   result = g_dbus_connection_call_finish (client->connection,
                                           res,
                                           NULL);
+  /* In case we already received NameOwnerChanged signal, we don't need to
+   * process GetNameOwner answer, because all the information we needed was already
+   * delivered with the signal and processed by the signal handler.
+   */
+  if (client->initialized)
+    goto out;
+
   if (result != NULL)
     {
       g_variant_get (result, "(&s)", &name_owner);
@@ -421,10 +431,10 @@ get_name_owner_cb (GObject      *source_object,
       call_vanished_handler (client);
     }
 
-  client->initialized = TRUE;
-
+ out:
   if (result != NULL)
     g_variant_unref (result);
+
   client_unref (client);
 }