From 21d8a5efa044eb876dc8c686712193c37ce10018 Mon Sep 17 00:00:00 2001 From: Doug Turner Date: Tue, 20 Apr 2010 09:32:28 -0700 Subject: [PATCH] Bug 545869 - Remove small buffer #defines and use preferences. r=honza --- config/autoconf.mk.in | 1 - configure.in | 14 ----- modules/libpref/src/init/all.js | 3 + netwerk/base/src/nsAsyncStreamCopier.cpp | 5 +- netwerk/base/src/nsIOService.cpp | 61 +++++++++++++------ netwerk/base/src/nsIOService.h | 9 +-- netwerk/base/src/nsInputStreamPump.cpp | 8 ++- netwerk/base/src/nsNetSegmentUtils.h | 20 ++---- netwerk/base/src/nsSyncStreamListener.cpp | 4 +- netwerk/necko-config.h.in | 2 - netwerk/protocol/data/src/nsDataChannel.cpp | 5 +- netwerk/protocol/file/src/nsFileChannel.cpp | 4 +- netwerk/protocol/ftp/src/nsFTPChannel.h | 6 -- .../ftp/src/nsFtpConnectionThread.cpp | 12 ++-- .../ftp/src/nsFtpControlConnection.cpp | 6 +- netwerk/protocol/http/src/nsHttp.h | 5 -- netwerk/protocol/http/src/nsHttpChannel.cpp | 1 - .../protocol/http/src/nsHttpConnection.cpp | 8 ++- netwerk/protocol/http/src/nsHttpPipeline.cpp | 6 +- netwerk/protocol/http/src/nsHttpPipeline.h | 2 +- .../protocol/http/src/nsHttpTransaction.cpp | 8 +-- .../streamconv/converters/nsBinHexDecoder.cpp | 18 +++--- .../exthandler/nsExternalHelperAppService.cpp | 23 ++++++- .../exthandler/nsExternalHelperAppService.h | 10 +-- 24 files changed, 123 insertions(+), 118 deletions(-) diff --git a/config/autoconf.mk.in b/config/autoconf.mk.in index 59e1af51c2f..c002365b4a4 100644 --- a/config/autoconf.mk.in +++ b/config/autoconf.mk.in @@ -210,7 +210,6 @@ MOZ_RDF = @MOZ_RDF@ NECKO_PROTOCOLS = @NECKO_PROTOCOLS@ NECKO_DISK_CACHE = @NECKO_DISK_CACHE@ -NECKO_SMALL_BUFFERS = @NECKO_SMALL_BUFFERS@ NECKO_COOKIES = @NECKO_COOKIES@ NECKO_WIFI = @NECKO_WIFI@ MOZ_AUTH_EXTENSION = @MOZ_AUTH_EXTENSION@ diff --git a/configure.in b/configure.in index 20888c65d28..0de8cb15930 100644 --- a/configure.in +++ b/configure.in @@ -4816,7 +4816,6 @@ NECKO_WIFI=1 NECKO_COOKIES=1 NECKO_DISK_CACHE=1 NECKO_PROTOCOLS_DEFAULT="about data file ftp gopher http res viewsource" -NECKO_SMALL_BUFFERS= BUILD_CTYPES=1 XPC_IDISPATCH_SUPPORT= @@ -8146,19 +8145,6 @@ if test "$NECKO_WIFI"; then fi AC_SUBST(NECKO_WIFI) -dnl -dnl option to minimize size of necko's i/o buffers -dnl -MOZ_ARG_ENABLE_BOOL(necko-small-buffers, -[ --enable-necko-small-buffers - Minimize size of necko's i/o buffers], - NECKO_SMALL_BUFFERS=1, - NECKO_SMALL_BUFFERS=) -AC_SUBST(NECKO_SMALL_BUFFERS) -if test "$NECKO_SMALL_BUFFERS"; then - AC_DEFINE(NECKO_SMALL_BUFFERS) -fi - dnl dnl option to disable cookies dnl diff --git a/modules/libpref/src/init/all.js b/modules/libpref/src/init/all.js index 0c5bba5e5ba..2d20b0c0eb6 100644 --- a/modules/libpref/src/init/all.js +++ b/modules/libpref/src/init/all.js @@ -2888,3 +2888,6 @@ pref("browser.history.allowPushState", true); pref("browser.history.allowReplaceState", true); pref("browser.history.allowPopState", true); pref("browser.history.maxStateObjectSize", 655360); + +pref("network.buffer.cache.count", 24); +pref("network.buffer.cache.size", 4096); diff --git a/netwerk/base/src/nsAsyncStreamCopier.cpp b/netwerk/base/src/nsAsyncStreamCopier.cpp index 53d95482957..73bf90c93eb 100644 --- a/netwerk/base/src/nsAsyncStreamCopier.cpp +++ b/netwerk/base/src/nsAsyncStreamCopier.cpp @@ -35,6 +35,7 @@ * * ***** END LICENSE BLOCK ***** */ +#include "nsIOService.h" #include "nsAsyncStreamCopier.h" #include "nsIEventTarget.h" #include "nsStreamUtils.h" @@ -56,7 +57,7 @@ static PRLogModuleInfo *gStreamCopierLog = nsnull; nsAsyncStreamCopier::nsAsyncStreamCopier() : mLock(nsnull) , mMode(NS_ASYNCCOPY_VIA_READSEGMENTS) - , mChunkSize(NET_DEFAULT_SEGMENT_SIZE) + , mChunkSize(nsIOService::gDefaultSegmentSize) , mStatus(NS_OK) , mIsPending(PR_FALSE) { @@ -234,7 +235,7 @@ nsAsyncStreamCopier::Init(nsIInputStream *source, return NS_ERROR_OUT_OF_MEMORY; if (chunkSize == 0) - chunkSize = NET_DEFAULT_SEGMENT_SIZE; + chunkSize = nsIOService::gDefaultSegmentSize; mChunkSize = chunkSize; mSource = source; diff --git a/netwerk/base/src/nsIOService.cpp b/netwerk/base/src/nsIOService.cpp index 285d61f77d3..afaa4d02af8 100644 --- a/netwerk/base/src/nsIOService.cpp +++ b/netwerk/base/src/nsIOService.cpp @@ -84,6 +84,9 @@ #define AUTODIAL_PREF "network.autodial-helper.enabled" #define MANAGE_OFFLINE_STATUS_PREF "network.manage-offline-status" +#define NECKO_BUFFER_CACHE_COUNT_PREF "network.buffer.cache.count" +#define NECKO_BUFFER_CACHE_SIZE_PREF "network.buffer.cache.size" + #define MAX_RECURSION_COUNT 50 nsIOService* gIOService = nsnull; @@ -162,6 +165,8 @@ static const char kProfileChangeNetRestoreTopic[] = "profile-change-net-restore" // Necko buffer cache nsIMemory* nsIOService::gBufferCache = nsnull; +PRUint32 nsIOService::gDefaultSegmentSize = 4096; +PRUint32 nsIOService::gDefaultSegmentCount = 24; //////////////////////////////////////////////////////////////////////////////// @@ -175,23 +180,6 @@ nsIOService::nsIOService() , mChannelEventSinks(NS_CHANNEL_EVENT_SINK_CATEGORY) , mContentSniffers(NS_CONTENT_SNIFFER_CATEGORY) { - // Get the allocator ready - if (!gBufferCache) - { - nsresult rv = NS_OK; - nsCOMPtr recyclingAllocator = - do_CreateInstance(NS_RECYCLINGALLOCATOR_CONTRACTID, &rv); - if (NS_FAILED(rv)) - return; - rv = recyclingAllocator->Init(NS_NECKO_BUFFER_CACHE_COUNT, - NS_NECKO_15_MINS, "necko"); - if (NS_FAILED(rv)) - return; - - nsCOMPtr eyeMemory = do_QueryInterface(recyclingAllocator); - gBufferCache = eyeMemory.get(); - NS_IF_ADDREF(gBufferCache); - } } nsresult @@ -251,6 +239,22 @@ nsIOService::Init() else NS_WARNING("failed to get observer service"); + // Get the allocator ready + if (!gBufferCache) { + nsresult rv = NS_OK; + nsCOMPtr recyclingAllocator = + do_CreateInstance(NS_RECYCLINGALLOCATOR_CONTRACTID, &rv); + + if (NS_FAILED(rv)) + return rv; + rv = recyclingAllocator->Init(gDefaultSegmentCount, + (15 * 60), // 15 minutes + "necko"); + + NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "Was unable to allocate. No gBufferCache."); + CallQueryInterface(recyclingAllocator, &gBufferCache); + } + gIOService = this; // go into managed mode if we can @@ -791,6 +795,29 @@ nsIOService::PrefsChanged(nsIPrefBranch *prefs, const char *pref) &manage))) SetManageOfflineStatus(manage); } + + if (!pref || strcmp(pref, NECKO_BUFFER_CACHE_COUNT_PREF) == 0) { + PRInt32 count; + if (NS_SUCCEEDED(prefs->GetIntPref(NECKO_BUFFER_CACHE_COUNT_PREF, + &count))) + /* check for bogus values and default if we find such a value */ + if (count > 0) + gDefaultSegmentCount = count; + } + + if (!pref || strcmp(pref, NECKO_BUFFER_CACHE_SIZE_PREF) == 0) { + PRInt32 size; + if (NS_SUCCEEDED(prefs->GetIntPref(NECKO_BUFFER_CACHE_SIZE_PREF, + &size))) + /* check for bogus values and default if we find such a value + * the upper limit here is arbitrary. having a 1mb segment size + * is pretty crazy. if you remove this, consider adding some + * integer rollover test. + */ + if (size > 0 && size < 1024*1024) + gDefaultSegmentSize = size; + NS_WARN_IF_FALSE( (!(size & (size - 1))) , "network buffer cache size is not a power of 2!"); + } } void diff --git a/netwerk/base/src/nsIOService.h b/netwerk/base/src/nsIOService.h index 400b4d8792b..d4f19bfd45c 100644 --- a/netwerk/base/src/nsIOService.h +++ b/netwerk/base/src/nsIOService.h @@ -60,13 +60,6 @@ #define NS_N(x) (sizeof(x)/sizeof(*x)) -#ifdef NECKO_SMALL_BUFFERS -#define NS_NECKO_BUFFER_CACHE_COUNT (10) // Max holdings: 10 * 2k = 20k -#else -#define NS_NECKO_BUFFER_CACHE_COUNT (24) // Max holdings: 24 * 4k = 96k -#endif -#define NS_NECKO_15_MINS (15 * 60) - static const char gScheme[][sizeof("resource")] = {"chrome", "file", "http", "jar", "resource"}; @@ -159,6 +152,8 @@ public: // Necko buffer cache. Used for all default buffer sizes that necko // allocates. static nsIMemory *gBufferCache; + static PRUint32 gDefaultSegmentSize; + static PRUint32 gDefaultSegmentCount; }; /** diff --git a/netwerk/base/src/nsInputStreamPump.cpp b/netwerk/base/src/nsInputStreamPump.cpp index 381f86871d0..73ff3f3ff0b 100644 --- a/netwerk/base/src/nsInputStreamPump.cpp +++ b/netwerk/base/src/nsInputStreamPump.cpp @@ -36,6 +36,7 @@ * * ***** END LICENSE BLOCK ***** */ +#include "nsIOService.h" #include "nsInputStreamPump.h" #include "nsIServiceManager.h" #include "nsIStreamTransportService.h" @@ -44,7 +45,6 @@ #include "nsITransport.h" #include "nsNetUtil.h" #include "nsThreadUtils.h" -#include "nsNetSegmentUtils.h" #include "nsCOMPtr.h" #include "prlog.h" @@ -138,8 +138,10 @@ nsInputStreamPump::PeekStream(PeekSegmentFun callback, void* closure) return rv; PeekData data(callback, closure); - return mAsyncStream->ReadSegments(CallPeekFunc, &data, - NET_DEFAULT_SEGMENT_SIZE, &dummy); + return mAsyncStream->ReadSegments(CallPeekFunc, + &data, + nsIOService::gDefaultSegmentSize, + &dummy); } nsresult diff --git a/netwerk/base/src/nsNetSegmentUtils.h b/netwerk/base/src/nsNetSegmentUtils.h index 301d04225be..4401c360a83 100644 --- a/netwerk/base/src/nsNetSegmentUtils.h +++ b/netwerk/base/src/nsNetSegmentUtils.h @@ -38,27 +38,18 @@ #ifndef nsNetSegmentUtils_h__ #define nsNetSegmentUtils_h__ -#include "necko-config.h" #include "nsIOService.h" -#ifdef NECKO_SMALL_BUFFERS -#define NET_DEFAULT_SEGMENT_SIZE 2048 -#define NET_DEFAULT_SEGMENT_COUNT 4 -#else -#define NET_DEFAULT_SEGMENT_SIZE 4096 -#define NET_DEFAULT_SEGMENT_COUNT 16 -#endif - /** * returns preferred allocator for given segment size. NULL implies * system allocator. this result can be used when allocating a pipe. */ + static inline nsIMemory * net_GetSegmentAlloc(PRUint32 segsize) { - return (segsize == NET_DEFAULT_SEGMENT_SIZE) - ? nsIOService::gBufferCache - : nsnull; + return (segsize == nsIOService::gDefaultSegmentSize) + ? nsIOService::gBufferCache : nsnull; } /** @@ -68,9 +59,10 @@ static inline void net_ResolveSegmentParams(PRUint32 &segsize, PRUint32 &segcount) { if (!segsize) - segsize = NET_DEFAULT_SEGMENT_SIZE; + segsize = nsIOService::gDefaultSegmentSize; + if (!segcount) - segcount = NET_DEFAULT_SEGMENT_COUNT; + segcount = nsIOService::gDefaultSegmentCount; } #endif // !nsNetSegmentUtils_h__ diff --git a/netwerk/base/src/nsSyncStreamListener.cpp b/netwerk/base/src/nsSyncStreamListener.cpp index 74d35e97295..147e1ce46ec 100644 --- a/netwerk/base/src/nsSyncStreamListener.cpp +++ b/netwerk/base/src/nsSyncStreamListener.cpp @@ -34,16 +34,16 @@ * * ***** END LICENSE BLOCK ***** */ +#include "nsIOService.h" #include "nsSyncStreamListener.h" #include "nsIPipe.h" -#include "nsNetSegmentUtils.h" nsresult nsSyncStreamListener::Init() { return NS_NewPipe(getter_AddRefs(mPipeIn), getter_AddRefs(mPipeOut), - NET_DEFAULT_SEGMENT_SIZE, + nsIOService::gDefaultSegmentSize, PR_UINT32_MAX, // no size limit PR_FALSE, PR_FALSE); diff --git a/netwerk/necko-config.h.in b/netwerk/necko-config.h.in index b353ab73416..549f35e526d 100644 --- a/netwerk/necko-config.h.in +++ b/netwerk/necko-config.h.in @@ -39,8 +39,6 @@ #undef NECKO_DISK_CACHE -#undef NECKO_SMALL_BUFFERS - #undef NECKO_COOKIES #undef NECKO_WIFI diff --git a/netwerk/protocol/data/src/nsDataChannel.cpp b/netwerk/protocol/data/src/nsDataChannel.cpp index fa63c9fb785..555e82a6fd8 100644 --- a/netwerk/protocol/data/src/nsDataChannel.cpp +++ b/netwerk/protocol/data/src/nsDataChannel.cpp @@ -37,6 +37,7 @@ // data implementation +#include "nsIOService.h" #include "nsDataChannel.h" #include "nsDataHandler.h" #include "nsNetUtil.h" @@ -44,7 +45,6 @@ #include "nsIInputStream.h" #include "nsIOutputStream.h" #include "nsReadableUtils.h" -#include "nsNetSegmentUtils.h" #include "nsEscape.h" #include "plbase64.h" #include "plstr.h" @@ -82,7 +82,8 @@ nsDataChannel::OpenContentStream(PRBool async, nsIInputStream **result, // create an unbounded pipe. rv = NS_NewPipe(getter_AddRefs(bufInStream), getter_AddRefs(bufOutStream), - NET_DEFAULT_SEGMENT_SIZE, PR_UINT32_MAX, + nsIOService::gDefaultSegmentSize, + PR_UINT32_MAX, async, PR_TRUE); if (NS_FAILED(rv)) return rv; diff --git a/netwerk/protocol/file/src/nsFileChannel.cpp b/netwerk/protocol/file/src/nsFileChannel.cpp index 2fff61d9f88..8ee33a1d796 100644 --- a/netwerk/protocol/file/src/nsFileChannel.cpp +++ b/netwerk/protocol/file/src/nsFileChannel.cpp @@ -37,6 +37,7 @@ * * ***** END LICENSE BLOCK ***** */ +#include "nsIOService.h" #include "nsFileChannel.h" #include "nsBaseContentStream.h" #include "nsDirectoryIndexStream.h" @@ -46,7 +47,6 @@ #include "nsURLHelper.h" #include "nsMimeTypes.h" #include "nsNetUtil.h" -#include "nsNetSegmentUtils.h" #include "nsProxyRelease.h" #include "nsAutoPtr.h" #include "nsStandardURL.h" @@ -107,7 +107,7 @@ nsFileCopyEvent::DoCopy() { // We'll copy in chunks this large by default. This size affects how // frequently we'll check for interrupts. - const PRInt32 chunk = NET_DEFAULT_SEGMENT_SIZE * NET_DEFAULT_SEGMENT_COUNT; + const PRInt32 chunk = nsIOService::gDefaultSegmentSize * nsIOService::gDefaultSegmentCount; nsresult rv = NS_OK; diff --git a/netwerk/protocol/ftp/src/nsFTPChannel.h b/netwerk/protocol/ftp/src/nsFTPChannel.h index f035f4e6feb..33235fb761b 100644 --- a/netwerk/protocol/ftp/src/nsFTPChannel.h +++ b/netwerk/protocol/ftp/src/nsFTPChannel.h @@ -63,12 +63,6 @@ #include "nsIResumableChannel.h" #include "nsHashPropertyBag.h" -#define FTP_COMMAND_CHANNEL_SEG_SIZE 64 -#define FTP_COMMAND_CHANNEL_SEG_COUNT 8 - -#define FTP_DATA_CHANNEL_SEG_SIZE (4*1024) -#define FTP_DATA_CHANNEL_SEG_COUNT 8 - class nsFtpChannel : public nsBaseChannel, public nsIFTPChannel, public nsIUploadChannel, diff --git a/netwerk/protocol/ftp/src/nsFtpConnectionThread.cpp b/netwerk/protocol/ftp/src/nsFtpConnectionThread.cpp index 72d6ae93394..81c570557b2 100644 --- a/netwerk/protocol/ftp/src/nsFtpConnectionThread.cpp +++ b/netwerk/protocol/ftp/src/nsFtpConnectionThread.cpp @@ -45,6 +45,7 @@ #include "prlog.h" #include "prtime.h" +#include "nsIOService.h" #include "nsFTPChannel.h" #include "nsFtpConnectionThread.h" #include "nsFtpControlConnection.h" @@ -1528,8 +1529,8 @@ nsFtpState::R_pasv() { // open a buffered, asynchronous socket input stream nsCOMPtr input; rv = mDataTransport->OpenInputStream(0, - FTP_DATA_CHANNEL_SEG_SIZE, - FTP_DATA_CHANNEL_SEG_COUNT, + nsIOService::gDefaultSegmentSize, + nsIOService::gDefaultSegmentCount, getter_AddRefs(input)); NS_ENSURE_SUCCESS(rv, FTP_ERROR); mDataStream = do_QueryInterface(input); @@ -1655,9 +1656,10 @@ nsFtpState::OpenCacheDataStream() // Open a non-blocking, buffered input stream... nsCOMPtr transportInput; - transport->OpenInputStream(0, FTP_DATA_CHANNEL_SEG_SIZE, - FTP_DATA_CHANNEL_SEG_COUNT, - getter_AddRefs(transportInput)); + transport->OpenInputStream(0, + nsIOService::gDefaultSegmentSize, + nsIOService::gDefaultSegmentCount, + getter_AddRefs(transportInput)); NS_ENSURE_STATE(transportInput); mDataStream = do_QueryInterface(transportInput); diff --git a/netwerk/protocol/ftp/src/nsFtpControlConnection.cpp b/netwerk/protocol/ftp/src/nsFtpControlConnection.cpp index 329fa2cbe84..d0629863b7e 100644 --- a/netwerk/protocol/ftp/src/nsFtpControlConnection.cpp +++ b/netwerk/protocol/ftp/src/nsFtpControlConnection.cpp @@ -35,7 +35,7 @@ * * ***** END LICENSE BLOCK ***** */ - +#include "nsIOService.h" #include "nsFTPChannel.h" #include "nsFtpControlConnection.h" #include "nsFtpProtocolHandler.h" @@ -153,8 +153,8 @@ nsFtpControlConnection::Connect(nsIProxyInfo* proxyInfo, // open buffered, non-blocking/asynchronous input stream to socket. nsCOMPtr inStream; rv = mSocket->OpenInputStream(0, - FTP_COMMAND_CHANNEL_SEG_SIZE, - FTP_COMMAND_CHANNEL_SEG_COUNT, + nsIOService::gDefaultSegmentSize, + nsIOService::gDefaultSegmentCount, getter_AddRefs(inStream)); if (NS_SUCCEEDED(rv)) mSocketInput = do_QueryInterface(inStream); diff --git a/netwerk/protocol/http/src/nsHttp.h b/netwerk/protocol/http/src/nsHttp.h index 78aeadfe756..28a689c9ec7 100644 --- a/netwerk/protocol/http/src/nsHttp.h +++ b/netwerk/protocol/http/src/nsHttp.h @@ -80,11 +80,6 @@ extern PRLogModuleInfo *gHttpLog; #define LOG4_ENABLED() PR_LOG_TEST(gHttpLog, 4) #define LOG_ENABLED() LOG4_ENABLED() -// http default buffer geometry -#define NS_HTTP_SEGMENT_SIZE 4096 -#define NS_HTTP_SEGMENT_COUNT 16 // 64k maximum -#define NS_HTTP_MAX_ODA_SIZE (NS_HTTP_SEGMENT_SIZE * 4) // 16k - // http version codes #define NS_HTTP_VERSION_UNKNOWN 0 #define NS_HTTP_VERSION_0_9 9 diff --git a/netwerk/protocol/http/src/nsHttpChannel.cpp b/netwerk/protocol/http/src/nsHttpChannel.cpp index 10f08ecc2fa..f74549b77a0 100644 --- a/netwerk/protocol/http/src/nsHttpChannel.cpp +++ b/netwerk/protocol/http/src/nsHttpChannel.cpp @@ -83,7 +83,6 @@ #include "nsAuthInformationHolder.h" #include "nsICacheService.h" #include "nsDNSPrefetch.h" -#include "nsNetSegmentUtils.h" // True if the local cache should be bypassed when processing a request. #define BYPASS_LOCAL_CACHE(loadFlags) \ diff --git a/netwerk/protocol/http/src/nsHttpConnection.cpp b/netwerk/protocol/http/src/nsHttpConnection.cpp index 37fc3f9d3d5..a9d8495fb8a 100644 --- a/netwerk/protocol/http/src/nsHttpConnection.cpp +++ b/netwerk/protocol/http/src/nsHttpConnection.cpp @@ -42,6 +42,7 @@ #include "nsHttpRequestHead.h" #include "nsHttpResponseHead.h" #include "nsHttpHandler.h" +#include "nsIOService.h" #include "nsISocketTransportService.h" #include "nsISocketTransport.h" #include "nsIServiceManager.h" @@ -567,11 +568,12 @@ nsHttpConnection::OnSocketWritable() if (mSSLProxyConnectStream) { LOG((" writing CONNECT request stream\n")); rv = mSSLProxyConnectStream->ReadSegments(ReadFromStream, this, - NS_HTTP_SEGMENT_SIZE, &n); + nsIOService::gDefaultSegmentSize, + &n); } else { LOG((" writing transaction request stream\n")); - rv = mTransaction->ReadSegments(this, NS_HTTP_SEGMENT_SIZE, &n); + rv = mTransaction->ReadSegments(this, nsIOService::gDefaultSegmentSize, &n); } LOG((" ReadSegments returned [rv=%x read=%u sock-cond=%x]\n", @@ -661,7 +663,7 @@ nsHttpConnection::OnSocketReadable() PRBool again = PR_TRUE; do { - rv = mTransaction->WriteSegments(this, NS_HTTP_SEGMENT_SIZE, &n); + rv = mTransaction->WriteSegments(this, nsIOService::gDefaultSegmentSize, &n); if (NS_FAILED(rv)) { // if the transaction didn't want to take any more data, then // wait for the transaction to call ResumeRecv. diff --git a/netwerk/protocol/http/src/nsHttpPipeline.cpp b/netwerk/protocol/http/src/nsHttpPipeline.cpp index 1240a9bc915..3a71ca23cf6 100644 --- a/netwerk/protocol/http/src/nsHttpPipeline.cpp +++ b/netwerk/protocol/http/src/nsHttpPipeline.cpp @@ -277,7 +277,7 @@ nsHttpPipeline::PushBack(const char *data, PRUint32 length) } else if (length > mPushBackMax) { // grow push back buffer as necessary. - NS_ASSERTION(length <= NS_HTTP_SEGMENT_SIZE, "too big"); + NS_ASSERTION(length <= nsIOService::gDefaultSegmentSize, "too big"); mPushBackMax = length; mPushBackBuf = (char *) realloc(mPushBackBuf, mPushBackMax); if (!mPushBackBuf) @@ -558,8 +558,8 @@ nsHttpPipeline::FillSendBuf() // allocate a single-segment pipe rv = NS_NewPipe(getter_AddRefs(mSendBufIn), getter_AddRefs(mSendBufOut), - NS_HTTP_SEGMENT_SIZE, - NS_HTTP_SEGMENT_SIZE, + nsIOService::gDefaultSegmentSize, /* segment size */ + nsIOService::gDefaultSegmentSize, /* max size */ PR_TRUE, PR_TRUE, nsIOService::gBufferCache); if (NS_FAILED(rv)) return rv; diff --git a/netwerk/protocol/http/src/nsHttpPipeline.h b/netwerk/protocol/http/src/nsHttpPipeline.h index 498b3ec62bd..3a057403fd9 100644 --- a/netwerk/protocol/http/src/nsHttpPipeline.h +++ b/netwerk/protocol/http/src/nsHttpPipeline.h @@ -107,7 +107,7 @@ private: nsCOMPtr mSendBufIn; nsCOMPtr mSendBufOut; - // the push back buffer. not exceeding NS_HTTP_SEGMENT_SIZE bytes. + // the push back buffer. not exceeding nsIOService::gDefaultSegmentSize bytes. char *mPushBackBuf; PRUint32 mPushBackLen; PRUint32 mPushBackMax; diff --git a/netwerk/protocol/http/src/nsHttpTransaction.cpp b/netwerk/protocol/http/src/nsHttpTransaction.cpp index 8d521ce4e27..6dccd8d0c28 100644 --- a/netwerk/protocol/http/src/nsHttpTransaction.cpp +++ b/netwerk/protocol/http/src/nsHttpTransaction.cpp @@ -38,13 +38,13 @@ * * ***** END LICENSE BLOCK ***** */ +#include "nsIOService.h" #include "nsHttpHandler.h" #include "nsHttpTransaction.h" #include "nsHttpConnection.h" #include "nsHttpRequestHead.h" #include "nsHttpResponseHead.h" #include "nsHttpChunkedDecoder.h" -#include "nsNetSegmentUtils.h" #include "nsTransportUtils.h" #include "nsNetUtil.h" #include "nsProxyRelease.h" @@ -291,7 +291,7 @@ nsHttpTransaction::Init(PRUint8 caps, // that we write data in the largest chunks possible. this is actually // necessary to workaround some common server bugs (see bug 137155). rv = NS_NewBufferedInputStream(getter_AddRefs(mRequestStream), multi, - NET_DEFAULT_SEGMENT_SIZE); + nsIOService::gDefaultSegmentSize); if (NS_FAILED(rv)) return rv; } else @@ -304,8 +304,8 @@ nsHttpTransaction::Init(PRUint8 caps, rv = NS_NewPipe2(getter_AddRefs(mPipeIn), getter_AddRefs(mPipeOut), PR_TRUE, PR_TRUE, - NS_HTTP_SEGMENT_SIZE, - NS_HTTP_SEGMENT_COUNT, + nsIOService::gDefaultSegmentSize, + nsIOService::gDefaultSegmentCount, nsIOService::gBufferCache); if (NS_FAILED(rv)) return rv; diff --git a/netwerk/streamconv/converters/nsBinHexDecoder.cpp b/netwerk/streamconv/converters/nsBinHexDecoder.cpp index 248d9e31286..f86d10ad28c 100644 --- a/netwerk/streamconv/converters/nsBinHexDecoder.cpp +++ b/netwerk/streamconv/converters/nsBinHexDecoder.cpp @@ -36,6 +36,7 @@ * * ***** END LICENSE BLOCK ***** */ +#include "nsIOService.h" #include "nsBinHexDecoder.h" #include "nsIServiceManager.h" #include "nsIStreamConverterService.h" @@ -52,11 +53,6 @@ #include "nsMimeTypes.h" -#define DATA_BUFFER_SIZE (4096*2) - -#define NS_STREAM_CONVERTER_SEGMENT_SIZE (4*1024) -#define NS_STREAM_CONVERTER_BUFFER_SIZE (32*1024) - // sadly I couldn't find char defintions for CR LF elsehwere in the code (they are defined as strings in nsCRT.h) #define CR '\015' #define LF '\012' @@ -167,7 +163,7 @@ nsBinHexDecoder::OnDataAvailable(nsIRequest* request, PRUint32 numBytesRead = 0; while (aCount > 0) // while we still have bytes to copy... { - aStream->Read(mDataBuffer, PR_MIN(aCount, DATA_BUFFER_SIZE - 1), &numBytesRead); + aStream->Read(mDataBuffer, PR_MIN(aCount, nsIOService::gDefaultSegmentSize - 1), &numBytesRead); if (aCount >= numBytesRead) aCount -= numBytesRead; // subtract off the number of bytes we just read else @@ -276,7 +272,7 @@ nsresult nsBinHexDecoder::ProcessNextState(nsIRequest * aRequest, nsISupports * mInCRC = 1; } - else if (mPosOutputBuff >= DATA_BUFFER_SIZE) + else if (mPosOutputBuff >= (PRInt32) nsIOService::gDefaultSegmentSize) { if (mState == BINHEX_STATE_DFORK) { @@ -483,14 +479,14 @@ nsBinHexDecoder::OnStartRequest(nsIRequest* request, nsISupports *aCtxt) NS_ENSURE_TRUE(mNextListener, NS_ERROR_FAILURE); - mDataBuffer = (char *) nsMemory::Alloc((sizeof(char) * DATA_BUFFER_SIZE)); - mOutgoingBuffer = (char *) nsMemory::Alloc((sizeof(char) * DATA_BUFFER_SIZE)); + mDataBuffer = (char *) nsMemory::Alloc((sizeof(char) * nsIOService::gDefaultSegmentSize)); + mOutgoingBuffer = (char *) nsMemory::Alloc((sizeof(char) * nsIOService::gDefaultSegmentSize)); if (!mDataBuffer || !mOutgoingBuffer) return NS_ERROR_FAILURE; // out of memory; // now we want to create a pipe which we'll use to write our converted data... rv = NS_NewPipe(getter_AddRefs(mInputStream), getter_AddRefs(mOutputStream), - NS_STREAM_CONVERTER_SEGMENT_SIZE, - NS_STREAM_CONVERTER_BUFFER_SIZE, + nsIOService::gDefaultSegmentSize, + nsIOService::gDefaultSegmentSize, PR_TRUE, PR_TRUE); // don't propagate the on start request to mNextListener until we have determined the content type. diff --git a/uriloader/exthandler/nsExternalHelperAppService.cpp b/uriloader/exthandler/nsExternalHelperAppService.cpp index 8f083788118..cb6389f2963 100644 --- a/uriloader/exthandler/nsExternalHelperAppService.cpp +++ b/uriloader/exthandler/nsExternalHelperAppService.cpp @@ -1110,6 +1110,7 @@ nsExternalAppHandler::nsExternalAppHandler(nsIMIMEInfo * aMIMEInfo, , mContentLength(-1) , mProgress(0) , mRequest(nsnull) +, mDataBuffer(nsnull) { // make sure the extention includes the '.' @@ -1138,12 +1139,30 @@ nsExternalAppHandler::nsExternalAppHandler(nsIMIMEInfo * aMIMEInfo, EnsureSuggestedFileName(); gExtProtSvc->AddRef(); + + nsCOMPtr prefs(do_GetService(NS_PREFSERVICE_CONTRACTID)); + if (!prefs) + return; + + mBufferSize = 8192; + PRInt32 size; + nsresult rv = prefs->GetIntPref("network.buffer.cache.size", &size); + if (NS_SUCCEEDED(rv)) { + mBufferSize = size; + } + + mDataBuffer = (char*) malloc(mBufferSize); + if (!mDataBuffer) + return; } nsExternalAppHandler::~nsExternalAppHandler() { // Not using NS_RELEASE, since we don't want to set gExtProtSvc to NULL gExtProtSvc->Release(); + + if (mDataBuffer) + free(mDataBuffer); } NS_IMETHODIMP nsExternalAppHandler::SetWebProgressListener(nsIWebProgressListener2 * aWebProgressListener) @@ -1758,7 +1777,7 @@ NS_IMETHODIMP nsExternalAppHandler::OnDataAvailable(nsIRequest *request, nsISupp { nsresult rv = NS_OK; // first, check to see if we've been canceled.... - if (mCanceled) // then go cancel our underlying channel too + if (mCanceled || !mDataBuffer) // then go cancel our underlying channel too return request->Cancel(NS_BINDING_ABORTED); // read the data out of the stream and write it to the temp file. @@ -1771,7 +1790,7 @@ NS_IMETHODIMP nsExternalAppHandler::OnDataAvailable(nsIRequest *request, nsISupp while (NS_SUCCEEDED(rv) && count > 0) // while we still have bytes to copy... { readError = PR_TRUE; - rv = inStr->Read(mDataBuffer, PR_MIN(count, DATA_BUFFER_SIZE - 1), &numBytesRead); + rv = inStr->Read(mDataBuffer, PR_MIN(count, mBufferSize - 1), &numBytesRead); if (NS_SUCCEEDED(rv)) { if (count >= numBytesRead) diff --git a/uriloader/exthandler/nsExternalHelperAppService.h b/uriloader/exthandler/nsExternalHelperAppService.h index c00db4f4033..374e731724e 100644 --- a/uriloader/exthandler/nsExternalHelperAppService.h +++ b/uriloader/exthandler/nsExternalHelperAppService.h @@ -237,13 +237,6 @@ protected: PRBool mInPrivateBrowsing; }; -/** - * We need to read the data out of the incoming stream into a buffer which we - * can then use to write the data into the output stream representing the - * temp file. - */ -#define DATA_BUFFER_SIZE (4096*2) - /** * An external app handler is just a small little class that presents itself as * a nsIStreamListener. It saves the incoming data into a temp file. The handler @@ -359,7 +352,8 @@ protected: */ nsCOMPtr mFinalFileDestination; - char mDataBuffer[DATA_BUFFER_SIZE]; + PRUint32 mBufferSize; + char *mDataBuffer; /** * Creates the temporary file for the download and an output stream for it.