bug 907960 - backout 905460 r=backout

This commit is contained in:
Patrick McManus 2013-08-21 21:01:19 -04:00
parent 726cb7d8ee
commit b819bb57bd
8 changed files with 89 additions and 66 deletions

View File

@ -270,39 +270,39 @@ nsHttpConnectionMgr::Observe(nsISupports *subject,
//-----------------------------------------------------------------------------
nsresult
nsHttpConnectionMgr::AddTransaction(nsHttpTransaction *aTrans, int32_t priority)
nsHttpConnectionMgr::AddTransaction(nsHttpTransaction *trans, int32_t priority)
{
LOG(("nsHttpConnectionMgr::AddTransaction [trans=%x %d]\n", aTrans, priority));
LOG(("nsHttpConnectionMgr::AddTransaction [trans=%x %d]\n", trans, priority));
nsRefPtr<nsHttpTransaction> trans(aTrans);
NS_ADDREF(trans);
nsresult rv = PostEvent(&nsHttpConnectionMgr::OnMsgNewTransaction, priority, trans);
if (NS_SUCCEEDED(rv))
trans.forget();
if (NS_FAILED(rv))
NS_RELEASE(trans);
return rv;
}
nsresult
nsHttpConnectionMgr::RescheduleTransaction(nsHttpTransaction *aTrans, int32_t priority)
nsHttpConnectionMgr::RescheduleTransaction(nsHttpTransaction *trans, int32_t priority)
{
LOG(("nsHttpConnectionMgr::RescheduleTransaction [trans=%x %d]\n", aTrans, priority));
LOG(("nsHttpConnectionMgr::RescheduleTransaction [trans=%x %d]\n", trans, priority));
nsRefPtr<nsHttpTransaction> trans(aTrans);
NS_ADDREF(trans);
nsresult rv = PostEvent(&nsHttpConnectionMgr::OnMsgReschedTransaction, priority, trans);
if (NS_SUCCEEDED(rv))
trans.forget();
if (NS_FAILED(rv))
NS_RELEASE(trans);
return rv;
}
nsresult
nsHttpConnectionMgr::CancelTransaction(nsHttpTransaction *aTrans, nsresult reason)
nsHttpConnectionMgr::CancelTransaction(nsHttpTransaction *trans, nsresult reason)
{
LOG(("nsHttpConnectionMgr::CancelTransaction [trans=%x reason=%x]\n", aTrans, reason));
LOG(("nsHttpConnectionMgr::CancelTransaction [trans=%x reason=%x]\n", trans, reason));
nsRefPtr<nsHttpTransaction> trans(aTrans);
NS_ADDREF(trans);
nsresult rv = PostEvent(&nsHttpConnectionMgr::OnMsgCancelTransaction,
static_cast<int32_t>(reason), trans);
if (NS_SUCCEEDED(rv))
trans.forget();
if (NS_FAILED(rv))
NS_RELEASE(trans);
return rv;
}
@ -359,14 +359,14 @@ nsHttpConnectionMgr::GetSocketThreadTarget(nsIEventTarget **target)
}
nsresult
nsHttpConnectionMgr::ReclaimConnection(nsHttpConnection *aConn)
nsHttpConnectionMgr::ReclaimConnection(nsHttpConnection *conn)
{
LOG(("nsHttpConnectionMgr::ReclaimConnection [conn=%x]\n", aConn));
LOG(("nsHttpConnectionMgr::ReclaimConnection [conn=%x]\n", conn));
nsRefPtr<nsHttpConnection> conn(aConn);
NS_ADDREF(conn);
nsresult rv = PostEvent(&nsHttpConnectionMgr::OnMsgReclaimConnection, 0, conn);
if (NS_SUCCEEDED(rv))
conn.forget();
if (NS_FAILED(rv))
NS_RELEASE(conn);
return rv;
}
@ -405,14 +405,14 @@ nsHttpConnectionMgr::UpdateParam(nsParamName name, uint16_t value)
}
nsresult
nsHttpConnectionMgr::ProcessPendingQ(nsHttpConnectionInfo *aCI)
nsHttpConnectionMgr::ProcessPendingQ(nsHttpConnectionInfo *ci)
{
LOG(("nsHttpConnectionMgr::ProcessPendingQ [ci=%s]\n", aCI->HashKey().get()));
LOG(("nsHttpConnectionMgr::ProcessPendingQ [ci=%s]\n", ci->HashKey().get()));
nsRefPtr<nsHttpConnectionInfo> ci(aCI);
NS_ADDREF(ci);
nsresult rv = PostEvent(&nsHttpConnectionMgr::OnMsgProcessPendingQ, 0, ci);
if (NS_SUCCEEDED(rv))
ci.forget();
if (NS_FAILED(rv))
NS_RELEASE(ci);
return rv;
}
@ -2090,12 +2090,12 @@ nsHttpConnectionMgr::OnMsgNewTransaction(int32_t priority, void *param)
{
LOG(("nsHttpConnectionMgr::OnMsgNewTransaction [trans=%p]\n", param));
nsRefPtr<nsHttpTransaction> trans =
dont_AddRef(static_cast<nsHttpTransaction *>(param));
nsHttpTransaction *trans = (nsHttpTransaction *) param;
trans->SetPriority(priority);
nsresult rv = ProcessNewTransaction(trans);
if (NS_FAILED(rv))
trans->Close(rv); // for whatever its worth
NS_RELEASE(trans);
}
void
@ -2104,8 +2104,7 @@ nsHttpConnectionMgr::OnMsgReschedTransaction(int32_t priority, void *param)
MOZ_ASSERT(PR_GetCurrentThread() == gSocketThread);
LOG(("nsHttpConnectionMgr::OnMsgReschedTransaction [trans=%p]\n", param));
nsRefPtr<nsHttpTransaction> trans =
dont_AddRef(static_cast<nsHttpTransaction *>(param));
nsHttpTransaction *trans = (nsHttpTransaction *) param;
trans->SetPriority(priority);
nsConnectionEntry *ent = LookupConnectionEntry(trans->ConnectionInfo(),
@ -2118,6 +2117,8 @@ nsHttpConnectionMgr::OnMsgReschedTransaction(int32_t priority, void *param)
InsertTransactionSorted(ent->mPendingQ, trans);
}
}
NS_RELEASE(trans);
}
void
@ -2127,8 +2128,7 @@ nsHttpConnectionMgr::OnMsgCancelTransaction(int32_t reason, void *param)
LOG(("nsHttpConnectionMgr::OnMsgCancelTransaction [trans=%p]\n", param));
nsresult closeCode = static_cast<nsresult>(reason);
nsRefPtr<nsHttpTransaction> trans =
dont_AddRef(static_cast<nsHttpTransaction *>(param));
nsHttpTransaction *trans = (nsHttpTransaction *) param;
//
// if the transaction owns a connection and the transaction is not done,
// then ask the connection to close the transaction. otherwise, close the
@ -2151,14 +2151,14 @@ nsHttpConnectionMgr::OnMsgCancelTransaction(int32_t reason, void *param)
}
trans->Close(closeCode);
}
NS_RELEASE(trans);
}
void
nsHttpConnectionMgr::OnMsgProcessPendingQ(int32_t, void *param)
{
MOZ_ASSERT(PR_GetCurrentThread() == gSocketThread);
nsRefPtr<nsHttpConnectionInfo> ci =
dont_AddRef(static_cast<nsHttpConnectionInfo *>(param));
nsHttpConnectionInfo *ci = (nsHttpConnectionInfo *) param;
if (!ci) {
LOG(("nsHttpConnectionMgr::OnMsgProcessPendingQ [ci=nullptr]\n"));
@ -2177,6 +2177,8 @@ nsHttpConnectionMgr::OnMsgProcessPendingQ(int32_t, void *param)
// for the specified connection info. walk the connection table...
mCT.Enumerate(ProcessOneTransactionCB, this);
}
NS_RELEASE(ci);
}
void
@ -2214,8 +2216,7 @@ nsHttpConnectionMgr::OnMsgReclaimConnection(int32_t, void *param)
MOZ_ASSERT(PR_GetCurrentThread() == gSocketThread);
LOG(("nsHttpConnectionMgr::OnMsgReclaimConnection [conn=%p]\n", param));
nsRefPtr<nsHttpConnection> conn =
dont_AddRef(static_cast<nsHttpConnection *>(param));
nsHttpConnection *conn = (nsHttpConnection *) param;
//
// 1) remove the connection from the active list
@ -2225,16 +2226,16 @@ nsHttpConnectionMgr::OnMsgReclaimConnection(int32_t, void *param)
nsConnectionEntry *ent = LookupConnectionEntry(conn->ConnectionInfo(),
conn, nullptr);
nsRefPtr<nsHttpConnectionInfo> ci;
nsHttpConnectionInfo *ci = nullptr;
if (!ent) {
// this should never happen
LOG(("nsHttpConnectionMgr::OnMsgReclaimConnection ent == null\n"));
MOZ_ASSERT(false, "no connection entry");
ci = conn->ConnectionInfo();
NS_ADDREF(ci = conn->ConnectionInfo());
}
else {
ci = ent->mConnInfo;
NS_ADDREF(ci = ent->mConnInfo);
// If the connection is in the active list, remove that entry
// and the reference held by the mActiveConns list.
@ -2254,9 +2255,8 @@ nsHttpConnectionMgr::OnMsgReclaimConnection(int32_t, void *param)
if (ent->mActiveConns.RemoveElement(conn)) {
if (conn == ent->mYellowConnection)
ent->OnYellowComplete();
// drop a reference that was held by list
conn.get()->Release();
nsHttpConnection *temp = conn;
NS_RELEASE(temp);
DecrementActiveConnCount(conn);
ConditionallyStopTimeoutTick();
}
@ -2277,8 +2277,7 @@ nsHttpConnectionMgr::OnMsgReclaimConnection(int32_t, void *param)
break;
}
// manually add a ref to the connection when it is in the list
conn.get()->AddRef();
NS_ADDREF(conn);
ent->mIdleConns.InsertElementAt(idx, conn);
mNumIdleConns++;
conn->BeginIdleMonitoring();
@ -2296,7 +2295,8 @@ nsHttpConnectionMgr::OnMsgReclaimConnection(int32_t, void *param)
}
}
OnMsgProcessPendingQ(0, ci.forget().get()); // releases |ci|
OnMsgProcessPendingQ(0, ci); // releases |ci|
NS_RELEASE(conn);
}
void
@ -2359,6 +2359,8 @@ nsHttpConnectionMgr::nsConnectionEntry::~nsConnectionEntry()
{
if (mSpdyPreferred)
gHttpHandler->ConnMgr()->RemoveSpdyPreferredEnt(mCoalescingKey);
NS_RELEASE(mConnInfo);
}
void
@ -2469,6 +2471,7 @@ nsHttpConnectionMgr::nsConnectionHandle::~nsConnectionHandle()
{
if (mConn) {
gHttpHandler->ReclaimConnection(mConn);
NS_RELEASE(mConn);
}
}
@ -3094,6 +3097,7 @@ nsConnectionEntry::nsConnectionEntry(nsHttpConnectionInfo *ci)
, mPreferIPv4(false)
, mPreferIPv6(false)
{
NS_ADDREF(mConnInfo);
if (gHttpHandler->GetPipelineAggressive()) {
mGreenDepth = kPipelineUnlimited;
mPipelineState = PS_GREEN;

View File

@ -273,7 +273,7 @@ private:
nsConnectionEntry(nsHttpConnectionInfo *ci);
~nsConnectionEntry();
nsRefPtr<nsHttpConnectionInfo> mConnInfo;
nsHttpConnectionInfo *mConnInfo;
nsTArray<nsHttpTransaction*> mPendingQ; // pending transaction queue
nsTArray<nsHttpConnection*> mActiveConns; // active connections
nsTArray<nsHttpConnection*> mIdleConns; // idle persistent connections
@ -393,10 +393,10 @@ private:
NS_DECL_THREADSAFE_ISUPPORTS
NS_DECL_NSAHTTPCONNECTION(mConn)
nsConnectionHandle(nsHttpConnection *conn) : mConn(conn) { }
nsConnectionHandle(nsHttpConnection *conn) { NS_ADDREF(mConn = conn); }
virtual ~nsConnectionHandle();
nsRefPtr<nsHttpConnection> mConn;
nsHttpConnection *mConn;
};
// nsHalfOpenSocket is used to hold the state of an opening TCP socket

View File

@ -121,14 +121,19 @@ NewURI(const nsACString &aSpec,
int32_t aDefaultPort,
nsIURI **aURI)
{
nsRefPtr<nsStandardURL> url = new nsStandardURL();
nsStandardURL *url = new nsStandardURL();
if (!url)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(url);
nsresult rv = url->Init(nsIStandardURL::URLTYPE_AUTHORITY,
aDefaultPort, aSpec, aCharset, aBaseURI);
if (NS_FAILED(rv)) {
NS_RELEASE(url);
return rv;
}
url.forget(aURI);
*aURI = url; // no QI needed
return NS_OK;
}
@ -139,7 +144,8 @@ NewURI(const nsACString &aSpec,
nsHttpHandler *gHttpHandler = nullptr;
nsHttpHandler::nsHttpHandler()
: mHttpVersion(NS_HTTP_VERSION_1_1)
: mConnMgr(nullptr)
, mHttpVersion(NS_HTTP_VERSION_1_1)
, mProxyHttpVersion(NS_HTTP_VERSION_1_1)
, mCapabilities(NS_HTTP_ALLOW_KEEPALIVE)
, mReferrerLevel(0xff) // by default we always send a referrer
@ -218,7 +224,7 @@ nsHttpHandler::~nsHttpHandler()
// make sure the connection manager is shutdown
if (mConnMgr) {
mConnMgr->Shutdown();
mConnMgr = nullptr;
NS_RELEASE(mConnMgr);
}
// Note: don't call NeckoChild::DestroyNeckoChild() here, as it's too late
@ -374,8 +380,12 @@ nsHttpHandler::InitConnectionMgr()
{
nsresult rv;
if (!mConnMgr)
if (!mConnMgr) {
mConnMgr = new nsHttpConnectionMgr();
if (!mConnMgr)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(mConnMgr);
}
rv = mConnMgr->Init(mMaxConnections,
mMaxPersistentConnectionsPerServer,

View File

@ -315,7 +315,7 @@ private:
nsHttpAuthCache mPrivateAuthCache;
// the connection manager
nsRefPtr<nsHttpConnectionMgr> mConnMgr;
nsHttpConnectionMgr *mConnMgr;
//
// prefs

View File

@ -63,7 +63,8 @@ private:
//-----------------------------------------------------------------------------
nsHttpPipeline::nsHttpPipeline()
: mStatus(NS_OK)
: mConnection(nullptr)
, mStatus(NS_OK)
, mRequestIsPartial(false)
, mResponseIsPartial(false)
, mClosed(false)
@ -83,6 +84,8 @@ nsHttpPipeline::~nsHttpPipeline()
// make sure we aren't still holding onto any transactions!
Close(NS_ERROR_ABORT);
NS_IF_RELEASE(mConnection);
if (mPushBackBuf)
free(mPushBackBuf);
}
@ -407,13 +410,14 @@ nsHttpPipeline::SetConnection(nsAHttpConnection *conn)
MOZ_ASSERT(PR_GetCurrentThread() == gSocketThread);
MOZ_ASSERT(!mConnection, "already have a connection");
mConnection = conn;
NS_IF_ADDREF(mConnection = conn);
}
nsAHttpConnection *
nsHttpPipeline::Connection()
{
LOG(("nsHttpPipeline::Connection [this=%p conn=%x]\n", this, mConnection.get()));
LOG(("nsHttpPipeline::Connection [this=%p conn=%x]\n", this, mConnection));
MOZ_ASSERT(PR_GetCurrentThread() == gSocketThread);
return mConnection;

View File

@ -52,7 +52,7 @@ private:
// overload of nsAHttpTransaction::QueryPipeline()
nsHttpPipeline *QueryPipeline();
nsRefPtr<nsAHttpConnection> mConnection;
nsAHttpConnection *mConnection;
nsTArray<nsAHttpTransaction*> mRequestQ; // array of transactions
nsTArray<nsAHttpTransaction*> mResponseQ; // array of transactions
nsresult mStatus;

View File

@ -82,6 +82,8 @@ LogHeaders(const char *lineStart)
nsHttpTransaction::nsHttpTransaction()
: mCallbacksLock("transaction mCallbacks lock")
, mRequestSize(0)
, mConnection(nullptr)
, mConnInfo(nullptr)
, mRequestHead(nullptr)
, mResponseHead(nullptr)
, mContentLength(-1)
@ -135,6 +137,9 @@ nsHttpTransaction::~nsHttpTransaction()
// Force the callbacks to be released right now
mCallbacks = nullptr;
NS_IF_RELEASE(mConnection);
NS_IF_RELEASE(mConnInfo);
delete mResponseHead;
delete mForTakeResponseHead;
delete mChunkedDecoder;
@ -227,7 +232,7 @@ nsHttpTransaction::Init(uint32_t caps,
!activityDistributorActive);
if (NS_FAILED(rv)) return rv;
mConnInfo = cinfo;
NS_ADDREF(mConnInfo = cinfo);
mCallbacks = callbacks;
mConsumerTarget = target;
mCaps = caps;
@ -403,7 +408,8 @@ nsHttpTransaction::TakeSubTransactions(
void
nsHttpTransaction::SetConnection(nsAHttpConnection *conn)
{
mConnection = conn;
NS_IF_RELEASE(mConnection);
NS_IF_ADDREF(mConnection = conn);
if (conn) {
MOZ_EVENT_TRACER_EXEC(static_cast<nsAHttpTransaction*>(this),
@ -818,8 +824,8 @@ nsHttpTransaction::Close(nsresult reason)
mTimings.responseEnd.IsNull() && !mTimings.responseStart.IsNull())
mTimings.responseEnd = TimeStamp::Now();
if (relConn)
mConnection = nullptr;
if (relConn && mConnection)
NS_RELEASE(mConnection);
mStatus = reason;
mTransactionDone = true; // forcibly flag the transaction as complete
@ -952,7 +958,7 @@ nsHttpTransaction::Restart()
// clear old connection state...
mSecurityInfo = 0;
mConnection = nullptr;
NS_IF_RELEASE(mConnection);
// disable pipelining for the next attempt in case pipelining caused the
// reset. this is being overly cautious since we don't know if pipelining

View File

@ -180,11 +180,10 @@ private:
nsCOMPtr<nsIInputStream> mRequestStream;
uint64_t mRequestSize;
nsRefPtr<nsHttpConnectionInfo> mConnInfo;
nsRefPtr<nsAHttpConnection> mConnection;
nsAHttpConnection *mConnection; // hard ref
nsHttpConnectionInfo *mConnInfo; // hard ref
nsHttpRequestHead *mRequestHead; // weak ref
nsHttpResponseHead *mResponseHead; // owning ref
nsHttpResponseHead *mResponseHead; // hard ref
nsAHttpSegmentReader *mReader;
nsAHttpSegmentWriter *mWriter;