[brasero] Speed up nautilus extension startup



commit 6685dd8aa1b4146973e805d56b86b559f36d1397
Author: Martin Pitt <martin pitt ubuntu com>
Date:   Tue Jan 5 13:08:46 2010 +0100

    Speed up nautilus extension startup
    
    Do not call brasero_*_start() at nautilus startup, they are very expensive (on
    my system it takes 3.1 seconds with a cold cache). Instead, call those lazily
    when needed. Now it starts up in less than 0.3 seconds.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=604084

 nautilus/nautilus-burn-extension.c |   46 ++++++++++++++++++++++++-----------
 1 files changed, 31 insertions(+), 15 deletions(-)
---
diff --git a/nautilus/nautilus-burn-extension.c b/nautilus/nautilus-burn-extension.c
index 213a1b8..e124c78 100644
--- a/nautilus/nautilus-burn-extension.c
+++ b/nautilus/nautilus-burn-extension.c
@@ -104,6 +104,29 @@ static GObjectClass *parent_class;
 //#define DEBUG_PRINT(format_MACRO,...)           g_print (format_MACRO, ##__VA_ARGS__);
 #define DEBUG_PRINT(format_MACRO,...)             
 
+/* do not call brasero_*_start() at nautilus startup, they are very expensive;
+ * lazily initialize those instead */
+static void
+ensure_initialized()
+{
+	static gboolean initialized = FALSE;
+	GConfClient *client;
+
+	if (!initialized) {
+		client = gconf_client_get_default ();
+		if (gconf_client_get_bool (client, "/apps/brasero/nautilus-extension-debug", NULL)) {
+		    brasero_media_library_set_debug (TRUE);
+		    brasero_burn_library_set_debug (TRUE);
+		}
+		g_object_unref (client);
+
+		brasero_media_library_start ();
+		brasero_burn_library_start (NULL, NULL);
+
+		DEBUG_PRINT ("Libbrasero-media started\n");
+		initialized = TRUE;
+	}
+}
 
 static void
 launch_brasero_on_window_session (BraseroSessionCfg	*session,
@@ -313,6 +336,8 @@ write_iso_activate_cb (NautilusMenuItem *item,
         NautilusFileInfo	*file_info;
         char			*uri;
 
+	ensure_initialized();
+
         file_info = g_object_get_data (G_OBJECT (item), "file_info");
         uri = nautilus_file_info_get_uri (file_info);
 
@@ -335,6 +360,8 @@ copy_disc_activate_cb (NautilusMenuItem *item,
 	BraseroTrackDisc	*track;
 	BraseroDrive		*drive;
 
+	ensure_initialized();
+
         device_path = g_object_get_data (G_OBJECT (item), "drive_device_path");
 	monitor = brasero_medium_monitor_get_default ();
 	drive = brasero_medium_monitor_get_drive (monitor, device_path);
@@ -392,6 +419,8 @@ blank_disc_activate_cb (NautilusMenuItem *item,
 {
 	BraseroBlankDialog *dialog;
 
+	ensure_initialized();
+
 	dialog = brasero_blank_dialog_new ();
 	tool_dialog_run (BRASERO_TOOL_DIALOG (dialog),
 			 GTK_WINDOW (user_data),
@@ -591,6 +620,8 @@ nautilus_disc_burn_get_file_items (NautilusMenuProvider *provider,
 		BraseroMedia		 media;
 		BraseroTrackType	*type;
 
+		ensure_initialized();
+
                 device_path = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE);
 		monitor = brasero_medium_monitor_get_default ();
 		bdrive = brasero_medium_monitor_get_drive (monitor, device_path);
@@ -985,22 +1016,7 @@ nautilus_disc_burn_register_type (GTypeModule *module)
 void
 nautilus_module_initialize (GTypeModule *module)
 {
-	GConfClient *client;
-
         DEBUG_PRINT ("Initializing nautilus-disc-recorder\n");
-
-	client = gconf_client_get_default ();
-	if (gconf_client_get_bool (client, "/apps/brasero/nautilus-extension-debug", NULL)) {
-		brasero_media_library_set_debug (TRUE);
-		brasero_burn_library_set_debug (TRUE);
-	}
-	g_object_unref (client);
-
-	brasero_media_library_start ();
-        brasero_burn_library_start (NULL, NULL);
-
-        DEBUG_PRINT ("Libbrasero-media started\n");
-
         nautilus_disc_burn_register_type (module);
 }
 



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