[gnome-software/1722-flatpak-handle-more-well-known-filesystem-permissions: 10/10] epiphany-plugin: Share single GsAppPermissions object between all GsApp instances




commit 03db80087333fc0e9107e2d77ac264043195d93a
Author: Milan Crha <mcrha redhat com>
Date:   Wed Jun 22 22:12:59 2022 +0200

    epiphany-plugin: Share single GsAppPermissions object between all GsApp instances
    
    As all the GsApp-s have the same permissions, the object can be reused
    some memory saved. The shared object can be modified only in
    the gs_plugin_epiphany_init() and nowhere else.

 plugins/epiphany/gs-plugin-epiphany.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)
---
diff --git a/plugins/epiphany/gs-plugin-epiphany.c b/plugins/epiphany/gs-plugin-epiphany.c
index bccf38f5c..3e7698da0 100644
--- a/plugins/epiphany/gs-plugin-epiphany.c
+++ b/plugins/epiphany/gs-plugin-epiphany.c
@@ -61,6 +61,9 @@ struct _GsPluginEpiphany
        /* installed_apps_cached: whether the plugin cache has all installed apps */
        gboolean installed_apps_cached;
        GHashTable *url_id_map; /* (owned) (not nullable) (element-type utf8 utf8) */
+
+       /* default permissions, shared between all applications */
+       GsAppPermissions *permissions; /* (owned) (not nullable) */
 };
 
 G_DEFINE_TYPE (GsPluginEpiphany, gs_plugin_epiphany, GS_TYPE_PLUGIN)
@@ -312,6 +315,11 @@ gs_plugin_epiphany_shutdown_finish (GsPlugin      *plugin,
 static void
 gs_plugin_epiphany_init (GsPluginEpiphany *self)
 {
+       /* Re-used permissions by all GsApp instances; do not modify it out
+          of this place. */
+       self->permissions = gs_app_permissions_new ();
+       gs_app_permissions_set_flags (self->permissions, GS_APP_PERMISSIONS_FLAGS_NETWORK);
+
        /* set name of MetaInfo file */
        gs_plugin_set_appstream_id (GS_PLUGIN (self), "org.gnome.Software.Plugin.Epiphany");
 
@@ -347,6 +355,7 @@ gs_plugin_epiphany_finalize (GObject *object)
        GsPluginEpiphany *self = GS_PLUGIN_EPIPHANY (object);
 
        g_mutex_clear (&self->installed_apps_mutex);
+       g_clear_object (&self->permissions);
 
        G_OBJECT_CLASS (gs_plugin_epiphany_parent_class)->finalize (object);
 }
@@ -455,7 +464,6 @@ refine_app (GsPluginEpiphany    *self,
        { "stackedit.io", "Apache-2.0" },
        { "squoosh.app", "Apache-2.0" },
        };
-       g_autoptr(GsAppPermissions) permissions = NULL;
 
        g_return_if_fail (GS_IS_APP (app));
        g_return_if_fail (uri != NULL);
@@ -488,10 +496,8 @@ refine_app (GsPluginEpiphany    *self,
 
        gs_app_set_size_download (app, GS_SIZE_TYPE_VALID, 0);
 
-       permissions = gs_app_permissions_new ();
-       gs_app_permissions_set_flags (permissions, GS_APP_PERMISSIONS_FLAGS_NETWORK);
-       gs_app_permissions_seal (permissions);
-       gs_app_set_permissions (app, permissions);
+       /* Use the default permissions */
+       gs_app_set_permissions (app, self->permissions);
 
        if (gs_app_get_url (app, AS_URL_KIND_HOMEPAGE) == NULL)
                gs_app_set_url (app, AS_URL_KIND_HOMEPAGE, url);


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