Merge backout of bug 614286; a=bustage-fix

This commit is contained in:
Ehsan Akhgari 2010-11-30 13:58:01 -05:00
Родитель 3402cba7c8 7daaa00ea9
Коммит 4680bdd42c
8 изменённых файлов: 41 добавлений и 116 удалений

Просмотреть файл

@ -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)
@ -192,10 +192,20 @@ nsIOService::Init()
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");
@ -285,28 +295,6 @@ 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() {
if (!gIOService) {
@ -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

Просмотреть файл

@ -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;

Просмотреть файл

@ -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();
//

Просмотреть файл

@ -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();
}
return NS_OK;
}

Просмотреть файл

@ -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,9 +111,18 @@ nsHttpConnectionMgr::Init(PRUint16 maxConns,
{
LOG(("nsHttpConnectionMgr::Init\n"));
{
nsresult rv;
nsCOMPtr<nsIEventTarget> sts = do_GetService(NS_SOCKETTRANSPORTSERVICE_CONTRACTID, &rv);
if (NS_FAILED(rv)) return rv;
nsAutoMonitor mon(mMonitor);
// 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;
@ -148,9 +130,9 @@ nsHttpConnectionMgr::Init(PRUint16 maxConns,
mMaxPersistConnsPerProxy = maxPersistConnsPerProxy;
mMaxRequestDelay = maxRequestDelay;
mMaxPipelinedRequests = maxPipelinedRequests;
}
return EnsureSocketThreadTargetIfOnline();
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;

Просмотреть файл

@ -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 *);

Просмотреть файл

@ -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);
}

Просмотреть файл

@ -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);
}