[epiphany] Allow for more fine-grained file helpers init



commit 3847db0803addac9f0b90dc86767d8f65768d4ad
Author: Xan Lopez <xan igalia com>
Date:   Mon May 7 20:27:33 2012 +0200

    Allow for more fine-grained file helpers init
    
    Since we are about to migrate our profile dir, allow file helpers init
    to not ensure the profile dir exists (it was hardcoded until now). For
    this we get rid of the ugly boolean parameters and add a flags
    parameter, which preserves the old behaviors and allows for this new
    option.
    
    We update all the callers in the tree.

 lib/ephy-file-helpers.c        |   17 ++++++++++-------
 lib/ephy-file-helpers.h        |   11 +++++++++--
 lib/ephy-profile-migrator.c    |    2 +-
 src/ephy-main.c                |   13 ++++++++++---
 tests/ephy-download-test.c     |    2 +-
 tests/ephy-embed-single-test.c |    2 +-
 tests/ephy-web-view-test.c     |    2 +-
 7 files changed, 33 insertions(+), 16 deletions(-)
---
diff --git a/lib/ephy-file-helpers.c b/lib/ephy-file-helpers.c
index 50e81f3..63f3c14 100644
--- a/lib/ephy-file-helpers.c
+++ b/lib/ephy-file-helpers.c
@@ -272,8 +272,7 @@ ephy_dot_dir (void)
 /**
  * ephy_file_helpers_init:
  * @profile_dir: directory to use as Epiphany's profile
- * @private_profile: %TRUE if we should use a private profile
- * @keep_temp_dir: %TRUE to omit deleting the temp dir on exit
+ * @flags: the %EphyFileHelpersFlags for this session
  * @error: an optional #GError
  *
  * Initializes Epiphany file helper functions, sets @profile_dir as Epiphany's
@@ -283,11 +282,11 @@ ephy_dot_dir (void)
  **/
 gboolean
 ephy_file_helpers_init (const char *profile_dir,
-			gboolean private_profile,
-			gboolean keep_temp_dir,
+			EphyFileHelpersFlags flags,
 			GError **error)
 {
 	const char *uuid;
+	gboolean private_profile;
 
 	/* See if we've been calling ourself, and abort if we have */
 	uuid = g_getenv (EPHY_UUID_ENVVAR);
@@ -307,7 +306,8 @@ ephy_file_helpers_init (const char *profile_dir,
 				       (GDestroyNotify) g_free,
 				       (GDestroyNotify) g_free);
 
-	keep_temp_directory = keep_temp_dir;
+	keep_temp_directory = flags & EPHY_FILE_HELPERS_KEEP_TEMP_DIR;
+	private_profile = flags & EPHY_FILE_HELPERS_PRIVATE_PROFILE;
 
 	if (private_profile && profile_dir != NULL)
 	{
@@ -336,8 +336,11 @@ ephy_file_helpers_init (const char *profile_dir,
 					    "epiphany",
 					    NULL);
 	}
-	
-	return ephy_ensure_dir_exists (ephy_dot_dir (), error);
+
+	if (flags & EPHY_FILE_HELPERS_ENSURE_EXISTS)
+		return ephy_ensure_dir_exists (ephy_dot_dir (), error);
+	else
+		return TRUE;
 }
 
 static void
diff --git a/lib/ephy-file-helpers.h b/lib/ephy-file-helpers.h
index 4cd270f..68a6db6 100644
--- a/lib/ephy-file-helpers.h
+++ b/lib/ephy-file-helpers.h
@@ -45,11 +45,18 @@ typedef enum
 	EPHY_MIME_PERMISSION_UNKNOWN	= 3
 } EphyMimePermission;
 
+typedef enum
+{
+	EPHY_FILE_HELPERS_NONE		   = 0,
+	EPHY_FILE_HELPERS_KEEP_TEMP_DIR	   = 1 << 1,
+	EPHY_FILE_HELPERS_PRIVATE_PROFILE  = 1 << 2,
+	EPHY_FILE_HELPERS_ENSURE_EXISTS	   = 1 << 3,
+} EphyFileHelpersFlags;
+
 #define EPHY_UUID_ENVVAR	"EPHY_UNIQUE"
 
 gboolean           ephy_file_helpers_init        (const char  *profile_dir,
-                                                  gboolean     private_profile,
-                                                  gboolean     keep_temp_dir,
+                                                  EphyFileHelpersFlags flags,
                                                   GError     **error);
 const char *       ephy_file                     (const char  *filename);
 const char *       ephy_dot_dir                  (void);
diff --git a/lib/ephy-profile-migrator.c b/lib/ephy-profile-migrator.c
index 2ab42c9..17b2692 100644
--- a/lib/ephy-profile-migrator.c
+++ b/lib/ephy-profile-migrator.c
@@ -670,7 +670,7 @@ main (int argc, char *argv[])
 
   ephy_debug_init ();
 
-  if (!ephy_file_helpers_init (NULL, FALSE, FALSE, NULL)) {
+  if (!ephy_file_helpers_init (NULL, EPHY_FILE_HELPERS_NONE, NULL)) {
     LOG ("Something wrong happened with ephy_file_helpers_init()");
     return -1;
   }
diff --git a/src/ephy-main.c b/src/ephy-main.c
index a9b71dd..328e506 100644
--- a/src/ephy-main.c
+++ b/src/ephy-main.c
@@ -26,6 +26,7 @@
 #include "ephy-embed-prefs.h"
 #include "ephy-file-helpers.h"
 #include "ephy-private.h"
+#include "ephy-profile-utils.h"
 #include "ephy-session.h"
 #include "ephy-settings.h"
 #include "ephy-shell.h"
@@ -245,6 +246,7 @@ main (int argc,
   EphyStartupFlags startup_flags;
   EphyEmbedShellMode mode;
   int status;
+  EphyFileHelpersFlags flags;
 
 #ifdef ENABLE_NLS
   /* Initialize the i18n stuff */
@@ -392,9 +394,14 @@ main (int argc,
     ephy_profile_utils_do_migration ();
 
   /* Start our services */
-  if (!ephy_file_helpers_init (profile_directory,
-                               private_instance || application_mode,
-                               keep_temp_directory || profile_directory,
+  flags = EPHY_FILE_HELPERS_ENSURE_EXISTS;
+
+  if (private_instance || application_mode)
+    flags |= EPHY_FILE_HELPERS_PRIVATE_PROFILE;
+  if (keep_temp_directory || profile_directory)
+    flags |= EPHY_FILE_HELPERS_KEEP_TEMP_DIR;
+
+  if (!ephy_file_helpers_init (profile_directory, flags,
                                &error)) {
     show_error_message (&error);
     exit (1);
diff --git a/tests/ephy-download-test.c b/tests/ephy-download-test.c
index b1c4171..3fd208a 100644
--- a/tests/ephy-download-test.c
+++ b/tests/ephy-download-test.c
@@ -166,7 +166,7 @@ main (int argc, char *argv[])
   ephy_embed_prefs_init ();
   _ephy_shell_create_instance (EPHY_EMBED_SHELL_MODE_PRIVATE);
 
-  if (!ephy_file_helpers_init (NULL, TRUE, FALSE, NULL)) {
+  if (!ephy_file_helpers_init (NULL, EPHY_FILE_HELPERS_PRIVATE_PROFILE, NULL)) {
     g_debug ("Something wrong happened with ephy_file_helpers_init()");
     return -1;
   }
diff --git a/tests/ephy-embed-single-test.c b/tests/ephy-embed-single-test.c
index d0891b0..f5e4b8e 100644
--- a/tests/ephy-embed-single-test.c
+++ b/tests/ephy-embed-single-test.c
@@ -87,7 +87,7 @@ main (int argc, char *argv[])
   ephy_embed_prefs_init ();
   _ephy_shell_create_instance (EPHY_EMBED_SHELL_MODE_PRIVATE);
 
-  if (!ephy_file_helpers_init (NULL, TRUE, FALSE, NULL)) {
+  if (!ephy_file_helpers_init (NULL, EPHY_FILE_HELPERS_PRIVATE_PROFILE, NULL)) {
     g_debug ("Something wrong happened with ephy_file_helpers_init()");
     return -1;
   }
diff --git a/tests/ephy-web-view-test.c b/tests/ephy-web-view-test.c
index 760ffff..ee2af1f 100644
--- a/tests/ephy-web-view-test.c
+++ b/tests/ephy-web-view-test.c
@@ -246,7 +246,7 @@ main (int argc, char *argv[])
   ephy_debug_init ();
   ephy_embed_prefs_init ();
 
-  if (!ephy_file_helpers_init (NULL, TRUE, FALSE, NULL)) {
+  if (!ephy_file_helpers_init (NULL, EPHY_FILE_HELPERS_PRIVATE_PROFILE, NULL)) {
     g_debug ("Something wrong happened with ephy_file_helpers_init()");
     return -1;
   }



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