Fetch the Content-Length from the hash bag instead of directly from the channel. r=dwitte, a=betaN+
authorByron Milligan <bmilligan@mozilla.com>
Tue, 07 Sep 2010 15:39:28 -0700
changeset 52144 1633b8d8a184
parent 52143 4905e9c69a52
child 52146 75d2145d1bd3
push id15553
push userdwitte@mozilla.com
push dateTue, 07 Sep 2010 22:40:02 +0000
treeherdermozilla-central@1633b8d8a184 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdwitte, betaN
milestone2.0b6pre
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
Fetch the Content-Length from the hash bag instead of directly from the channel. r=dwitte, a=betaN+
netwerk/cache/nsCacheEntry.cpp
netwerk/protocol/http/nsHttpChannel.cpp
--- a/netwerk/cache/nsCacheEntry.cpp
+++ b/netwerk/cache/nsCacheEntry.cpp
@@ -57,16 +57,17 @@ nsCacheEntry::nsCacheEntry(nsCString *  
                            PRBool               streamBased,
                            nsCacheStoragePolicy storagePolicy)
     : mKey(key),
       mFetchCount(0),
       mLastFetched(0),
       mLastModified(0),
       mExpirationTime(nsICache::NO_EXPIRATION_TIME),
       mFlags(0),
+      mPredictedDataSize(-1),
       mDataSize(0),
       mCacheDevice(nsnull),
       mData(nsnull)
 {
     MOZ_COUNT_CTOR(nsCacheEntry);
     PR_INIT_CLIST(this);
     PR_INIT_CLIST(&mRequestQ);
     PR_INIT_CLIST(&mDescriptorQ);
--- a/netwerk/protocol/http/nsHttpChannel.cpp
+++ b/netwerk/protocol/http/nsHttpChannel.cpp
@@ -750,20 +750,30 @@ nsHttpChannel::CallOnStartRequest()
                 }
             }
         }
     }
 
     if (mResponseHead && mResponseHead->ContentCharset().IsEmpty())
         mResponseHead->SetContentCharset(mContentCharsetHint);
 
-    if (mResponseHead)
+    if (mResponseHead) {
         SetPropertyAsInt64(NS_CHANNEL_PROP_CONTENT_LENGTH,
                            mResponseHead->ContentLength());
-
+        // If we have a cache entry, set its predicted size to ContentLength to
+        // avoid caching an entry that will exceed the max size limit.
+        if (mCacheEntry) {
+            nsresult rv;
+            PRInt64 predictedDataSize = -1; // -1 in case GetAsInt64 fails.
+            GetPropertyAsInt64(NS_CHANNEL_PROP_CONTENT_LENGTH, 
+                               &predictedDataSize);
+            rv = mCacheEntry->SetPredictedDataSize(predictedDataSize);
+            if (NS_FAILED(rv)) return rv;
+        }
+    }
     // Allow consumers to override our content type
     if ((mLoadFlags & LOAD_CALL_CONTENT_SNIFFERS) &&
         gIOService->GetContentSniffers().Count() != 0) {
         // NOTE: We can have both a txn pump and a cache pump when the cache
         // content is partial. In that case, we need to read from the cache,
         // because that's the one that has the initial contents. If that fails
         // then give the transaction pump a shot.
 
@@ -2793,23 +2803,16 @@ nsHttpChannel::InitCacheEntry()
 
     // Set the expiration time for this cache entry
     rv = UpdateExpirationTime();
     if (NS_FAILED(rv)) return rv;
 
     rv = AddCacheEntryHeaders(mCacheEntry);
     if (NS_FAILED(rv)) return rv;
 
-    // set predicted size of entry so we do not store anything that will exceed
-    // the max entry size limit
-    PRInt64 predictedDataSize;
-    GetContentLength(&predictedDataSize);
-    rv = mCacheEntry->SetPredictedDataSize(predictedDataSize);
-    if (NS_FAILED(rv)) return rv;
-
     mInitedCacheEntry = PR_TRUE;
     return NS_OK;
 }
 
 
 nsresult
 nsHttpChannel::InitOfflineCacheEntry()
 {