bug 585326 improve cookie logging
authorChristian Biesinger <cbiesinger@gmail.com>
Wed, 25 Aug 2010 11:32:01 +0200
changeset 51398 4a6ee9e82945e1750643a220d5d8f092947c3dff
parent 51397 973351678dee4e5eae752a22f75da23e3c19edc9
child 51399 403160bb08012ed3a3927413eec4c325a9e04de2
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs585326
milestone2.0b5pre
first release with
nightly linux32
4a6ee9e82945 / 4.0b5pre / 20100825030909 / files
nightly linux64
4a6ee9e82945 / 4.0b5pre / 20100825031957 / files
nightly mac
4a6ee9e82945 / 4.0b5pre / 20100825030526 / files
nightly win32
4a6ee9e82945 / 4.0b5pre / 20100825062325 / files
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
nightly linux32
nightly linux64
nightly mac
nightly win32
bug 585326 improve cookie logging r=dwitte a=jst
netwerk/cookie/nsCookieService.cpp
--- a/netwerk/cookie/nsCookieService.cpp
+++ b/netwerk/cookie/nsCookieService.cpp
@@ -218,20 +218,20 @@ struct nsEnumerationData
 #define GET_COOKIE PR_FALSE
 
 #ifdef PR_LOGGING
 static PRLogModuleInfo *sCookieLog = PR_NewLogModule("cookie");
 
 #define COOKIE_LOGFAILURE(a, b, c, d)    LogFailure(a, b, c, d)
 #define COOKIE_LOGSUCCESS(a, b, c, d, e) LogSuccess(a, b, c, d, e)
 
-#define COOKIE_LOGEVICTED(a)                   \
+#define COOKIE_LOGEVICTED(a, details)          \
   PR_BEGIN_MACRO                               \
     if (PR_LOG_TEST(sCookieLog, PR_LOG_DEBUG)) \
-      LogEvicted(a);                           \
+      LogEvicted(a, details);                  \
   PR_END_MACRO
 
 #define COOKIE_LOGSTRING(lvl, fmt)   \
   PR_BEGIN_MACRO                     \
     PR_LOG(sCookieLog, lvl, fmt);    \
     PR_LOG(sCookieLog, lvl, ("\n")); \
   PR_END_MACRO
 
@@ -314,19 +314,20 @@ LogSuccess(PRBool aSetCookie, nsIURI *aH
     PR_LOG(sCookieLog, PR_LOG_DEBUG,("replaces existing cookie: %s\n", aReplacing ? "true" : "false"));
 
   LogCookie(aCookie);
 
   PR_LOG(sCookieLog, PR_LOG_DEBUG,("\n"));
 }
 
 static void
-LogEvicted(nsCookie *aCookie)
+LogEvicted(nsCookie *aCookie, const char* details)
 {
   PR_LOG(sCookieLog, PR_LOG_DEBUG,("===== COOKIE EVICTED =====\n"));
+  PR_LOG(sCookieLog, PR_LOG_DEBUG,("%s\n", details));
 
   LogCookie(aCookie);
 
   PR_LOG(sCookieLog, PR_LOG_DEBUG,("\n"));
 }
 
 // inline wrappers to make passing in nsAFlatCStrings easier
 static inline void
@@ -2214,19 +2215,19 @@ nsCookieService::AddInternal(const nsCSt
     if (aCookie->Expiry() <= currentTime) {
       COOKIE_LOGFAILURE(SET_COOKIE, aHostURI, aCookieHeader, "cookie has already expired");
       return;
     }
 
     // check if we have to delete an old cookie.
     nsEnumerationData data(currentTime, LL_MAXINT);
     if (CountCookiesFromHostInternal(aBaseDomain, data) >= mMaxCookiesPerHost) {
-      // remove the oldest cookie from host
+      // remove the oldest cookie from the domain
       oldCookie = data.iter.Cookie();
-      COOKIE_LOGEVICTED(oldCookie);
+      COOKIE_LOGEVICTED(oldCookie, "Too many cookies for this domain");
       RemoveCookieFromList(data.iter);
 
       NotifyChanged(oldCookie, NS_LITERAL_STRING("deleted").get());
 
     } else if (mDBState->cookieCount >= ADD_TEN_PERCENT(mMaxNumberOfCookies)) {
       PRInt64 maxAge = aCurrentTimeInUsec - mDBState->cookieOldestTime;
       PRInt64 purgeAge = ADD_TEN_PERCENT(mCookiePurgeAge);
       if (maxAge >= purgeAge) {
@@ -2940,17 +2941,17 @@ purgeCookiesCallback(nsCookieEntry *aEnt
   mozIStorageBindingParamsArray *array = data.paramsArray;
   for (nsCookieEntry::IndexType i = 0; i < cookies.Length(); ) {
     nsListIter iter(aEntry, i);
     nsCookie *cookie = cookies[i];
 
     // check if the cookie has expired
     if (cookie->Expiry() <= data.currentTime) {
       data.removedList->AppendElement(cookie, PR_FALSE);
-      COOKIE_LOGEVICTED(cookie);
+      COOKIE_LOGEVICTED(cookie, "Cookie expired");
 
       // remove from list; do not increment our iterator
       gCookieService->RemoveCookieFromList(iter, array);
 
     } else {
       // check if the cookie is over the age limit
       if (cookie->LastAccessed() <= data.purgeTime) {
         data.purgeList.AppendElement(iter);
@@ -3017,17 +3018,17 @@ nsCookieService::PurgeCookies(PRInt64 aC
 
   // sort the list again, this time grouping cookies with a common entryclass
   // together, and with ascending index. this allows us to iterate backwards
   // over the list removing cookies, without having to adjust indexes as we go.
   purgeList.Sort(CompareCookiesByIndex());
   for (nsPurgeData::ArrayType::index_type i = purgeList.Length(); i--; ) {
     nsCookie *cookie = purgeList[i].Cookie();
     removedList->AppendElement(cookie, PR_FALSE);
-    COOKIE_LOGEVICTED(cookie);
+    COOKIE_LOGEVICTED(cookie, "Cookie expired or too old");
 
     RemoveCookieFromList(purgeList[i], paramsArray);
   }
 
   // Update the database if we have entries to purge.
   if (paramsArray) {
     PRUint32 length;
     paramsArray->GetLength(&length);