Followup for review comment in bug 608545. a=b7+
authorDan Witte <dwitte@mozilla.com>
Tue, 02 Nov 2010 10:46:19 -0700
changeset 56830 46a81506595f8e03894e743c276c762922948479
parent 56829 2a4571a9ef2a61e80ba553a971e0b2b8b60e7e3d
child 56832 b192fa5cfffc8ded1790eb8d10b7c5955cf53fc1
push idunknown
push userunknown
push dateunknown
reviewersb7
bugs608545
milestone2.0b8pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Followup for review comment in bug 608545. a=b7+
netwerk/cookie/nsCookieService.cpp
netwerk/cookie/nsCookieService.h
--- a/netwerk/cookie/nsCookieService.cpp
+++ b/netwerk/cookie/nsCookieService.cpp
@@ -1319,16 +1319,25 @@ nsCookieService::NotifyRejected(nsIURI *
 void
 nsCookieService::NotifyChanged(nsISupports     *aSubject,
                                const PRUnichar *aData)
 {
   if (mObserverService)
     mObserverService->NotifyObservers(aSubject, "cookie-changed", aData);
 }
 
+void
+nsCookieService::NotifyPurged(nsICookie2* aCookie)
+{
+  nsCOMPtr<nsIMutableArray> removedList =
+    do_CreateInstance(NS_ARRAY_CONTRACTID);
+  removedList->AppendElement(aCookie, PR_FALSE);
+  NotifyChanged(removedList, NS_LITERAL_STRING("batch-deleted").get());
+}
+
 /******************************************************************************
  * nsCookieService:
  * pref observer impl
  ******************************************************************************/
 
 void
 nsCookieService::PrefChanged(nsIPrefBranch *aPrefBranch)
 {
@@ -2331,21 +2340,17 @@ nsCookieService::AddInternal(const nsCSt
           "cookie has already expired");
         return;
       }
 
       // Remove the stale cookie and notify.
       RemoveCookieFromList(matchIter);
       COOKIE_LOGFAILURE(SET_COOKIE, aHostURI, aCookieHeader,
         "stale cookie was purged");
-
-      nsCOMPtr<nsIMutableArray> removedList =
-        do_CreateInstance(NS_ARRAY_CONTRACTID);
-      removedList->AppendElement(oldCookie, PR_FALSE);
-      NotifyChanged(removedList, NS_LITERAL_STRING("batch-deleted").get());
+      NotifyPurged(oldCookie);
 
       // We've done all we need to wrt removing and notifying the stale cookie.
       // From here on out, we pretend pretend it didn't exist, so that we
       // preserve expected notification semantics when adding the new cookie.
       foundCookie = PR_FALSE;
 
     } else {
       // If the old cookie is httponly, make sure we're not coming from script.
@@ -2384,21 +2389,17 @@ nsCookieService::AddInternal(const nsCSt
     if (entry && entry->GetCookies().Length() >= mMaxCookiesPerHost) {
       nsListIter iter;
       FindStaleCookie(entry, currentTime, iter);
       oldCookie = iter.Cookie();
 
       // remove the oldest cookie from the domain
       RemoveCookieFromList(iter);
       COOKIE_LOGEVICTED(oldCookie, "Too many cookies for this domain");
-
-      nsCOMPtr<nsIMutableArray> removedList =
-        do_CreateInstance(NS_ARRAY_CONTRACTID);
-      removedList->AppendElement(oldCookie, PR_FALSE);
-      NotifyChanged(removedList, NS_LITERAL_STRING("batch-deleted").get());
+      NotifyPurged(oldCookie);
 
     } else if (mDBState->cookieCount >= ADD_TEN_PERCENT(mMaxNumberOfCookies)) {
       PRInt64 maxAge = aCurrentTimeInUsec - mDBState->cookieOldestTime;
       PRInt64 purgeAge = ADD_TEN_PERCENT(mCookiePurgeAge);
       if (maxAge >= purgeAge) {
         // we're over both size and age limits by 10%; time to purge the table!
         // do this by:
         // 1) removing expired cookies;
--- a/netwerk/cookie/nsCookieService.h
+++ b/netwerk/cookie/nsCookieService.h
@@ -246,16 +246,17 @@ class nsCookieService : public nsICookie
     static PRBool                 CheckPath(nsCookieAttributes &aCookie, nsIURI *aHostURI);
     static PRBool                 GetExpiry(nsCookieAttributes &aCookie, PRInt64 aServerTime, PRInt64 aCurrentTime);
     void                          RemoveAllFromMemory();
     void                          PurgeCookies(PRInt64 aCurrentTimeInUsec);
     PRBool                        FindCookie(const nsCString& aBaseDomain, const nsAFlatCString &aHost, const nsAFlatCString &aName, const nsAFlatCString &aPath, nsListIter &aIter);
     static void                   FindStaleCookie(nsCookieEntry *aEntry, PRInt64 aCurrentTime, nsListIter &aIter);
     void                          NotifyRejected(nsIURI *aHostURI);
     void                          NotifyChanged(nsISupports *aSubject, const PRUnichar *aData);
+    void                          NotifyPurged(nsICookie2* aCookie);
 
   protected:
     // cached members.
     nsCOMPtr<nsIObserverService>     mObserverService;
     nsCOMPtr<nsICookiePermission>    mPermissionService;
     nsCOMPtr<mozIThirdPartyUtil>     mThirdPartyUtil;
     nsCOMPtr<nsIEffectiveTLDService> mTLDService;
     nsCOMPtr<nsIIDNService>          mIDNService;