Backout changesets 79a36ed03e14, d17ac9b0254e due to suspect xpcshell permaorange on OSX opt
authorMarco Bonardo <mbonardo@mozilla.com>
Fri, 22 Jul 2011 14:35:41 +0200
changeset 74243 b6514fd7c26de30db01db69603f2f2f265ee79cc
parent 74242 590784923cf77f97e32b592b04e45c812e65bf49
child 74244 037dee4ee39fe7248a802fcfee43f20a9011e5d8
push id67
push userclegnitto@mozilla.com
push dateFri, 04 Nov 2011 22:39:41 +0000
treeherdermozilla-release@04778346a3b0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
milestone8.0a1
backs out79a36ed03e143a4151c2a66c0fa9dbaef654a150
d17ac9b0254e79e0a0390c8309db0433fe8bfa46
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
Backout changesets 79a36ed03e14, d17ac9b0254e due to suspect xpcshell permaorange on OSX opt
mobile/app/mobile.js
modules/libpref/src/init/all.js
netwerk/cache/nsCacheEntryDescriptor.cpp
netwerk/cache/nsCacheEntryDescriptor.h
netwerk/cache/nsCacheService.cpp
netwerk/cache/nsCacheService.h
netwerk/cache/nsICacheEntryDescriptor.idl
netwerk/protocol/about/nsAboutCacheEntry.cpp
netwerk/protocol/http/nsHttpChannel.cpp
netwerk/test/unit/test_compressappend.js
netwerk/test/unit/xpcshell.ini
--- a/mobile/app/mobile.js
+++ b/mobile/app/mobile.js
@@ -93,19 +93,16 @@ pref("image.cache.size", 1048576); // by
 
 /* offline cache prefs */
 pref("browser.offline-apps.notify", true);
 pref("browser.cache.offline.enable", true);
 pref("browser.cache.offline.capacity", 5120); // kilobytes
 pref("offline-apps.quota.max", 2048); // kilobytes
 pref("offline-apps.quota.warn", 1024); // kilobytes
 
-/* zlib compression level used for cache compression */
-pref("browser.cache.compression_level", 1);
-
 /* protocol warning prefs */
 pref("network.protocol-handler.warn-external.tel", false);
 pref("network.protocol-handler.warn-external.mailto", false);
 pref("network.protocol-handler.warn-external.vnd.youtube", false);
 
 /* http prefs */
 pref("network.http.pipelining", true);
 pref("network.http.pipelining.ssl", true);
--- a/modules/libpref/src/init/all.js
+++ b/modules/libpref/src/init/all.js
@@ -87,22 +87,16 @@ pref("browser.cache.offline.capacity",  
 // offline apps should be limited to this much data in global storage
 // (in kilobytes)
 pref("offline-apps.quota.max",        204800);
 
 // the user should be warned if offline app disk usage exceeds this amount
 // (in kilobytes)
 pref("offline-apps.quota.warn",        51200);
 
-// zlib compression level used for cache compression:
-// 0 => disable compression
-// 1 => best speed
-// 9 => best compression
-pref("browser.cache.compression_level", 5);
-
 // Whether or not indexedDB is enabled.
 pref("dom.indexedDB.enabled", true);
 // Space to allow indexedDB databases before prompting (in MB).
 pref("dom.indexedDB.warningQuota", 50);
 
 // Whether window.performance is enabled
 pref("dom.enable_performance", true);
 
--- a/netwerk/cache/nsCacheEntryDescriptor.cpp
+++ b/netwerk/cache/nsCacheEntryDescriptor.cpp
@@ -42,19 +42,16 @@
 #include "nsCache.h"
 #include "nsCacheService.h"
 #include "nsCacheEntryDescriptor.h"
 #include "nsCacheEntry.h"
 #include "nsReadableUtils.h"
 #include "nsIOutputStream.h"
 #include "nsCRT.h"
 
-#define kMinDecompressReadBufLen 1024
-#define kMinCompressWriteBufLen  1024
-
 NS_IMPL_THREADSAFE_ISUPPORTS2(nsCacheEntryDescriptor,
                               nsICacheEntryDescriptor,
                               nsICacheEntryInfo)
 
 nsCacheEntryDescriptor::nsCacheEntryDescriptor(nsCacheEntry * entry,
                                                nsCacheAccessMode accessGranted)
     : mCacheEntry(entry),
       mAccessGranted(accessGranted),
@@ -211,35 +208,17 @@ NS_IMETHODIMP nsCacheEntryDescriptor::Se
 }
 
 NS_IMETHODIMP nsCacheEntryDescriptor::GetDataSize(PRUint32 *result)
 {
     NS_ENSURE_ARG_POINTER(result);
     nsCacheServiceAutoLock lock;
     if (!mCacheEntry)  return NS_ERROR_NOT_AVAILABLE;
 
-    const char* val = mCacheEntry->GetMetaDataElement("uncompressed-len");
-    if (!val) {
-        *result = mCacheEntry->DataSize();
-    } else {
-        *result = atol(val);
-    }
-
-    return NS_OK;
-}
-
-
-NS_IMETHODIMP nsCacheEntryDescriptor::GetStorageDataSize(PRUint32 *result)
-{
-    NS_ENSURE_ARG_POINTER(result);
-    nsCacheServiceAutoLock lock;
-    if (!mCacheEntry)  return NS_ERROR_NOT_AVAILABLE;
-
     *result = mCacheEntry->DataSize();
-
     return NS_OK;
 }
 
 
 nsresult
 nsCacheEntryDescriptor::RequestDataSizeChange(PRInt32 deltaSize)
 {
     nsCacheServiceAutoLock lock;
@@ -292,24 +271,18 @@ nsCacheEntryDescriptor::OpenInputStream(
         if (!mCacheEntry)                  return NS_ERROR_NOT_AVAILABLE;
         if (!mCacheEntry->IsStreamData())  return NS_ERROR_CACHE_DATA_IS_NOT_STREAM;
 
         // ensure valid permissions
         if (!(mAccessGranted & nsICache::ACCESS_READ))
             return NS_ERROR_CACHE_READ_ACCESS_DENIED;
     }
 
-    nsInputStreamWrapper* cacheInput = nsnull;
-    const char *val;
-    val = mCacheEntry->GetMetaDataElement("uncompressed-len");
-    if (val) {
-        cacheInput = new nsDecompressInputStreamWrapper(this, offset);
-    } else {
-        cacheInput = new nsInputStreamWrapper(this, offset);
-    }
+    nsInputStreamWrapper* cacheInput =
+        new nsInputStreamWrapper(this, offset);
     if (!cacheInput) return NS_ERROR_OUT_OF_MEMORY;
 
     NS_ADDREF(*result = cacheInput);
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsCacheEntryDescriptor::OpenOutputStream(PRUint32 offset, nsIOutputStream ** result)
@@ -321,25 +294,18 @@ nsCacheEntryDescriptor::OpenOutputStream
         if (!mCacheEntry)                  return NS_ERROR_NOT_AVAILABLE;
         if (!mCacheEntry->IsStreamData())  return NS_ERROR_CACHE_DATA_IS_NOT_STREAM;
 
         // ensure valid permissions
         if (!(mAccessGranted & nsICache::ACCESS_WRITE))
             return NS_ERROR_CACHE_WRITE_ACCESS_DENIED;
     }
 
-    nsOutputStreamWrapper* cacheOutput = nsnull;
-    PRInt32 compressionLevel = nsCacheService::CacheCompressionLevel();
-    const char *val;
-    val = mCacheEntry->GetMetaDataElement("uncompressed-len");
-    if ((compressionLevel > 0) && val) {
-        cacheOutput = new nsCompressOutputStreamWrapper(this, offset);
-    } else {
-        cacheOutput = new nsOutputStreamWrapper(this, offset);
-    }
+    nsOutputStreamWrapper* cacheOutput =
+        new nsOutputStreamWrapper(this, offset);
     if (!cacheOutput) return NS_ERROR_OUT_OF_MEMORY;
 
     NS_ADDREF(*result = cacheOutput);
     return NS_OK;
 }
 
 
 NS_IMETHODIMP
@@ -541,17 +507,17 @@ nsCacheEntryDescriptor::VisitMetaData(ns
     NS_ENSURE_ARG_POINTER(visitor);
     if (!mCacheEntry)  return NS_ERROR_NOT_AVAILABLE;
 
     return mCacheEntry->VisitMetaDataElements(visitor);
 }
 
 
 /******************************************************************************
- * nsCacheInputStream - a wrapper for nsIInputStream keeps the cache entry
+ * nsCacheInputStream - a wrapper for nsIInputstream keeps the cache entry
  *                      open while referenced.
  ******************************************************************************/
 
 NS_IMPL_THREADSAFE_ISUPPORTS1(nsCacheEntryDescriptor::nsInputStreamWrapper,
                               nsIInputStream)
 
 nsresult nsCacheEntryDescriptor::
 nsInputStreamWrapper::LazyInit()
@@ -616,145 +582,19 @@ nsInputStreamWrapper::IsNonBlocking(PRBo
 {
     // cache streams will never return NS_BASE_STREAM_WOULD_BLOCK
     *result = PR_FALSE;
     return NS_OK;
 }
 
 
 /******************************************************************************
- * nsDecompressInputStreamWrapper - an input stream wrapper that decompresses
- ******************************************************************************/
-
-NS_IMPL_THREADSAFE_ISUPPORTS1(nsCacheEntryDescriptor::nsDecompressInputStreamWrapper,
-                              nsIInputStream)
-
-NS_IMETHODIMP nsCacheEntryDescriptor::
-nsDecompressInputStreamWrapper::Read(char *    buf, 
-                                     PRUint32  count, 
-                                     PRUint32 *countRead)
-{
-    int zerr = Z_OK;
-    nsresult rv = NS_OK;
-
-    if (!mStreamInitialized) {
-        rv = InitZstream();
-        if (NS_FAILED(rv)) {
-            return rv;
-        }
-    }
-
-    mZstream.next_out = (Bytef*)buf;
-    mZstream.avail_out = count;
-
-    if (mReadBufferLen < count) {
-        // Allocate a buffer for reading from the input stream. This will
-        // determine the max number of compressed bytes read from the
-        // input stream at one time. Making the buffer size proportional
-        // to the request size is not necessary, but helps minimize the
-        // number of read requests to the input stream.
-        PRUint32 newBufLen = NS_MAX(count, (PRUint32)kMinDecompressReadBufLen);
-        unsigned char* newBuf;
-        newBuf = (unsigned char*)nsMemory::Realloc(mReadBuffer, 
-            newBufLen);
-        if (newBuf) {
-            mReadBuffer = newBuf;
-            mReadBufferLen = newBufLen;
-        }
-        if (!mReadBuffer) {
-            mReadBufferLen = 0;
-            return NS_ERROR_OUT_OF_MEMORY;
-        }
-    }
-
-    // read and inflate data until the output buffer is full, or
-    // there is no more data to read
-    while (NS_SUCCEEDED(rv) &&
-           zerr == Z_OK && 
-           mZstream.avail_out > 0 &&
-           count > 0) {
-        if (mZstream.avail_in == 0) {
-            rv = nsInputStreamWrapper::Read((char*)mReadBuffer, 
-                                            mReadBufferLen, 
-                                            &mZstream.avail_in);
-            if (NS_FAILED(rv) || !mZstream.avail_in) {
-                break;
-            }
-            mZstream.next_in = mReadBuffer;
-        }
-        zerr = inflate(&mZstream, Z_NO_FLUSH);
-        if (zerr == Z_STREAM_END) {
-            // The compressed data may have been stored in multiple
-            // chunks/streams. To allow for this case, re-initialize 
-            // the inflate stream and continue decompressing from 
-            // the next byte.
-            Bytef * saveNextIn = mZstream.next_in;
-            unsigned int saveAvailIn = mZstream.avail_in;
-            Bytef * saveNextOut = mZstream.next_out;
-            unsigned int saveAvailOut = mZstream.avail_out;
-            inflateReset(&mZstream);
-            mZstream.next_in = saveNextIn;
-            mZstream.avail_in = saveAvailIn;
-            mZstream.next_out = saveNextOut;
-            mZstream.avail_out = saveAvailOut;
-            zerr = Z_OK;
-        } else if (zerr != Z_OK) {
-            rv = NS_ERROR_INVALID_CONTENT_ENCODING;
-        }
-    }
-    if (NS_SUCCEEDED(rv)) {
-        *countRead = count - mZstream.avail_out;
-    }
-    return rv;
-}
-
-nsresult nsCacheEntryDescriptor::
-nsDecompressInputStreamWrapper::Close()
-{
-    EndZstream();
-    if (mReadBuffer) {
-        nsMemory::Free(mReadBuffer);
-        mReadBuffer = 0;
-        mReadBufferLen = 0;
-    }
-    return nsInputStreamWrapper::Close();
-}
-
-nsresult nsCacheEntryDescriptor::
-nsDecompressInputStreamWrapper::InitZstream()
-{
-    // Initialize zlib inflate stream
-    mZstream.zalloc = Z_NULL;
-    mZstream.zfree = Z_NULL;
-    mZstream.opaque = Z_NULL;
-    mZstream.next_out = Z_NULL;
-    mZstream.avail_out = 0;
-    mZstream.next_in = Z_NULL;
-    mZstream.avail_in = 0;
-    if (inflateInit(&mZstream) != Z_OK) {
-        return NS_ERROR_FAILURE;
-    }
-    mStreamInitialized = PR_TRUE;
-    return NS_OK;
-}
-
-nsresult nsCacheEntryDescriptor::
-nsDecompressInputStreamWrapper::EndZstream()
-{
-    if (mStreamInitialized && !mStreamEnded) {
-        inflateEnd(&mZstream);
-        mStreamEnded = PR_TRUE;
-    }
-    return NS_OK;
-}
-
-/******************************************************************************
- * nsOutputStreamWrapper - a wrapper for nsIOutputstream to track the amount of
- *                         data written to a cache entry.
- *                       - also keeps the cache entry open while referenced.
+ * nsCacheOutputStream - a wrapper for nsIOutputstream to track the amount of
+ *                       data written to a cache entry.
+ *                     - also keeps the cache entry open while referenced.
  ******************************************************************************/
 
 NS_IMPL_THREADSAFE_ISUPPORTS1(nsCacheEntryDescriptor::nsOutputStreamWrapper,
                               nsIOutputStream)
 
 nsresult nsCacheEntryDescriptor::
 nsOutputStreamWrapper::LazyInit()
 {
@@ -859,148 +699,8 @@ nsOutputStreamWrapper::WriteSegments(nsR
 
 NS_IMETHODIMP nsCacheEntryDescriptor::
 nsOutputStreamWrapper::IsNonBlocking(PRBool *result)
 {
     // cache streams will never return NS_BASE_STREAM_WOULD_BLOCK
     *result = PR_FALSE;
     return NS_OK;
 }
-
-/******************************************************************************
- * nsCompressOutputStreamWrapper - an output stream wrapper that compresses
- *   data before it is written
- ******************************************************************************/
-
-NS_IMPL_THREADSAFE_ISUPPORTS1(nsCacheEntryDescriptor::nsCompressOutputStreamWrapper,
-                              nsIOutputStream)
-
-NS_IMETHODIMP nsCacheEntryDescriptor::
-nsCompressOutputStreamWrapper::Write(const char * buf,
-                                     PRUint32     count,
-                                     PRUint32 *   result)
-{
-    int zerr = Z_OK;
-    nsresult rv = NS_OK;
-
-    if (!mStreamInitialized) {
-        rv = InitZstream();
-        if (NS_FAILED(rv)) {
-            return rv;
-        }
-    }
-
-    if (!mWriteBuffer) {
-        // Once allocated, this buffer is referenced by the zlib stream and
-        // cannot be grown. We use 2x(initial write request) to approximate
-        // a stream buffer size proportional to request buffers.
-        mWriteBufferLen = NS_MAX(count*2, (PRUint32)kMinCompressWriteBufLen);
-        mWriteBuffer = (unsigned char*)nsMemory::Alloc(mWriteBufferLen);
-        if (!mWriteBuffer) {
-            mWriteBufferLen = 0;
-            return NS_ERROR_OUT_OF_MEMORY;
-        }
-        mZstream.next_out = mWriteBuffer;
-        mZstream.avail_out = mWriteBufferLen;
-    }
-
-    // Compress (deflate) the requested buffer. Keep going
-    // until the entire buffer has been deflated.
-    mZstream.avail_in = count;
-    mZstream.next_in = (Bytef*)buf;
-    while (mZstream.avail_in > 0) {
-        zerr = deflate(&mZstream, Z_NO_FLUSH);
-        if (zerr == Z_STREAM_ERROR) {
-            return NS_ERROR_FAILURE;
-        }
-        // Note: Z_BUF_ERROR is non-fatal and sometimes expected here.
-
-        // If the compression stream output buffer is filled, write
-        // it out to the underlying stream wrapper.
-        if (mZstream.avail_out == 0) {
-            rv = WriteBuffer();
-            if (NS_FAILED(rv)) {
-                return rv;
-            }
-        }
-    }
-    *result = count;
-    mUncompressedCount += *result;
-    return NS_OK;
-}
-
-NS_IMETHODIMP nsCacheEntryDescriptor::
-nsCompressOutputStreamWrapper::Close()
-{
-    nsresult rv = NS_OK;
-    int zerr = 0;
-
-    if (mStreamInitialized) {
-        // complete compression of any data remaining in the zlib stream
-        do {
-            zerr = deflate(&mZstream, Z_FINISH);
-            rv = WriteBuffer();
-        } while (zerr == Z_OK && rv == NS_OK);
-        deflateEnd(&mZstream);
-    }
-
-    if (mDescriptor->CacheEntry()) {
-        nsCAutoString uncompressedLenStr;
-        rv = mDescriptor->GetMetaDataElement("uncompressed-len",
-                                             getter_Copies(uncompressedLenStr));
-        if (NS_SUCCEEDED(rv)) {
-            PRInt32 oldCount = uncompressedLenStr.ToInteger(&rv);
-            if (NS_SUCCEEDED(rv)) {
-                mUncompressedCount += oldCount;
-            }
-        }
-        uncompressedLenStr.Adopt(0);
-        uncompressedLenStr.AppendInt(mUncompressedCount);
-        rv = mDescriptor->SetMetaDataElement("uncompressed-len",
-            uncompressedLenStr.get());
-    }
-
-    if (mWriteBuffer) {
-        nsMemory::Free(mWriteBuffer);
-        mWriteBuffer = 0;
-        mWriteBufferLen = 0;
-    }
-
-    return nsOutputStreamWrapper::Close();
-}
-
-nsresult nsCacheEntryDescriptor::
-nsCompressOutputStreamWrapper::InitZstream()
-{
-    // Determine compression level: Aggressive compression
-    // may impact performance on mobile devices, while a
-    // lower compression level still provides substantial
-    // space savings for many text streams.
-    PRInt32 compressionLevel = nsCacheService::CacheCompressionLevel();
-
-    // Initialize zlib deflate stream
-    mZstream.zalloc = Z_NULL;
-    mZstream.zfree = Z_NULL;
-    mZstream.opaque = Z_NULL;
-    if (deflateInit2(&mZstream, compressionLevel, Z_DEFLATED,
-                     MAX_WBITS, 8, Z_DEFAULT_STRATEGY) != Z_OK) {
-        return NS_ERROR_FAILURE;
-    }
-    mZstream.next_in = Z_NULL;
-    mZstream.avail_in = 0;
-
-    mStreamInitialized = PR_TRUE;
-
-    return NS_OK;
-}
-
-nsresult nsCacheEntryDescriptor::
-nsCompressOutputStreamWrapper::WriteBuffer()
-{
-    PRUint32 bytesToWrite = mWriteBufferLen - mZstream.avail_out;
-    PRUint32 result = 0;
-    nsresult rv = nsCacheEntryDescriptor::nsOutputStreamWrapper::Write(
-        (const char *)mWriteBuffer, bytesToWrite, &result);
-    mZstream.next_out = mWriteBuffer;
-    mZstream.avail_out = mWriteBufferLen;
-    return rv;
-}
-
--- a/netwerk/cache/nsCacheEntryDescriptor.h
+++ b/netwerk/cache/nsCacheEntryDescriptor.h
@@ -43,17 +43,16 @@
 #define _nsCacheEntryDescriptor_h_
 
 #include "nsICacheEntryDescriptor.h"
 #include "nsCacheEntry.h"
 #include "nsIInputStream.h"
 #include "nsIOutputStream.h"
 #include "nsCacheService.h"
 #include "nsIDiskCacheStreamInternal.h"
-#include "zlib.h"
 
 /******************************************************************************
 * nsCacheEntryDescriptor
 *******************************************************************************/
 class nsCacheEntryDescriptor :
     public PRCList,
     public nsICacheEntryDescriptor
 {
@@ -125,55 +124,24 @@ private:
 
      private:
          nsresult LazyInit();
          nsresult EnsureInit() { return mInitialized ? NS_OK : LazyInit(); }
      };
      friend class nsInputStreamWrapper;
 
 
-     class nsDecompressInputStreamWrapper : public nsInputStreamWrapper {
-     private:
-         unsigned char* mReadBuffer;
-         PRUint32 mReadBufferLen;
-         z_stream mZstream;
-         PRBool mStreamInitialized;
-         PRBool mStreamEnded;
-     public:
-         NS_DECL_ISUPPORTS
-
-         nsDecompressInputStreamWrapper(nsCacheEntryDescriptor * desc, 
-                                      PRUint32 off)
-          : nsInputStreamWrapper(desc, off)
-          , mReadBuffer(0)
-          , mReadBufferLen(0)
-          , mStreamInitialized(PR_FALSE)
-          , mStreamEnded(PR_FALSE)
-         {
-         }
-         virtual ~nsDecompressInputStreamWrapper()
-         { 
-             Close();
-         }
-         NS_IMETHOD Read(char* buf, PRUint32 count, PRUint32 * result);
-         NS_IMETHOD Close();
-     private:
-         nsresult InitZstream();
-         nsresult EndZstream();
-     };
-
-
      /*************************************************************************
       * output stream wrapper class -
       *
       * The output stream wrapper references the descriptor, but the descriptor
       * doesn't need any references to the stream wrapper.
       *************************************************************************/
      class nsOutputStreamWrapper : public nsIOutputStream {
-     protected:
+     private:
          nsCacheEntryDescriptor *    mDescriptor;
          nsCOMPtr<nsIOutputStream>   mOutput;
          PRUint32                    mStartOffset;
          PRBool                      mInitialized;
      public:
          NS_DECL_ISUPPORTS
          NS_DECL_NSIOUTPUTSTREAM
 
@@ -197,46 +165,16 @@ private:
 
      private:
          nsresult LazyInit();
          nsresult EnsureInit() { return mInitialized ? NS_OK : LazyInit(); }
          nsresult OnWrite(PRUint32 count);
      };
      friend class nsOutputStreamWrapper;
 
-     class nsCompressOutputStreamWrapper : public nsOutputStreamWrapper {
-     private:
-         unsigned char* mWriteBuffer;
-         PRUint32 mWriteBufferLen;
-         z_stream mZstream;
-         PRBool mStreamInitialized;
-         PRUint32 mUncompressedCount;
-     public:
-         NS_DECL_ISUPPORTS
-
-         nsCompressOutputStreamWrapper(nsCacheEntryDescriptor * desc, 
-                                       PRUint32 off)
-          : nsOutputStreamWrapper(desc, off)
-          , mWriteBuffer(0)
-          , mWriteBufferLen(0)
-          , mStreamInitialized(PR_FALSE)
-          , mUncompressedCount(0)
-         {
-         }
-         virtual ~nsCompressOutputStreamWrapper()
-         { 
-             Close();
-         }
-         NS_IMETHOD Write(const char* buf, PRUint32 count, PRUint32 * result);
-         NS_IMETHOD Close();
-     private:
-         nsresult InitZstream();
-         nsresult WriteBuffer();
-     };
-
  private:
      /**
       * nsCacheEntryDescriptor data members
       */
      nsCacheEntry          * mCacheEntry; // we are a child of the entry
      nsCacheAccessMode       mAccessGranted;
      nsIOutputStream       * mOutput;
 };
--- a/netwerk/cache/nsCacheService.cpp
+++ b/netwerk/cache/nsCacheService.cpp
@@ -100,19 +100,16 @@ using namespace mozilla;
 #define OFFLINE_CACHE_DIR_PREF      "browser.cache.offline.parent_directory"
 #define OFFLINE_CACHE_CAPACITY_PREF "browser.cache.offline.capacity"
 #define OFFLINE_CACHE_CAPACITY      512000
 
 #define MEMORY_CACHE_ENABLE_PREF    "browser.cache.memory.enable"
 #define MEMORY_CACHE_CAPACITY_PREF  "browser.cache.memory.capacity"
 #define MEMORY_CACHE_MAX_ENTRY_SIZE_PREF "browser.cache.memory.max_entry_size"
 
-#define CACHE_COMPRESSION_LEVEL_PREF "browser.cache.compression_level"
-#define CACHE_COMPRESSION_LEVEL     1
-
 static const char * observerList[] = { 
     "profile-before-change",
     "profile-do-change",
     NS_XPCOM_SHUTDOWN_OBSERVER_ID,
     NS_PRIVATE_BROWSING_SWITCH_TOPIC
 };
 static const char * prefList[] = { 
 #ifdef NECKO_DISK_CACHE
@@ -124,18 +121,17 @@ static const char * prefList[] = {
 #endif
 #ifdef NECKO_OFFLINE_CACHE
     OFFLINE_CACHE_ENABLE_PREF,
     OFFLINE_CACHE_CAPACITY_PREF,
     OFFLINE_CACHE_DIR_PREF,
 #endif
     MEMORY_CACHE_ENABLE_PREF,
     MEMORY_CACHE_CAPACITY_PREF,
-    MEMORY_CACHE_MAX_ENTRY_SIZE_PREF,
-    CACHE_COMPRESSION_LEVEL_PREF
+    MEMORY_CACHE_MAX_ENTRY_SIZE_PREF
 };
 
 // Cache sizes, in KB
 const PRInt32 DEFAULT_CACHE_SIZE = 250 * 1024;  // 250 MB
 const PRInt32 MIN_CACHE_SIZE = 50 * 1024;       //  50 MB
 const PRInt32 MAX_CACHE_SIZE = 1024 * 1024;     //   1 GB
 // Default cache size was 50 MB for many years until FF 4:
 const PRInt32 PRE_GECKO_2_0_DEFAULT_CACHE_SIZE = 50 * 1024;
@@ -152,17 +148,16 @@ public:
         , mDiskCacheCapacity(0)
         , mDiskCacheMaxEntrySize(-1) // -1 means "no limit"
         , mOfflineCacheEnabled(PR_FALSE)
         , mOfflineCacheCapacity(0)
         , mMemoryCacheEnabled(PR_TRUE)
         , mMemoryCacheCapacity(-1)
         , mMemoryCacheMaxEntrySize(-1) // -1 means "no limit"
         , mInPrivateBrowsing(PR_FALSE)
-        , mCacheCompressionLevel(1)
     {
     }
 
     virtual ~nsCacheProfilePrefObserver() {}
     
     nsresult        Install();
     void            Remove();
     nsresult        ReadPrefs(nsIPrefBranch* branch);
@@ -176,18 +171,16 @@ public:
     PRBool          OfflineCacheEnabled();
     PRInt32         OfflineCacheCapacity()         { return mOfflineCacheCapacity; }
     nsILocalFile *  OfflineCacheParentDirectory()  { return mOfflineCacheParentDirectory; }
     
     PRBool          MemoryCacheEnabled();
     PRInt32         MemoryCacheCapacity();
     PRInt32         MemoryCacheMaxEntrySize()     { return mMemoryCacheMaxEntrySize; }
 
-    PRInt32         CacheCompressionLevel();
-
     static PRUint32 GetSmartCacheSize(const nsAString& cachePath);
 
 private:
     bool                    PermittedToSmartSize(nsIPrefBranch*, PRBool firstRun);
     PRBool                  mHaveProfile;
     
     PRBool                  mDiskCacheEnabled;
     PRInt32                 mDiskCacheCapacity; // in kilobytes
@@ -198,18 +191,16 @@ private:
     PRInt32                 mOfflineCacheCapacity; // in kilobytes
     nsCOMPtr<nsILocalFile>  mOfflineCacheParentDirectory;
     
     PRBool                  mMemoryCacheEnabled;
     PRInt32                 mMemoryCacheCapacity; // in kilobytes
     PRInt32                 mMemoryCacheMaxEntrySize; // in kilobytes
 
     PRBool                  mInPrivateBrowsing;
-
-    PRInt32                 mCacheCompressionLevel;
 };
 
 NS_IMPL_THREADSAFE_ISUPPORTS1(nsCacheProfilePrefObserver, nsIObserver)
 
 // Runnable sent to main thread after the cache IO thread calculates available
 // disk space, so that there is no race in setting mDiskCacheCapacity.
 class nsSetSmartSizeEvent: public nsRunnable 
 {
@@ -536,22 +527,16 @@ nsCacheProfilePrefObserver::Observe(nsIS
             PRInt32 newMaxSize;
             rv = branch->GetIntPref(MEMORY_CACHE_MAX_ENTRY_SIZE_PREF,
                                      &newMaxSize);
             if (NS_FAILED(rv)) 
                 return rv;
             
             mMemoryCacheMaxEntrySize = NS_MAX(-1, newMaxSize);
             nsCacheService::SetMemoryCacheMaxEntrySize(mMemoryCacheMaxEntrySize);
-        } else if (!strcmp(CACHE_COMPRESSION_LEVEL_PREF, data.get())) {
-            mCacheCompressionLevel = CACHE_COMPRESSION_LEVEL;
-            (void)branch->GetIntPref(CACHE_COMPRESSION_LEVEL_PREF,
-                                     &mCacheCompressionLevel);
-            mCacheCompressionLevel = NS_MAX(0, mCacheCompressionLevel);
-            mCacheCompressionLevel = NS_MIN(9, mCacheCompressionLevel);
         }
     } else if (!strcmp(NS_PRIVATE_BROWSING_SWITCH_TOPIC, topic)) {
         if (!strcmp(NS_PRIVATE_BROWSING_ENTER, data.get())) {
             mInPrivateBrowsing = PR_TRUE;
 
             nsCacheService::OnEnterExitPrivateBrowsing();
 
 #ifdef NECKO_DISK_CACHE
@@ -837,24 +822,16 @@ nsCacheProfilePrefObserver::ReadPrefs(ns
 
     mMemoryCacheCapacity = -1;
     (void) branch->GetIntPref(MEMORY_CACHE_CAPACITY_PREF,
                               &mMemoryCacheCapacity);
 
     (void) branch->GetIntPref(MEMORY_CACHE_MAX_ENTRY_SIZE_PREF,
                               &mMemoryCacheMaxEntrySize);
     mMemoryCacheMaxEntrySize = NS_MAX(-1, mMemoryCacheMaxEntrySize);
-
-    // read cache compression level pref
-    mCacheCompressionLevel = CACHE_COMPRESSION_LEVEL;
-    (void)branch->GetIntPref(CACHE_COMPRESSION_LEVEL_PREF,
-                             &mCacheCompressionLevel);
-    mCacheCompressionLevel = NS_MAX(0, mCacheCompressionLevel);
-    mCacheCompressionLevel = NS_MIN(9, mCacheCompressionLevel);
-
     return rv;
 }
 
 nsresult
 nsCacheService::DispatchToCacheIOThread(nsIRunnable* event)
 {
     if (!gService->mCacheIOThread) return NS_ERROR_NOT_AVAILABLE;
     return gService->mCacheIOThread->Dispatch(event, NS_DISPATCH_NORMAL);
@@ -978,21 +955,16 @@ nsCacheProfilePrefObserver::MemoryCacheC
         capacity   *= 1024;
     } else {
         capacity    = 0;
     }
 
     return capacity;
 }
 
-PRInt32
-nsCacheProfilePrefObserver::CacheCompressionLevel()
-{
-    return mCacheCompressionLevel;
-}
 
 /******************************************************************************
  * nsProcessRequestEvent
  *****************************************************************************/
 
 class nsProcessRequestEvent : public nsRunnable {
 public:
     nsProcessRequestEvent(nsCacheRequest *aRequest)
@@ -2344,24 +2316,16 @@ nsCacheService::ValidateEntry(nsCacheEnt
     nsresult rv = gService->ProcessPendingRequests(entry);
     NS_ASSERTION(rv == NS_OK, "ProcessPendingRequests failed.");
     // XXX what else should be done?
 
     return rv;
 }
 
 
-PRInt32
-nsCacheService::CacheCompressionLevel()
-{
-    PRInt32 level = gService->mObserver->CacheCompressionLevel();
-    return level;
-}
-
-
 void
 nsCacheService::DeactivateEntry(nsCacheEntry * entry)
 {
     CACHE_LOG_DEBUG(("Deactivating entry %p\n", entry));
     nsresult  rv = NS_OK;
     NS_ASSERTION(entry->IsNotInUse(), "### deactivating an entry while in use!");
     nsCacheDevice * device = nsnull;
 
--- a/netwerk/cache/nsCacheService.h
+++ b/netwerk/cache/nsCacheService.h
@@ -119,17 +119,16 @@ public:
                                               nsIOutputStream ** result);
 
     static nsresult  OnDataSizeChange(nsCacheEntry * entry, PRInt32 deltaSize);
 
     static nsresult  SetCacheElement(nsCacheEntry * entry, nsISupports * element);
 
     static nsresult  ValidateEntry(nsCacheEntry * entry);
 
-    static PRInt32   CacheCompressionLevel();
 
     /**
      * Methods called by any cache classes
      */
 
     static
     nsCacheService * GlobalInstance()   { return gService; }
 
@@ -171,18 +170,16 @@ public:
     static void      SetMemoryCacheMaxEntrySize(PRInt32  maxSize);
 
     static void      SetOfflineCacheEnabled(PRBool  enabled);
     // Sets the offline cache capacity (in kilobytes)
     static void      SetOfflineCacheCapacity(PRInt32  capacity);
 
     static void      SetMemoryCache();
 
-    static void      SetCacheCompressionLevel(PRInt32  level);
-
     static void      OnEnterExitPrivateBrowsing();
 
     nsresult         Init();
     void             Shutdown();
 
     static void      AssertOwnsLock()
     { gService->mLock.AssertCurrentThreadOwns(); }
 
--- a/netwerk/cache/nsICacheEntryDescriptor.idl
+++ b/netwerk/cache/nsICacheEntryDescriptor.idl
@@ -132,22 +132,16 @@ interface nsICacheEntryDescriptor : nsIC
 
     /**
      * Get/set security info on the cache entry for this descriptor.  This fails
      * if the storage policy is not STORE_IN_MEMORY.
      */
     attribute nsISupports securityInfo;
     
     /**
-     * Get the size of the cache entry data, as stored. This may differ
-     * from the entry's dataSize, if the entry is compressed.
-     */
-    readonly attribute unsigned long storageDataSize;
-
-    /**
      * Doom the cache entry this descriptor references in order to slate it for 
      * removal.  Once doomed a cache entry cannot be undoomed.
      *
      * A descriptor with WRITE access can doom the cache entry and choose to
      * fail pending requests.  This means that pending requests will not get
      * a cache descriptor.  This is meant as a tool for clients that wish to
      * instruct pending requests to skip the cache.
      */
--- a/netwerk/protocol/about/nsAboutCacheEntry.cpp
+++ b/netwerk/protocol/about/nsAboutCacheEntry.cpp
@@ -335,17 +335,17 @@ nsAboutCacheEntry::WriteCacheEntryDescri
         APPEND_ROW("expires", timeBuf);
     } else {
         APPEND_ROW("expires", "No expiration time");
     }
 
     // Data Size
     s.Truncate();
     PRUint32 dataSize;
-    descriptor->GetStorageDataSize(&dataSize);
+    descriptor->GetDataSize(&dataSize);
     s.AppendInt((PRInt32)dataSize);     // XXX nsICacheEntryInfo interfaces should be fixed.
     APPEND_ROW("Data size", s);
 
     // Storage Policy
 
     // XXX Stream Based?
 
     // XXX Cache Device
@@ -399,18 +399,21 @@ nsAboutCacheEntry::WriteCacheEntryDescri
     if (dataSize) { // don't draw an <hr> if the Data Size is 0.
         nsCOMPtr<nsIInputStream> stream;
         descriptor->OpenInputStream(0, getter_AddRefs(stream));
         if (stream) {
             buffer.AssignLiteral("<hr/>\n"
                                  "<pre>");
             PRUint32 hexDumpState = 0;
             char chunk[4096];
-            while(NS_SUCCEEDED(stream->Read(chunk, sizeof(chunk), &n)) && 
-                  n > 0) {
+            while (dataSize) {
+                PRUint32 count = NS_MIN<PRUint32>(dataSize, sizeof(chunk));
+                if (NS_FAILED(stream->Read(chunk, count, &n)) || n == 0)
+                    break;
+                dataSize -= n;
                 HexDump(&hexDumpState, chunk, n, buffer);
                 outputStream->Write(buffer.get(), buffer.Length(), &n);
                 buffer.Truncate();
             }
             buffer.AssignLiteral("</pre>\n");
             outputStream->Write(buffer.get(), buffer.Length(), &n);
       }
     }
--- a/netwerk/protocol/http/nsHttpChannel.cpp
+++ b/netwerk/protocol/http/nsHttpChannel.cpp
@@ -3105,42 +3105,16 @@ nsHttpChannel::InstallCacheListener(PRUi
 {
     nsresult rv;
 
     LOG(("Preparing to write data into the cache [uri=%s]\n", mSpec.get()));
 
     NS_ASSERTION(mCacheEntry, "no cache entry");
     NS_ASSERTION(mListener, "no listener");
 
-    nsCacheStoragePolicy policy;
-    rv = mCacheEntry->GetStoragePolicy(&policy);
-    if (NS_FAILED(rv)) {
-        policy = nsICache::STORE_ON_DISK_AS_FILE;
-    }
-
-    // If the content is compressible and the server has not compressed it,
-    // mark the cache entry for compression.
-    if ((mResponseHead->PeekHeader(nsHttp::Content_Encoding) == nsnull) && (
-         policy != nsICache::STORE_ON_DISK_AS_FILE) && (
-         mResponseHead->ContentType().EqualsLiteral(TEXT_HTML) ||
-         mResponseHead->ContentType().EqualsLiteral(TEXT_PLAIN) ||
-         mResponseHead->ContentType().EqualsLiteral(TEXT_CSS) ||
-         mResponseHead->ContentType().EqualsLiteral(TEXT_JAVASCRIPT) ||
-         mResponseHead->ContentType().EqualsLiteral(TEXT_ECMASCRIPT) ||
-         mResponseHead->ContentType().EqualsLiteral(TEXT_XML) ||
-         mResponseHead->ContentType().EqualsLiteral(APPLICATION_JAVASCRIPT) ||
-         mResponseHead->ContentType().EqualsLiteral(APPLICATION_ECMASCRIPT) ||
-         mResponseHead->ContentType().EqualsLiteral(APPLICATION_XJAVASCRIPT) ||
-         mResponseHead->ContentType().EqualsLiteral(APPLICATION_XHTML_XML))) {
-        rv = mCacheEntry->SetMetaDataElement("uncompressed-len", "0"); 
-        if (NS_FAILED(rv)) {
-            LOG(("unable to mark cache entry for compression"));
-        }
-    } 
-      
     nsCOMPtr<nsIOutputStream> out;
     rv = mCacheEntry->OpenOutputStream(offset, getter_AddRefs(out));
     if (NS_FAILED(rv)) return rv;
 
     // XXX disk cache does not support overlapped i/o yet
 #if 0
     // Mark entry valid inorder to allow simultaneous reading...
     rv = mCacheEntry->MarkValid();
@@ -3153,17 +3127,20 @@ nsHttpChannel::InstallCacheListener(PRUi
 
     nsCOMPtr<nsICacheService> serv =
         do_GetService(NS_CACHESERVICE_CONTRACTID, &rv);
     NS_ENSURE_SUCCESS(rv, rv);
 
     nsCOMPtr<nsIEventTarget> cacheIOTarget;
     serv->GetCacheIOTarget(getter_AddRefs(cacheIOTarget));
 
-    if (policy == nsICache::STORE_ON_DISK_AS_FILE ||
+    nsCacheStoragePolicy policy;
+    rv = mCacheEntry->GetStoragePolicy(&policy);
+
+    if (NS_FAILED(rv) || policy == nsICache::STORE_ON_DISK_AS_FILE ||
         !cacheIOTarget) {
         LOG(("nsHttpChannel::InstallCacheListener sync tee %p rv=%x policy=%d "
              "cacheIOTarget=%p", tee.get(), rv, policy, cacheIOTarget.get()));
         rv = tee->Init(mListener, out, nsnull);
     } else {
         LOG(("nsHttpChannel::InstallCacheListener async tee %p", tee.get()));
         rv = tee->InitAsync(mListener, cacheIOTarget, out, nsnull);
     }
deleted file mode 100644
--- a/netwerk/test/unit/test_compressappend.js
+++ /dev/null
@@ -1,106 +0,0 @@
-//
-// Test that data can be appended to a cache entry even when the data is 
-// compressed by the cache compression feature - bug 648429.
-//
-const Cc = Components.classes;
-const Ci = Components.interfaces;
-const Cr = Components.results;
-
-var _CSvc;
-function get_cache_service() {
-  if (_CSvc)
-    return _CSvc;
-
-  return _CSvc = Cc["@mozilla.org/network/cache-service;1"].
-                 getService(Ci.nsICacheService);
-}
-
-function get_ostream_for_entry(key, append, compress, entryRef)
-{
-  var cache = get_cache_service();
-  var session = cache.createSession(
-                  "HTTP",
-                  Ci.nsICache.STORE_ON_DISK,
-                  Ci.nsICache.STREAM_BASED);
-  var cacheEntry = session.openCacheEntry(
-                     key,
-                     append ? Ci.nsICache.ACCESS_READ_WRITE
-                            : Ci.nsICache.ACCESS_WRITE,
-                     true);
-
-  if (compress)
-    if (!append)
-      cacheEntry.setMetaDataElement("uncompressed-len", "0");
-
-  var oStream = cacheEntry.openOutputStream(append ? cacheEntry.storageDataSize : 0);
-  entryRef.value = cacheEntry;
-  return oStream;
-}
-
-function write_and_check(str, data, len)
-{
-  var written = str.write(data, len);
-  if (written != len) {
-    do_throw("str.write has not written all data!\n" +
-             "  Expected: " + len  + "\n" +
-             "  Actual: " + written + "\n");
-  }
-}
-
-function check_datafile()
-{
-  var cache = get_cache_service();
-  var session = cache.createSession(
-                  "HTTP",
-                  Ci.nsICache.STORE_ON_DISK,
-                  Ci.nsICache.STREAM_BASED);
-  var entry = session.openCacheEntry(
-                "data",
-                Ci.nsICache.ACCESS_READ,
-                true);
-
-  var wrapper = Cc["@mozilla.org/scriptableinputstream;1"].
-                createInstance(Ci.nsIScriptableInputStream);
-
-  wrapper.init(entry.openInputStream(0));
-
-  var str = wrapper.read(wrapper.available());
-  do_check_eq(str.length, 10);
-  do_check_eq(str, "12345abcde");
-
-  wrapper.close();
-  entry.close();
-}
-
-
-function write_datafile(compress)
-{
-  var entry = {};
-  var oStr = get_ostream_for_entry("data", false, compress, entry);
-  write_and_check(oStr, "12345", 5);
-  oStr.close();
-  entry.value.close();
-}
-
-function append_datafile()
-{
-  var entry = {};
-  var oStr = get_ostream_for_entry("data", true, false, entry);
-  write_and_check(oStr, "abcde", 5);
-  oStr.close();
-  entry.value.close();
-}
-
-function test_append(compress)
-{
-  get_cache_service().evictEntries(Ci.nsICache.STORE_ANYWHERE);
-  write_datafile(compress);
-  append_datafile();
-  check_datafile();
-}
-
-function run_test() {
-  do_get_profile();
-  test_append(false);
-  test_append(true);
-}
--- a/netwerk/test/unit/xpcshell.ini
+++ b/netwerk/test/unit/xpcshell.ini
@@ -68,17 +68,16 @@ tail =
 [test_bug659569.js]
 [test_bug660066.js]
 [test_bug651185.js]
 [test_bug667907.js]
 [test_bug670333.js]
 [test_cacheflags.js]
 [test_channel_close.js]
 [test_compareURIs.js]
-[test_compressappend.js]
 [test_content_sniffer.js]
 [test_cookie_header.js]
 [test_data_protocol.js]
 [test_dns_service.js]
 [test_duplicate_headers.js]
 [test_event_sink.js]
 [test_extract_charset_from_content_type.js]
 [test_fallback_no-cache-entry_canceled.js]