From d265cec7f1255e279dfa7dd67463f754cecca679 Mon Sep 17 00:00:00 2001 From: "ccarlen%netscape.com" Date: Fri, 14 Feb 2003 00:32:57 +0000 Subject: [PATCH] Bug 193078 - cookies file loses entries if you switch to a new profile and then quit. r=mvl@exedo.nl/sr=darin/a=asa --- extensions/cookie/nsCookieManager.cpp | 2 +- extensions/cookie/nsCookieService.cpp | 11 +++-------- extensions/cookie/nsCookieService.h | 5 ----- extensions/cookie/nsCookies.cpp | 19 +++++-------------- extensions/cookie/nsCookies.h | 2 +- 5 files changed, 10 insertions(+), 29 deletions(-) diff --git a/extensions/cookie/nsCookieManager.cpp b/extensions/cookie/nsCookieManager.cpp index 6d279782f39b..379d2f7125df 100644 --- a/extensions/cookie/nsCookieManager.cpp +++ b/extensions/cookie/nsCookieManager.cpp @@ -123,7 +123,7 @@ nsresult nsCookieManager::Init() NS_IMETHODIMP nsCookieManager::RemoveAll(void) { ::COOKIE_RemoveAll(); - ::COOKIE_Write(nsnull); + ::COOKIE_Write(); return NS_OK; } diff --git a/extensions/cookie/nsCookieService.cpp b/extensions/cookie/nsCookieService.cpp index 58c48d0bb32c..300ba2400d45 100644 --- a/extensions/cookie/nsCookieService.cpp +++ b/extensions/cookie/nsCookieService.cpp @@ -80,18 +80,13 @@ nsresult nsCookieService::Init() COOKIE_RegisterPrefCallbacks(); nsresult rv; - // cache mDir - rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(mDir)); - if (NS_SUCCEEDED(rv)) { - COOKIE_Read(); - } + COOKIE_Read(); nsCOMPtr observerService = do_GetService("@mozilla.org/observer-service;1", &rv); if (observerService) { observerService->AddObserver(this, "profile-before-change", PR_TRUE); observerService->AddObserver(this, "profile-do-change", PR_TRUE); - observerService->AddObserver(this, "xpcom-shutdown", PR_TRUE); observerService->AddObserver(this, "cookieIcon", PR_FALSE); } @@ -214,9 +209,9 @@ NS_IMETHODIMP nsCookieService::Observe(nsISupports *aSubject, const char *aTopic if (!nsCRT::strcmp(aTopic, "profile-before-change")) { // The profile is about to change, // or is going away because the application is shutting down. - - COOKIE_Write(mDir); + COOKIE_Write(); COOKIE_RemoveAll(); + if (!nsCRT::strcmp(someData, NS_LITERAL_STRING("shutdown-cleanse").get())) COOKIE_DeletePersistentUserData(); } else if (!nsCRT::strcmp(aTopic, "profile-do-change")) { diff --git a/extensions/cookie/nsCookieService.h b/extensions/cookie/nsCookieService.h index 15f07448d5c5..0145928b7444 100644 --- a/extensions/cookie/nsCookieService.h +++ b/extensions/cookie/nsCookieService.h @@ -63,11 +63,6 @@ public: nsCookieService(); virtual ~nsCookieService(void); nsresult Init(); - -protected: - // cached IOService - nsCOMPtr mDir; - }; #endif /* nsCookieService_h__ */ diff --git a/extensions/cookie/nsCookies.cpp b/extensions/cookie/nsCookies.cpp index 0970c4e5fce7..dd36ab4b78eb 100644 --- a/extensions/cookie/nsCookies.cpp +++ b/extensions/cookie/nsCookies.cpp @@ -1750,7 +1750,7 @@ COOKIE_SetCookieStringFromHttp(nsIURI * curURL, nsIURI * firstURL, nsIPrompt *aP /* saves out the HTTP cookies to disk */ PUBLIC nsresult -COOKIE_Write(nsIFile* dir) { +COOKIE_Write() { if (!cookie_changed) { return NS_OK; } @@ -1758,19 +1758,10 @@ COOKIE_Write(nsIFile* dir) { time_t cur_date = get_current_time(); char date_string[36]; nsFileSpec dirSpec; - nsCOMPtr dirSpec0; nsresult rv; - if (dir == nsnull) { - rv = CKutil_ProfileDirectory(dirSpec); - if (NS_FAILED(rv)) { - return rv; - } - } else { - rv = NS_NewFileSpecFromIFile(dir, getter_AddRefs(dirSpec0)); - if (NS_FAILED(rv)) { - return rv; - } - rv = dirSpec0->GetFileSpec(&dirSpec); + rv = CKutil_ProfileDirectory(dirSpec); + if (NS_FAILED(rv)) { + return rv; } dirSpec += kCookiesFileName; PRBool ignored; @@ -2093,7 +2084,7 @@ COOKIE_Remove cookie_list->RemoveElementAt(count); deleteCookie((void*)cookie, nsnull); cookie_changed = PR_TRUE; - COOKIE_Write(nsnull); + COOKIE_Write(); break; } } diff --git a/extensions/cookie/nsCookies.h b/extensions/cookie/nsCookies.h index 6c64505ba8ac..2ee07f2710ef 100644 --- a/extensions/cookie/nsCookies.h +++ b/extensions/cookie/nsCookies.h @@ -51,7 +51,7 @@ class nsIPrompt; class nsIHttpChannel; extern nsresult COOKIE_Read(); -extern nsresult COOKIE_Write(nsIFile* dir); +extern nsresult COOKIE_Write(); extern nsresult COOKIE_Notify(); //XXX these should operate on |const char*| extern char * COOKIE_GetCookie(nsIURI * address);