Backed out changeset 630b08a7fe63 because of xpcshell test failures

This commit is contained in:
Ehsan Akhgari 2010-11-30 13:57:24 -05:00
parent 932c374a07
commit fd067b7b7d
8 changed files with 41 additions and 116 deletions

View File

@ -174,7 +174,7 @@ PRUint32 nsIOService::gDefaultSegmentCount = 24;
////////////////////////////////////////////////////////////////////////////////
nsIOService::nsIOService()
: mOffline(PR_TRUE)
: mOffline(PR_FALSE)
, mOfflineForProfileChange(PR_FALSE)
, mManageOfflineStatus(PR_TRUE)
, mSettingOffline(PR_FALSE)
@ -191,11 +191,21 @@ nsIOService::Init()
NS_TIME_FUNCTION;
nsresult rv;
// We need to get references to the DNS service so that we can shut it
// We need to get references to these services so that we can shut them
// down later. If we wait until the nsIOService is being shut down,
// GetService will fail at that point.
// TODO(darin): Load the Socket and DNS services lazily.
mSocketTransportService = do_GetService(NS_SOCKETTRANSPORTSERVICE_CONTRACTID, &rv);
if (NS_FAILED(rv)) {
NS_WARNING("failed to get socket transport service");
return rv;
}
NS_TIME_FUNCTION_MARK("got SocketTransportService");
mDNSService = do_GetService(NS_DNSSERVICE_CONTRACTID, &rv);
if (NS_FAILED(rv)) {
NS_WARNING("failed to get DNS service");
@ -283,29 +293,7 @@ nsIOService::Init()
nsIOService::~nsIOService()
{
gIOService = nsnull;
}
nsresult
nsIOService::InitializeSocketTransportService()
{
NS_TIME_FUNCTION;
nsresult rv = NS_OK;
if (!mSocketTransportService) {
mSocketTransportService = do_GetService(NS_SOCKETTRANSPORTSERVICE_CONTRACTID, &rv);
if (NS_FAILED(rv)) {
NS_WARNING("failed to get socket transport service");
}
}
if (mSocketTransportService) {
rv = mSocketTransportService->Init();
NS_ASSERTION(NS_SUCCEEDED(rv), "socket transport service init failed");
}
return rv;
}
}
nsIOService*
nsIOService::GetInstance() {
@ -754,7 +742,10 @@ nsIOService::SetOffline(PRBool offline)
rv = mDNSService->Init();
NS_ASSERTION(NS_SUCCEEDED(rv), "DNS service init failed");
}
InitializeSocketTransportService();
if (mSocketTransportService) {
rv = mSocketTransportService->Init();
NS_ASSERTION(NS_SUCCEEDED(rv), "socket transport service init failed");
}
mOffline = PR_FALSE; // indicate success only AFTER we've
// brought up the services

View File

@ -108,10 +108,6 @@ public:
PRBool IsOffline() { return mOffline; }
PRBool IsLinkUp();
PRBool IsComingOnline() const {
return mOffline && mSettingOffline && !mSetOfflineValue;
}
private:
// These shouldn't be called directly:
// - construct using GetInstance
@ -133,8 +129,6 @@ private:
NS_HIDDEN_(void) GetPrefBranch(nsIPrefBranch2 **);
NS_HIDDEN_(void) ParsePortList(nsIPrefBranch *prefBranch, const char *pref, PRBool remove);
nsresult InitializeSocketTransportService();
private:
PRPackedBool mOffline;
PRPackedBool mOfflineForProfileChange;

View File

@ -52,7 +52,6 @@
#include "nsIPrefService.h"
#include "nsIPrefBranch2.h"
#include "nsServiceManagerUtils.h"
#include "nsIOService.h"
#include "mozilla/FunctionTimer.h"
@ -396,10 +395,6 @@ nsSocketTransportService::Init()
if (mShuttingDown)
return NS_ERROR_UNEXPECTED;
// Don't initialize inside the offline mode
if (gIOService->IsOffline() && !gIOService->IsComingOnline())
return NS_ERROR_OFFLINE;
if (!mThreadEvent) {
mThreadEvent = PR_NewPollableEvent();
//

View File

@ -57,7 +57,6 @@
#include "prmon.h"
#include "prio.h"
#include "plstr.h"
#include "nsIOService.h"
#include "mozilla/FunctionTimer.h"
@ -383,13 +382,6 @@ nsDNSService::Init()
if (enableIDN)
idn = do_GetService(NS_IDNSERVICE_CONTRACTID);
nsDNSPrefetch::Initialize(this);
// Don't initialize the resolver if we're in offline mode.
// Later on, the IO service will reinitialize us when going online.
if (gIOService->IsOffline() && !gIOService->IsComingOnline())
return NS_OK;
nsRefPtr<nsHostResolver> res;
nsresult rv = nsHostResolver::Create(maxCacheEntries,
maxCacheLifetime,
@ -405,6 +397,8 @@ nsDNSService::Init()
// Disable prefetching either by explicit preference or if a manual proxy is configured
mDisablePrefetch = disablePrefetch || (proxyType == nsIProtocolProxyService::PROXYCONFIG_MANUAL);
}
nsDNSPrefetch::Initialize(this);
return rv;
}
@ -577,8 +571,8 @@ nsDNSService::Observe(nsISupports *subject, const char *topic, const PRUnichar *
if (mResolver) {
Shutdown();
Init();
}
Init();
return NS_OK;
}

View File

@ -43,7 +43,6 @@
#include "nsAutoLock.h"
#include "nsNetCID.h"
#include "nsCOMPtr.h"
#include "nsNetUtil.h"
#include "nsIServiceManager.h"
@ -101,32 +100,6 @@ nsHttpConnectionMgr::~nsHttpConnectionMgr()
nsAutoMonitor::DestroyMonitor(mMonitor);
}
nsresult
nsHttpConnectionMgr::EnsureSocketThreadTargetIfOnline()
{
nsresult rv;
nsCOMPtr<nsIEventTarget> sts;
nsCOMPtr<nsIIOService> ioService = do_GetIOService(&rv);
if (NS_SUCCEEDED(rv)) {
PRBool offline = PR_TRUE;
ioService->GetOffline(&offline);
if (!offline) {
sts = do_GetService(NS_SOCKETTRANSPORTSERVICE_CONTRACTID, &rv);
}
}
nsAutoMonitor mon(mMonitor);
// do nothing if already initialized
if (mSocketThreadTarget)
return NS_OK;
mSocketThreadTarget = sts;
return rv;
}
nsresult
nsHttpConnectionMgr::Init(PRUint16 maxConns,
PRUint16 maxConnsPerHost,
@ -138,19 +111,28 @@ nsHttpConnectionMgr::Init(PRUint16 maxConns,
{
LOG(("nsHttpConnectionMgr::Init\n"));
{
nsAutoMonitor mon(mMonitor);
nsresult rv;
nsCOMPtr<nsIEventTarget> sts = do_GetService(NS_SOCKETTRANSPORTSERVICE_CONTRACTID, &rv);
if (NS_FAILED(rv)) return rv;
mMaxConns = maxConns;
mMaxConnsPerHost = maxConnsPerHost;
mMaxConnsPerProxy = maxConnsPerProxy;
mMaxPersistConnsPerHost = maxPersistConnsPerHost;
mMaxPersistConnsPerProxy = maxPersistConnsPerProxy;
mMaxRequestDelay = maxRequestDelay;
mMaxPipelinedRequests = maxPipelinedRequests;
}
nsAutoMonitor mon(mMonitor);
return EnsureSocketThreadTargetIfOnline();
// do nothing if already initialized
if (mSocketThreadTarget)
return NS_OK;
// no need to do any special synchronization here since there cannot be
// any activity on the socket thread (because Shutdown is synchronous).
mMaxConns = maxConns;
mMaxConnsPerHost = maxConnsPerHost;
mMaxConnsPerProxy = maxConnsPerProxy;
mMaxPersistConnsPerHost = maxPersistConnsPerHost;
mMaxPersistConnsPerProxy = maxPersistConnsPerProxy;
mMaxRequestDelay = maxRequestDelay;
mMaxPipelinedRequests = maxPipelinedRequests;
mSocketThreadTarget = sts;
return rv;
}
nsresult
@ -184,12 +166,6 @@ nsHttpConnectionMgr::Shutdown()
nsresult
nsHttpConnectionMgr::PostEvent(nsConnEventHandler handler, PRInt32 iparam, void *vparam)
{
// This object doesn't get reinitialized if the offline state changes, so our
// socket thread target might be uninitialized if we were offline when this
// object was being initialized, and we go online later on. This call takes
// care of initializing the socket thread target if that's the case.
EnsureSocketThreadTargetIfOnline();
nsAutoMonitor mon(mMonitor);
nsresult rv;
@ -309,12 +285,6 @@ nsHttpConnectionMgr::PruneDeadConnections()
nsresult
nsHttpConnectionMgr::GetSocketThreadTarget(nsIEventTarget **target)
{
// This object doesn't get reinitialized if the offline state changes, so our
// socket thread target might be uninitialized if we were offline when this
// object was being initialized, and we go online later on. This call takes
// care of initializing the socket thread target if that's the case.
EnsureSocketThreadTargetIfOnline();
nsAutoMonitor mon(mMonitor);
NS_IF_ADDREF(*target = mSocketThreadTarget);
return NS_OK;

View File

@ -215,7 +215,6 @@ private:
PRUint8 caps, nsHttpConnection *);
PRBool BuildPipeline(nsConnectionEntry *, nsAHttpTransaction *, nsHttpPipeline **);
nsresult ProcessNewTransaction(nsHttpTransaction *);
nsresult EnsureSocketThreadTargetIfOnline();
// message handlers have this signature
typedef void (nsHttpConnectionMgr:: *nsConnEventHandler)(PRInt32, void *);

View File

@ -1,10 +0,0 @@
function run_test() {
var ioService = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
var linkService = Components.classes["@mozilla.org/network/network-link-service;1"]
.getService(Components.interfaces.nsINetworkLinkService);
// The offline status should depends on the link status
do_check_neq(ioService.offline, linkService.isLinkUp);
}

View File

@ -1,8 +0,0 @@
function run_test() {
try {
var sts = Components.classes["@mozilla.org/network/socket-transport-service;1"]
.getService(Components.interfaces.nsISocketTransportService);
} catch(e) {}
do_check_true(!!sts);
}