Bug 552605 - Change "must validate if expired" to "must always validate" in the image cache, to fit with the spirit of the HTTP spec. r=jrmuizel f=bz
authorJoe Drew <joe@drew.ca>
Fri, 01 Jul 2011 13:03:35 -0400
changeset 72713 35aa54f107aca6a4de3ac98775c83f6694993d17
parent 72712 3a7f41ccc2267c45c15562a101fa7a94505b7e29
child 72714 188a959fc629bcd8d8411962e574067373bef438
push id159
push usereakhgari@mozilla.com
push dateTue, 16 Aug 2011 17:53:11 +0000
treeherdermozilla-beta@8786e3e49240 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel
bugs552605
milestone7.0a1
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
Bug 552605 - Change "must validate if expired" to "must always validate" in the image cache, to fit with the spirit of the HTTP spec. r=jrmuizel f=bz
modules/libpr0n/src/imgLoader.cpp
modules/libpr0n/src/imgLoader.h
modules/libpr0n/src/imgRequest.cpp
--- a/modules/libpr0n/src/imgLoader.cpp
+++ b/modules/libpr0n/src/imgLoader.cpp
@@ -396,17 +396,17 @@ static PRBool NewRequestAndEntry(nsIURI 
   // If file, force revalidation on expiration
   PRBool isFile;
   uri->SchemeIs("file", &isFile);
 
   *request = new imgRequest();
   if (!*request)
     return PR_FALSE;
 
-  *entry = new imgCacheEntry(*request, /* mustValidateIfExpired = */ isFile);
+  *entry = new imgCacheEntry(*request, /* mustValidate = */ isFile);
   if (!*entry) {
     delete *request;
     return PR_FALSE;
   }
 
   NS_ADDREF(*request);
   NS_ADDREF(*entry);
 
@@ -420,30 +420,33 @@ static PRBool ShouldRevalidateEntry(imgC
   PRBool bValidateEntry = PR_FALSE;
 
   if (aFlags & nsIRequest::LOAD_BYPASS_CACHE)
     return PR_FALSE;
 
   if (aFlags & nsIRequest::VALIDATE_ALWAYS) {
     bValidateEntry = PR_TRUE;
   }
+  else if (aEntry->GetMustValidate()) {
+    bValidateEntry = PR_TRUE;
+  }
   //
   // The cache entry has expired...  Determine whether the stale cache
   // entry can be used without validation...
   //
   else if (aHasExpired) {
     //
     // VALIDATE_NEVER and VALIDATE_ONCE_PER_SESSION allow stale cache
     // entries to be used unless they have been explicitly marked to
     // indicate that revalidation is necessary.
     //
     if (aFlags & (nsIRequest::VALIDATE_NEVER | 
                   nsIRequest::VALIDATE_ONCE_PER_SESSION)) 
     {
-      bValidateEntry = aEntry->GetMustValidateIfExpired();
+      bValidateEntry = PR_FALSE;
     }
     //
     // LOAD_FROM_CACHE allows a stale cache entry to be used... Otherwise,
     // the entry must be revalidated.
     //
     else if (!(aFlags & nsIRequest::LOAD_FROM_CACHE)) {
       bValidateEntry = PR_TRUE;
     }
@@ -521,22 +524,22 @@ static nsresult NewImageChannel(nsIChann
   return NS_OK;
 }
 
 static PRUint32 SecondsFromPRTime(PRTime prTime)
 {
   return PRUint32(PRInt64(prTime) / PRInt64(PR_USEC_PER_SEC));
 }
 
-imgCacheEntry::imgCacheEntry(imgRequest *request, PRBool mustValidateIfExpired /* = PR_FALSE */)
+imgCacheEntry::imgCacheEntry(imgRequest *request, PRBool mustValidate /* = PR_FALSE */)
  : mRequest(request),
    mDataSize(0),
    mTouchedTime(SecondsFromPRTime(PR_Now())),
    mExpiryTime(0),
-   mMustValidateIfExpired(mustValidateIfExpired),
+   mMustValidate(mustValidate),
    mEvicted(PR_FALSE),
    mHasNoProxies(PR_TRUE)
 {}
 
 imgCacheEntry::~imgCacheEntry()
 {
   LOG_FUNC(gImgLog, "imgCacheEntry::~imgCacheEntry()");
 }
--- a/modules/libpr0n/src/imgLoader.h
+++ b/modules/libpr0n/src/imgLoader.h
@@ -118,23 +118,23 @@ public:
     return mExpiryTime;
   }
   void SetExpiryTime(PRInt32 aExpiryTime)
   {
     mExpiryTime = aExpiryTime;
     Touch();
   }
 
-  PRBool GetMustValidateIfExpired() const
+  PRBool GetMustValidate() const
   {
-    return mMustValidateIfExpired;
+    return mMustValidate;
   }
-  void SetMustValidateIfExpired(PRBool aValidate)
+  void SetMustValidate(PRBool aValidate)
   {
-    mMustValidateIfExpired = aValidate;
+    mMustValidate = aValidate;
     Touch();
   }
 
   already_AddRefed<imgRequest> GetRequest() const
   {
     imgRequest *req = mRequest;
     NS_ADDREF(req);
     return req;
@@ -173,17 +173,17 @@ private: // data
   nsAutoRefCnt mRefCnt;
   NS_DECL_OWNINGTHREAD
 
   nsRefPtr<imgRequest> mRequest;
   PRUint32 mDataSize;
   PRInt32 mTouchedTime;
   PRInt32 mExpiryTime;
   nsExpirationState mExpirationState;
-  PRPackedBool mMustValidateIfExpired : 1;
+  PRPackedBool mMustValidate : 1;
   PRPackedBool mEvicted : 1;
   PRPackedBool mHasNoProxies : 1;
 };
 
 #include <vector>
 
 #define NS_IMGLOADER_CID \
 { /* 9f6a0d2e-1dd1-11b2-a5b8-951f13c846f7 */         \
--- a/modules/libpr0n/src/imgRequest.cpp
+++ b/modules/libpr0n/src/imgRequest.cpp
@@ -525,23 +525,18 @@ void imgRequest::SetCacheValidation(imgC
           // Expiration time defaults to 0. We set the expiration time on our
           // entry if it hasn't been set yet.
           if (aCacheEntry->GetExpiryTime() == 0)
             aCacheEntry->SetExpiryTime(expiration);
         }
       }
     }
 
-    //
-    // Determine whether the cache entry must be revalidated when it expires.
-    // If so, then the cache entry must *not* be used during HISTORY loads if
-    // it has expired.
-    //
+    // Determine whether the cache entry must be revalidated when we try to use it.
     // Currently, only HTTP specifies this information...
-    //
     nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(aRequest));
     if (httpChannel) {
       PRBool bMustRevalidate = PR_FALSE;
 
       httpChannel->IsNoStoreResponse(&bMustRevalidate);
 
       if (!bMustRevalidate) {
         httpChannel->IsNoCacheResponse(&bMustRevalidate);
@@ -556,17 +551,17 @@ void imgRequest::SetCacheValidation(imgC
           bMustRevalidate = PR_TRUE;
         }
       }
 
       // Cache entries default to not needing to validate. We ensure that
       // multiple calls to this function don't override an earlier decision to
       // validate by making validation a one-way decision.
       if (bMustRevalidate)
-        aCacheEntry->SetMustValidateIfExpired(bMustRevalidate);
+        aCacheEntry->SetMustValidate(bMustRevalidate);
     }
   }
 }
 
 nsresult
 imgRequest::LockImage()
 {
   return mImage->LockImage();