[empathy/gnome-3-4] tp-chat: stop setting the TpAccount during construction



commit 284d3c729f9cb30610ddee56c479d1176270f854
Author: Guillaume Desmottes <guillaume desmottes collabora co uk>
Date:   Wed Jun 27 11:05:18 2012 +0200

    tp-chat: stop setting the TpAccount during construction
    
    It doesn't have to be a property any more, we can just get it from the
    TpConnection when we need it.
    
    Should fix a race crash when the TpAccount of the TpConnection is not set yet;
    see fdo#51444.

 libempathy/empathy-client-factory.c |    6 +---
 libempathy/empathy-tp-chat.c        |   49 +++++++---------------------------
 libempathy/empathy-tp-chat.h        |    1 -
 3 files changed, 11 insertions(+), 45 deletions(-)
---
diff --git a/libempathy/empathy-client-factory.c b/libempathy/empathy-client-factory.c
index 2a85594..11e2b16 100644
--- a/libempathy/empathy-client-factory.c
+++ b/libempathy/empathy-client-factory.c
@@ -45,12 +45,8 @@ empathy_client_factory_create_channel (TpSimpleClientFactory *factory,
 
   if (!tp_strdiff (chan_type, TP_IFACE_CHANNEL_TYPE_TEXT))
     {
-      TpAccount *account;
-
-      account = tp_connection_get_account (conn);
-
       return TP_CHANNEL (empathy_tp_chat_new (
-            TP_SIMPLE_CLIENT_FACTORY (factory), account, conn, path,
+            TP_SIMPLE_CLIENT_FACTORY (factory), conn, path,
             properties));
     }
 
diff --git a/libempathy/empathy-tp-chat.c b/libempathy/empathy-tp-chat.c
index e90f6ed..af6c380 100644
--- a/libempathy/empathy-tp-chat.c
+++ b/libempathy/empathy-tp-chat.c
@@ -179,6 +179,7 @@ tp_chat_add (EmpathyContactList *list,
 		const char        *object_path;
 		GPtrArray          channels = { (gpointer *) &object_path, 1 };
 		const char        *invitees[2] = { NULL, };
+		TpAccount         *account;
 
 		invitees[0] = empathy_contact_get_id (contact);
 		object_path = tp_proxy_get_object_path (self);
@@ -195,7 +196,9 @@ tp_chat_add (EmpathyContactList *list,
 		    /* FIXME: InvitationMessage ? */
 		    NULL);
 
-		req = tp_account_channel_request_new (self->priv->account, props,
+		account = empathy_tp_chat_get_account (self);
+
+		req = tp_account_channel_request_new (account, props,
 			TP_USER_ACTION_TIME_NOT_USER_ACTION);
 
 		/* Although this is a MUC, it's anonymous, so CreateChannel is
@@ -761,7 +764,6 @@ tp_chat_dispose (GObject *object)
 {
 	EmpathyTpChat *self = EMPATHY_TP_CHAT (object);
 
-	tp_clear_object (&self->priv->account);
 	tp_clear_object (&self->priv->remote_contact);
 	tp_clear_object (&self->priv->user);
 
@@ -1107,9 +1109,6 @@ tp_chat_get_property (GObject    *object,
 	EmpathyTpChat *self = EMPATHY_TP_CHAT (object);
 
 	switch (param_id) {
-	case PROP_ACCOUNT:
-		g_value_set_object (value, self->priv->account);
-		break;
 	case PROP_SELF_CONTACT:
 		g_value_set_object (value, self->priv->user);
 		break;
@@ -1134,24 +1133,6 @@ tp_chat_get_property (GObject    *object,
 	};
 }
 
-static void
-tp_chat_set_property (GObject      *object,
-		      guint         param_id,
-		      const GValue *value,
-		      GParamSpec   *pspec)
-{
-	EmpathyTpChat *self = EMPATHY_TP_CHAT (object);
-
-	switch (param_id) {
-	case PROP_ACCOUNT:
-		self->priv->account = g_value_dup_object (value);
-		break;
-	default:
-		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
-		break;
-	};
-}
-
 enum {
 	FEAT_READY,
 	N_FEAT
@@ -1187,20 +1168,9 @@ empathy_tp_chat_class_init (EmpathyTpChatClass *klass)
 	object_class->dispose = tp_chat_dispose;
 	object_class->finalize = tp_chat_finalize;
 	object_class->get_property = tp_chat_get_property;
-	object_class->set_property = tp_chat_set_property;
 
 	proxy_class->list_features = tp_chat_list_features;
 
-	g_object_class_install_property (object_class,
-					 PROP_ACCOUNT,
-					 g_param_spec_object ("account",
-							      "TpAccount",
-							      "the account associated with the chat",
-							      TP_TYPE_ACCOUNT,
-							      G_PARAM_READWRITE |
-							      G_PARAM_CONSTRUCT_ONLY |
-							      G_PARAM_STATIC_STRINGS));
-
 	/**
 	 * EmpathyTpChat:self-contact:
 	 *
@@ -1315,20 +1285,17 @@ tp_chat_iface_init (EmpathyContactListIface *iface)
 EmpathyTpChat *
 empathy_tp_chat_new (
 		     TpSimpleClientFactory *factory,
-		     TpAccount *account,
 		     TpConnection *conn,
 		     const gchar *object_path,
 		     const GHashTable *immutable_properties)
 {
 	TpProxy *conn_proxy = (TpProxy *) conn;
 
-	g_return_val_if_fail (TP_IS_ACCOUNT (account), NULL);
 	g_return_val_if_fail (TP_IS_CONNECTION (conn), NULL);
 	g_return_val_if_fail (immutable_properties != NULL, NULL);
 
 	return g_object_new (EMPATHY_TYPE_TP_CHAT,
 			     "factory", factory,
-			     "account", account,
 			     "connection", conn,
 			     "dbus-daemon", conn_proxy->dbus_daemon,
 			     "bus-name", conn_proxy->bus_name,
@@ -1365,9 +1332,13 @@ empathy_tp_chat_get_remote_contact (EmpathyTpChat *self)
 TpAccount *
 empathy_tp_chat_get_account (EmpathyTpChat *self)
 {
-	g_return_val_if_fail (EMPATHY_IS_TP_CHAT (self), NULL);
+  TpConnection *connection;
+
+  g_return_val_if_fail (EMPATHY_IS_TP_CHAT (self), NULL);
+
+  connection = tp_channel_borrow_connection (TP_CHANNEL (self));
 
-	return self->priv->account;
+  return tp_connection_get_account (connection);
 }
 
 void
diff --git a/libempathy/empathy-tp-chat.h b/libempathy/empathy-tp-chat.h
index 885479c..a7414ba 100644
--- a/libempathy/empathy-tp-chat.h
+++ b/libempathy/empathy-tp-chat.h
@@ -66,7 +66,6 @@ GType          empathy_tp_chat_get_type             (void) G_GNUC_CONST;
 
 EmpathyTpChat *empathy_tp_chat_new                  (
 						     TpSimpleClientFactory *factory,
-						     TpAccount *account,
 						     TpConnection *connection,
 						     const gchar *object_path,
 						     const GHashTable *immutable_properties);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]