shell-app: don't recreate a session proxy every time

Cache the connection inside the ShellAppRunningState structure instead.

https://bugzilla.gnome.org/show_bug.cgi?id=697207
This commit is contained in:
Cosimo Cecchi 2013-04-03 14:15:17 -04:00
parent 811ee1d989
commit b8830f4a09

View File

@ -42,7 +42,8 @@ typedef struct {
/* See GApplication documentation */ /* See GApplication documentation */
GDBusMenuModel *remote_menu; GDBusMenuModel *remote_menu;
GActionMuxer *muxer; GActionMuxer *muxer;
char * unique_bus_name; char *unique_bus_name;
GDBusConnection *session;
} ShellAppRunningState; } ShellAppRunningState;
/** /**
@ -554,7 +555,7 @@ shell_app_update_window_actions (ShellApp *app, MetaWindow *window)
actions = g_object_get_data (G_OBJECT (window), "actions"); actions = g_object_get_data (G_OBJECT (window), "actions");
if (actions == NULL) if (actions == NULL)
{ {
actions = G_ACTION_GROUP (g_dbus_action_group_get (g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL), actions = G_ACTION_GROUP (g_dbus_action_group_get (app->running_state->session,
meta_window_get_gtk_unique_bus_name (window), meta_window_get_gtk_unique_bus_name (window),
object_path)); object_path));
g_object_set_data_full (G_OBJECT (window), "actions", actions, g_object_unref); g_object_set_data_full (G_OBJECT (window), "actions", actions, g_object_unref);
@ -1218,6 +1219,8 @@ create_running_state (ShellApp *app)
app->running_state->workspace_switch_id = app->running_state->workspace_switch_id =
g_signal_connect (screen, "workspace-switched", G_CALLBACK(shell_app_on_ws_switch), app); g_signal_connect (screen, "workspace-switched", G_CALLBACK(shell_app_on_ws_switch), app);
app->running_state->session = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
g_assert (app->running_state->session != NULL);
app->running_state->muxer = g_action_muxer_new (); app->running_state->muxer = g_action_muxer_new ();
} }
@ -1244,7 +1247,6 @@ shell_app_update_app_menu (ShellApp *app,
{ {
const gchar *application_object_path; const gchar *application_object_path;
const gchar *app_menu_object_path; const gchar *app_menu_object_path;
GDBusConnection *session;
GDBusActionGroup *actions; GDBusActionGroup *actions;
application_object_path = meta_window_get_gtk_application_object_path (window); application_object_path = meta_window_get_gtk_application_object_path (window);
@ -1253,16 +1255,13 @@ shell_app_update_app_menu (ShellApp *app,
if (application_object_path == NULL || app_menu_object_path == NULL || unique_bus_name == NULL) if (application_object_path == NULL || app_menu_object_path == NULL || unique_bus_name == NULL)
return; return;
session = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
g_assert (session != NULL);
g_clear_pointer (&app->running_state->unique_bus_name, g_free); g_clear_pointer (&app->running_state->unique_bus_name, g_free);
app->running_state->unique_bus_name = g_strdup (unique_bus_name); app->running_state->unique_bus_name = g_strdup (unique_bus_name);
g_clear_object (&app->running_state->remote_menu); g_clear_object (&app->running_state->remote_menu);
app->running_state->remote_menu = g_dbus_menu_model_get (session, unique_bus_name, app_menu_object_path); app->running_state->remote_menu = g_dbus_menu_model_get (app->running_state->session, unique_bus_name, app_menu_object_path);
actions = g_dbus_action_group_get (session, unique_bus_name, application_object_path); actions = g_dbus_action_group_get (app->running_state->session, unique_bus_name, application_object_path);
g_action_muxer_insert (app->running_state->muxer, "app", G_ACTION_GROUP (actions)); g_action_muxer_insert (app->running_state->muxer, "app", G_ACTION_GROUP (actions));
g_object_unref (actions); g_object_unref (actions);
g_object_unref (session);
} }
} }
@ -1282,6 +1281,7 @@ unref_running_state (ShellAppRunningState *state)
g_clear_object (&state->remote_menu); g_clear_object (&state->remote_menu);
g_clear_object (&state->muxer); g_clear_object (&state->muxer);
g_clear_object (&state->session);
g_clear_pointer (&state->unique_bus_name, g_free); g_clear_pointer (&state->unique_bus_name, g_free);
g_clear_pointer (&state->remote_menu, g_free); g_clear_pointer (&state->remote_menu, g_free);