diff options
author | Ondrej Holy <oholy@redhat.com> | 2017-01-04 10:31:08 +0100 |
---|---|---|
committer | Ondrej Holy <oholy@redhat.com> | 2017-06-06 09:11:24 +0200 |
commit | ceb0daa48bd6b5144873a4984572c2781fa4a7ac (patch) | |
tree | 3ef72406e6e921caa0ba7441b6b08c2d8ec6708e /common | |
parent | 29872122c87623c77a85869e309f79a50aed8e09 (diff) | |
download | gvfs-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')
-rw-r--r-- | common/gmounttracker.c | 45 | ||||
-rw-r--r-- | common/gmounttracker.h | 3 | ||||
-rw-r--r-- | common/org.gtk.vfs.xml | 4 |
3 files changed, 45 insertions, 7 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; } diff --git a/common/gmounttracker.h b/common/gmounttracker.h index cbd76f8b..67ae4828 100644 --- a/common/gmounttracker.h +++ b/common/gmounttracker.h @@ -79,7 +79,8 @@ void g_mount_info_apply_prefix (GMountInfo *info, GMountInfo * g_mount_info_from_dbus (GVariant *value); -GMountTracker *g_mount_tracker_new (GDBusConnection *connection); +GMountTracker *g_mount_tracker_new (GDBusConnection *connection, + gboolean user_visible_only); GList * g_mount_tracker_list_mounts (GMountTracker *tracker); GMountInfo * g_mount_tracker_find_by_mount_spec (GMountTracker *tracker, GMountSpec *mount_spec); diff --git a/common/org.gtk.vfs.xml b/common/org.gtk.vfs.xml index 5030bb5f..5257c8a7 100644 --- a/common/org.gtk.vfs.xml +++ b/common/org.gtk.vfs.xml @@ -82,6 +82,10 @@ <method name="ListMounts"> <arg type='a(sossssssbay(aya{sv})ay)' name='mounts' direction='out'/> </method> + <method name="ListMounts2"> + <arg type='b' name='user_visible_only' direction='in'/> + <arg type='a(sossssssbay(aya{sv})ay)' name='mounts' direction='out'/> + </method> <method name="RegisterMount"> <arg type='o' name='obj_path' direction='in'/> <arg type='s' name='display_name' direction='in'/> |