summaryrefslogtreecommitdiff
path: root/common/gmounttracker.c
diff options
context:
space:
mode:
authorOndrej Holy <oholy@redhat.com>2017-01-04 10:31:08 +0100
committerOndrej Holy <oholy@redhat.com>2017-06-06 09:11:24 +0200
commitceb0daa48bd6b5144873a4984572c2781fa4a7ac (patch)
tree3ef72406e6e921caa0ba7441b6b08c2d8ec6708e /common/gmounttracker.c
parent29872122c87623c77a85869e309f79a50aed8e09 (diff)
downloadgvfs-ceb0daa48bd6b5144873a4984572c2781fa4a7ac.tar.gz
Do not sent user invisible mounts if not needed
g_volume_monitor_get() might be really slow if there is too many mounts, because the list of the mounts is send over D-Bus. It can simply happen due to user invisible mounts, e.g. http. User invisible mounts are ignored by the volume monitor, so it is useless to send them over D-Bus. Improve the D-Bus API and don't send the user invisible mounts if it is not needed. https://bugzilla.gnome.org/show_bug.cgi?id=775600
Diffstat (limited to 'common/gmounttracker.c')
-rw-r--r--common/gmounttracker.c45
1 files changed, 39 insertions, 6 deletions
diff --git a/common/gmounttracker.c b/common/gmounttracker.c
index 2356fe40..67898728 100644
--- a/common/gmounttracker.c
+++ b/common/gmounttracker.c
@@ -36,7 +36,8 @@ enum {
enum {
PROP_0,
- PROP_CONNECTION
+ PROP_CONNECTION,
+ PROP_USER_VISIBLE_ONLY
};
/* TODO: Real P_() */
@@ -53,6 +54,8 @@ struct _GMountTracker
GList *mounts;
GDBusConnection *connection;
GVfsDBusMountTracker *proxy;
+
+ gboolean user_visible_only;
};
G_DEFINE_TYPE (GMountTracker, g_mount_tracker, G_TYPE_OBJECT)
@@ -309,7 +312,15 @@ g_mount_tracker_class_init (GMountTrackerClass *klass)
P_("The dbus connection to use for ipc."),
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB));
-
+
+ g_object_class_install_property (gobject_class,
+ PROP_USER_VISIBLE_ONLY,
+ g_param_spec_boolean ("user-visible-only",
+ P_("User visible only"),
+ P_("User visible only"),
+ FALSE,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
}
static void
@@ -327,6 +338,9 @@ g_mount_tracker_set_property (GObject *object,
if (g_value_get_pointer (value))
tracker->connection = g_object_ref (g_value_get_pointer (value));
break;
+ case PROP_USER_VISIBLE_ONLY:
+ tracker->user_visible_only = g_value_get_boolean (value);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -346,6 +360,9 @@ g_mount_tracker_get_property (GObject *object,
case PROP_CONNECTION:
g_value_set_pointer (value, tracker->connection);
break;
+ case PROP_USER_VISIBLE_ONLY:
+ g_value_set_boolean (value, tracker->user_visible_only);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -380,6 +397,12 @@ g_mount_tracker_add_mount (GMountTracker *tracker,
return;
}
+ if (tracker->user_visible_only && !info->user_visible)
+ {
+ g_mutex_unlock (&tracker->lock);
+ return;
+ }
+
tracker->mounts = g_list_prepend (tracker->mounts, g_mount_info_ref (info));
g_mutex_unlock (&tracker->lock);
@@ -475,6 +498,7 @@ init_connection_sync (GMountTracker *tracker)
{
GError *error;
GVariant *iter_mounts;
+ gboolean res;
if (tracker->connection == NULL)
tracker->connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
@@ -497,7 +521,15 @@ init_connection_sync (GMountTracker *tracker)
g_dbus_proxy_set_default_timeout (G_DBUS_PROXY (tracker->proxy),
G_VFS_DBUS_TIMEOUT_MSECS);
- if (gvfs_dbus_mount_tracker_call_list_mounts_sync (tracker->proxy, &iter_mounts, NULL, NULL))
+ res = gvfs_dbus_mount_tracker_call_list_mounts2_sync (tracker->proxy, tracker->user_visible_only, &iter_mounts, NULL, &error);
+ if (!res)
+ {
+ if (g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD))
+ res = gvfs_dbus_mount_tracker_call_list_mounts_sync (tracker->proxy, &iter_mounts, NULL, NULL);
+ g_clear_error (&error);
+ }
+
+ if (res)
{
list_mounts_reply (tracker, iter_mounts);
g_variant_unref (iter_mounts);
@@ -534,12 +566,13 @@ g_mount_tracker_constructor (GType type,
}
GMountTracker *
-g_mount_tracker_new (GDBusConnection *connection)
+g_mount_tracker_new (GDBusConnection *connection,
+ gboolean user_visible_only)
{
GMountTracker *tracker;
- tracker = g_object_new (G_TYPE_MOUNT_TRACKER, "connection", connection, NULL);
-
+ tracker = g_object_new (G_TYPE_MOUNT_TRACKER, "connection", connection, "user_visible_only", user_visible_only, NULL);
+
return tracker;
}