Skip to content

Commit

Permalink
bug 792438 - part 2 block network image loads on head css,js r=honzab…
Browse files Browse the repository at this point in the history
… sr=bz
  • Loading branch information
mcmanus committed Dec 4, 2012
1 parent 94e5e11 commit 78ae24c
Show file tree
Hide file tree
Showing 13 changed files with 322 additions and 40 deletions.
4 changes: 4 additions & 0 deletions modules/libpref/src/init/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,10 @@ pref("network.http.connection-retry-timeout", 250);
// to give up if the OS does not give up first
pref("network.http.connection-timeout", 90);

// The maximum number of current global half open sockets allowable
// when starting a new speculative connection.
pref("network.http.speculative-parallel-limit", 6);

// Disable IPv6 for backup connections to workaround problems about broken
// IPv6 connectivity.
pref("network.http.fast-fallback-to-IPv4", true);
Expand Down
35 changes: 34 additions & 1 deletion netwerk/base/public/nsILoadGroup.idl
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
interface nsISimpleEnumerator;
interface nsIRequestObserver;
interface nsIInterfaceRequestor;
interface nsILoadGroupConnectionInfo;

/**
* A load group maintains a collection of nsIRequest objects.
*/
[scriptable, uuid(3de0a31c-feaf-400f-9f1e-4ef71f8b20cc)]
[scriptable, uuid(19501006-46e3-4634-b97d-26eff894b4d3)]
interface nsILoadGroup : nsIRequest
{
/**
Expand Down Expand Up @@ -71,4 +72,36 @@ interface nsILoadGroup : nsIRequest
* Notification callbacks for the load group.
*/
attribute nsIInterfaceRequestor notificationCallbacks;

/**
* Connection information for managing things like js/css
* connection blocking, and per-tab connection grouping
*/
readonly attribute nsILoadGroupConnectionInfo connectionInfo;
};

/**
* Used to maintain state about the connections of a load group and
* how they interact with blocking items like HEAD css/js loads.
*/
[uuid(d1f9f18e-3d85-473a-ad58-a2367d7cdb2a)]
interface nsILoadGroupConnectionInfo : nsISupports
{
/**
* Number of active blocking transactions associated with this load group
*/
readonly attribute unsigned long blockingTransactionCount;

/**
* Increase the number of active blocking transactions associated
* with this load group by one.
*/
void addBlockingTransaction();

/**
* Decrease the number of active blocking transactions associated
* with this load group by one. The return value is the number of remaining
* blockers.
*/
unsigned long removeBlockingTransaction();
};
103 changes: 79 additions & 24 deletions netwerk/base/src/nsLoadGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,30 +146,6 @@ nsLoadGroup::~nsLoadGroup()
}


nsresult nsLoadGroup::Init()
{
static PLDHashTableOps hash_table_ops =
{
PL_DHashAllocTable,
PL_DHashFreeTable,
PL_DHashVoidPtrKeyStub,
RequestHashMatchEntry,
PL_DHashMoveEntryStub,
RequestHashClearEntry,
PL_DHashFinalizeStub,
RequestHashInitEntry
};

if (!PL_DHashTableInit(&mRequests, &hash_table_ops, nullptr,
sizeof(RequestMapEntry), 16)) {
mRequests.ops = nullptr;

return NS_ERROR_OUT_OF_MEMORY;
}

return NS_OK;
}

////////////////////////////////////////////////////////////////////////////////
// nsISupports methods:

Expand Down Expand Up @@ -791,6 +767,15 @@ nsLoadGroup::SetNotificationCallbacks(nsIInterfaceRequestor *aCallbacks)
return NS_OK;
}

NS_IMETHODIMP
nsLoadGroup::GetConnectionInfo(nsILoadGroupConnectionInfo **aCI)
{
NS_ENSURE_ARG_POINTER(aCI);
*aCI = mConnectionInfo;
NS_IF_ADDREF(*aCI);
return NS_OK;
}

////////////////////////////////////////////////////////////////////////////////
// nsISupportsPriority methods:

Expand Down Expand Up @@ -1004,3 +989,73 @@ nsresult nsLoadGroup::MergeLoadFlags(nsIRequest *aRequest, nsLoadFlags& outFlags
outFlags = flags;
return rv;
}

// nsLoadGroupConnectionInfo

class nsLoadGroupConnectionInfo MOZ_FINAL : public nsILoadGroupConnectionInfo
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSILOADGROUPCONNECTIONINFO

nsLoadGroupConnectionInfo();
private:
int32_t mBlockingTransactionCount; // signed for PR_ATOMIC_*
};

NS_IMPL_THREADSAFE_ISUPPORTS1(nsLoadGroupConnectionInfo, nsILoadGroupConnectionInfo)

nsLoadGroupConnectionInfo::nsLoadGroupConnectionInfo()
: mBlockingTransactionCount(0)
{
}

NS_IMETHODIMP
nsLoadGroupConnectionInfo::GetBlockingTransactionCount(uint32_t *aBlockingTransactionCount)
{
NS_ENSURE_ARG_POINTER(aBlockingTransactionCount);
*aBlockingTransactionCount = static_cast<uint32_t>(mBlockingTransactionCount);
return NS_OK;
}

NS_IMETHODIMP
nsLoadGroupConnectionInfo::AddBlockingTransaction()
{
PR_ATOMIC_INCREMENT(&mBlockingTransactionCount);
return NS_OK;
}

NS_IMETHODIMP
nsLoadGroupConnectionInfo::RemoveBlockingTransaction(uint32_t *_retval)
{
NS_ENSURE_ARG_POINTER(_retval);
*_retval =
static_cast<uint32_t>(PR_ATOMIC_DECREMENT(&mBlockingTransactionCount));
return NS_OK;
}

nsresult nsLoadGroup::Init()
{
static PLDHashTableOps hash_table_ops =
{
PL_DHashAllocTable,
PL_DHashFreeTable,
PL_DHashVoidPtrKeyStub,
RequestHashMatchEntry,
PL_DHashMoveEntryStub,
RequestHashClearEntry,
PL_DHashFinalizeStub,
RequestHashInitEntry
};

if (!PL_DHashTableInit(&mRequests, &hash_table_ops, nullptr,
sizeof(RequestMapEntry), 16)) {
mRequests.ops = nullptr;

return NS_ERROR_OUT_OF_MEMORY;
}

mConnectionInfo = new nsLoadGroupConnectionInfo();

return NS_OK;
}
2 changes: 2 additions & 0 deletions netwerk/base/src/nsLoadGroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "mozilla/TimeStamp.h"

class nsISupportsArray;
class nsILoadGroupConnectionInfo;

class nsLoadGroup : public nsILoadGroup,
public nsISupportsPriority,
Expand Down Expand Up @@ -64,6 +65,7 @@ class nsLoadGroup : public nsILoadGroup,

nsCOMPtr<nsILoadGroup> mLoadGroup; // load groups can contain load groups
nsCOMPtr<nsIInterfaceRequestor> mCallbacks;
nsCOMPtr<nsILoadGroupConnectionInfo> mConnectionInfo;

nsCOMPtr<nsIRequest> mDefaultLoadRequest;
PLDHashTable mRequests;
Expand Down
8 changes: 7 additions & 1 deletion netwerk/protocol/http/nsHttp.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,19 @@ typedef uint8_t nsHttpVersion;
// a transaction with this caps flag keeps timing information
#define NS_HTTP_TIMING_ENABLED (1<<5)

// (1<<6) is unused
// a transaction with this flag blocks the initiation of other transactons
// in the same load group until it is complete
#define NS_HTTP_LOAD_AS_BLOCKING (1<<6)

// Disallow the use of the SPDY protocol. This is meant for the contexts
// such as HTTP upgrade which are nonsensical for SPDY, it is not the
// SPDY configuration variable.
#define NS_HTTP_DISALLOW_SPDY (1<<7)

// a transaction with this flag loads without respect to whether the load
// group is currently blocking on some resources
#define NS_HTTP_LOAD_UNBLOCKED (1<<8)

//-----------------------------------------------------------------------------
// some default values
//-----------------------------------------------------------------------------
Expand Down
32 changes: 32 additions & 0 deletions netwerk/protocol/http/nsHttpChannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,31 @@ nsHttpChannel::ContinueHandleAsyncFallback(nsresult rv)
return rv;
}

void
nsHttpChannel::SetupTransactionLoadGroupInfo()
{
// Find the loadgroup at the end of the chain in order
// to make sure all channels derived from the load group
// use the same connection scope.
nsCOMPtr<nsILoadGroup> rootLoadGroup = mLoadGroup;
while (rootLoadGroup) {
nsCOMPtr<nsILoadGroup> tmp;
rootLoadGroup->GetLoadGroup(getter_AddRefs(tmp));
if (tmp)
rootLoadGroup.swap(tmp);
else
break;
}

// Set the load group connection scope on the transaction
if (rootLoadGroup) {
nsCOMPtr<nsILoadGroupConnectionInfo> ci;
rootLoadGroup->GetConnectionInfo(getter_AddRefs(ci));
if (ci)
mTransaction->SetLoadGroupConnectionInfo(ci);
}
}

nsresult
nsHttpChannel::SetupTransaction()
{
Expand Down Expand Up @@ -854,6 +879,8 @@ nsHttpChannel::SetupTransaction()
return rv;
}

SetupTransactionLoadGroupInfo();

rv = nsInputStreamPump::Create(getter_AddRefs(mTransactionPump),
responseStream);
return rv;
Expand Down Expand Up @@ -4418,6 +4445,11 @@ nsHttpChannel::BeginConnect()
(BYPASS_LOCAL_CACHE(mLoadFlags)))
mCaps |= NS_HTTP_REFRESH_DNS;

if (mLoadAsBlocking)
mCaps |= NS_HTTP_LOAD_AS_BLOCKING;
if (mLoadUnblocked)
mCaps |= NS_HTTP_LOAD_UNBLOCKED;

// Force-Reload should reset the persistent connection pool for this host
if (mLoadFlags & LOAD_FRESH_CONNECTION) {
// just the initial document resets the whole pool
Expand Down
1 change: 1 addition & 0 deletions netwerk/protocol/http/nsHttpChannel.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ class nsHttpChannel : public HttpBaseChannel
nsresult ContinueConnect();
void SpeculativeConnect();
nsresult SetupTransaction();
void SetupTransactionLoadGroupInfo();
nsresult CallOnStartRequest();
nsresult ProcessResponse();
nsresult ContinueProcessResponse(nsresult);
Expand Down
Loading

0 comments on commit 78ae24c

Please sign in to comment.