From 7d0e12d707e642031a529d10cfbb61acac559f77 Mon Sep 17 00:00:00 2001 From: "ccarlen%netscape.com" Date: Wed, 26 Feb 2003 15:01:19 +0000 Subject: [PATCH] Bug 188214 - Cookies are not getting saved on exit in GtkEmbed. This adds a new call to nsProfileDirServiceProvider which allows an app to shutdown the provider and it will send out profile shutdown notifications. r=dougt/sr=blizzard --- embedding/browser/gtk/src/EmbedPrivate.cpp | 12 ++++++++---- embedding/browser/gtk/src/EmbedPrivate.h | 2 ++ .../public/nsProfileDirServiceProvider.h | 10 ++++++++++ .../src/nsProfileDirServiceProvider.cpp | 16 ++++++++++++++++ 4 files changed, 36 insertions(+), 4 deletions(-) diff --git a/embedding/browser/gtk/src/EmbedPrivate.cpp b/embedding/browser/gtk/src/EmbedPrivate.cpp index b660aa6a55a..62de38496a0 100644 --- a/embedding/browser/gtk/src/EmbedPrivate.cpp +++ b/embedding/browser/gtk/src/EmbedPrivate.cpp @@ -78,6 +78,7 @@ nsIPref *EmbedPrivate::sPrefs = nsnull; GtkWidget *EmbedPrivate::sOffscreenWindow = 0; GtkWidget *EmbedPrivate::sOffscreenFixed = 0; nsIDirectoryServiceProvider *EmbedPrivate::sAppFileLocProvider = nsnull; +nsProfileDirServiceProvider *EmbedPrivate::sProfileDirServiceProvider = nsnull; EmbedPrivate::EmbedPrivate(void) { @@ -796,16 +797,14 @@ EmbedPrivate::StartupProfile(void) NS_NewProfileDirServiceProvider(PR_TRUE, getter_AddRefs(locProvider)); if (!locProvider) return NS_ERROR_FAILURE; - - // Directory service holds an strong reference to any - // provider that is registered with it. Let it hold the - // only ref. locProvider won't die when we leave this scope. rv = locProvider->Register(); if (NS_FAILED(rv)) return rv; rv = locProvider->SetProfileDir(profileDir); if (NS_FAILED(rv)) return rv; + // Keep a ref so we can shut it down. + NS_ADDREF(sProfileDirServiceProvider = locProvider); // get prefs nsCOMPtr pref; @@ -822,6 +821,11 @@ EmbedPrivate::StartupProfile(void) void EmbedPrivate::ShutdownProfile(void) { + if (sProfileDirServiceProvider) { + sProfileDirServiceProvider->Shutdown(); + NS_RELEASE(sProfileDirServiceProvider); + sProfileDirServiceProvider = 0; + } if (sPrefs) { NS_RELEASE(sPrefs); sPrefs = 0; diff --git a/embedding/browser/gtk/src/EmbedPrivate.h b/embedding/browser/gtk/src/EmbedPrivate.h index 1298b74fe1c..7aa9a27d939 100644 --- a/embedding/browser/gtk/src/EmbedPrivate.h +++ b/embedding/browser/gtk/src/EmbedPrivate.h @@ -46,6 +46,7 @@ class EmbedStream; class nsPIDOMWindow; class nsIDirectoryServiceProvider; +class nsProfileDirServiceProvider; class EmbedPrivate { @@ -134,6 +135,7 @@ class EmbedPrivate { static char *sProfileDir; static char *sProfileName; // for profiles + static nsProfileDirServiceProvider *sProfileDirServiceProvider; static nsIPref *sPrefs; static nsIDirectoryServiceProvider * sAppFileLocProvider; diff --git a/profile/dirserviceprovider/public/nsProfileDirServiceProvider.h b/profile/dirserviceprovider/public/nsProfileDirServiceProvider.h index ecad556311d..bc89f5d658d 100755 --- a/profile/dirserviceprovider/public/nsProfileDirServiceProvider.h +++ b/profile/dirserviceprovider/public/nsProfileDirServiceProvider.h @@ -79,6 +79,16 @@ public: virtual nsresult Register(); + /** + * Shutdown + * + * This method must be called before shutting down XPCOM if this object + * was created with aNotifyObservers == PR_TRUE. If this object was + * created with aNotifyObservers == PR_FALSE, this method is a no-op. + */ + + virtual nsresult Shutdown(); + protected: nsProfileDirServiceProvider(PRBool aNotifyObservers = PR_TRUE); virtual ~nsProfileDirServiceProvider(); diff --git a/profile/dirserviceprovider/src/nsProfileDirServiceProvider.cpp b/profile/dirserviceprovider/src/nsProfileDirServiceProvider.cpp index bb3dbbafc18..f1accf3018d 100755 --- a/profile/dirserviceprovider/src/nsProfileDirServiceProvider.cpp +++ b/profile/dirserviceprovider/src/nsProfileDirServiceProvider.cpp @@ -155,6 +155,22 @@ nsProfileDirServiceProvider::Register() return directoryService->RegisterProvider(this); } +nsresult +nsProfileDirServiceProvider::Shutdown() +{ + if (!mNotifyObservers) + return NS_OK; + + nsCOMPtr observerService = + do_GetService("@mozilla.org/observer-service;1"); + if (!observerService) + return NS_ERROR_FAILURE; + + NS_NAMED_LITERAL_STRING(context, "shutdown-persist"); + observerService->NotifyObservers(nsnull, "profile-before-change", context.get()); + return NS_OK; +} + //***************************************************************************** // nsProfileDirServiceProvider::nsISupports //*****************************************************************************