Bug 1239955 - Let DNSService rely on IOService::Offline, r=bagder

This commit is contained in:
Kershaw Chang 2016-02-17 22:29:00 +01:00
Родитель 140ab016c2
Коммит d5f84ee56f
6 изменённых файлов: 26 добавлений и 39 удалений

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

@ -1021,9 +1021,6 @@ nsIOService::SetOffline(bool offline)
NS_IOSERVICE_GOING_OFFLINE_TOPIC,
offlineString.get());
if (mDNSService)
mDNSService->SetOffline(true);
if (mSocketTransportService)
mSocketTransportService->SetOffline(true);
@ -1036,7 +1033,6 @@ nsIOService::SetOffline(bool offline)
else if (!offline && mOffline) {
// go online
if (mDNSService) {
mDNSService->SetOffline(false);
DebugOnly<nsresult> rv = mDNSService->Init();
NS_ASSERTION(NS_SUCCEEDED(rv), "DNS service init failed");
}

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

@ -4,11 +4,13 @@
#include "mozilla/net/ChildDNSService.h"
#include "nsIDNSListener.h"
#include "nsIIOService.h"
#include "nsIThread.h"
#include "nsThreadUtils.h"
#include "nsIXPConnect.h"
#include "nsIPrefService.h"
#include "nsIProtocolProxyService.h"
#include "nsNetCID.h"
#include "mozilla/net/NeckoChild.h"
#include "mozilla/net/DNSListenerProxy.h"
#include "nsServiceManagerUtils.h"
@ -42,7 +44,6 @@ NS_IMPL_ISUPPORTS(ChildDNSService,
ChildDNSService::ChildDNSService()
: mFirstTime(true)
, mOffline(false)
, mDisablePrefetch(false)
, mPendingRequestsLock("DNSPendingRequestsLock")
{
@ -103,7 +104,7 @@ ChildDNSService::AsyncResolveExtended(const nsACString &hostname,
// Support apps being 'offline' even if parent is not: avoids DNS traffic by
// apps that have been told they are offline.
if (mOffline) {
if (GetOffline()) {
flags |= RESOLVE_OFFLINE;
}
@ -298,18 +299,15 @@ ChildDNSService::SetPrefetchEnabled(bool inVal)
return NS_OK;
}
NS_IMETHODIMP
ChildDNSService::GetOffline(bool* aResult)
bool
ChildDNSService::GetOffline() const
{
*aResult = mOffline;
return NS_OK;
}
NS_IMETHODIMP
ChildDNSService::SetOffline(bool value)
{
mOffline = value;
return NS_OK;
bool offline = false;
nsCOMPtr<nsIIOService> io = do_GetService(NS_IOSERVICE_CONTRACTID);
if (io) {
io->GetOffline(&offline);
}
return offline;
}
//-----------------------------------------------------------------------------

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

@ -35,6 +35,8 @@ public:
static ChildDNSService* GetSingleton();
void NotifyRequestDone(DNSRequestChild *aDnsRequest);
bool GetOffline() const;
private:
virtual ~ChildDNSService();
@ -45,7 +47,6 @@ private:
nsACString &aHashKey);
bool mFirstTime;
bool mOffline;
bool mDisablePrefetch;
// We need to remember pending dns requests to be able to cancel them.

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

@ -483,7 +483,6 @@ nsDNSService::nsDNSService()
, mDisableIPv6(false)
, mDisablePrefetch(false)
, mFirstTime(true)
, mOffline(false)
, mNotifyResolution(false)
, mOfflineLocalhost(false)
{
@ -677,18 +676,15 @@ nsDNSService::Shutdown()
return NS_OK;
}
NS_IMETHODIMP
nsDNSService::GetOffline(bool *offline)
bool
nsDNSService::GetOffline() const
{
*offline = mOffline;
return NS_OK;
}
NS_IMETHODIMP
nsDNSService::SetOffline(bool offline)
{
mOffline = offline;
return NS_OK;
bool offline = false;
nsCOMPtr<nsIIOService> io = do_GetService(NS_IOSERVICE_CONTRACTID);
if (io) {
io->GetOffline(&offline);
}
return offline;
}
NS_IMETHODIMP
@ -784,7 +780,7 @@ nsDNSService::AsyncResolveExtended(const nsACString &aHostname,
return rv;
}
if (mOffline &&
if (GetOffline() &&
(!mOfflineLocalhost || !hostname.LowerCaseEqualsASCII("localhost"))) {
flags |= RESOLVE_OFFLINE;
}
@ -899,7 +895,7 @@ nsDNSService::Resolve(const nsACString &aHostname,
return rv;
}
if (mOffline &&
if (GetOffline() &&
(!mOfflineLocalhost || !hostname.LowerCaseEqualsASCII("localhost"))) {
flags |= RESOLVE_OFFLINE;
}

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

@ -36,6 +36,8 @@ public:
size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const;
bool GetOffline() const;
private:
~nsDNSService();
@ -62,7 +64,6 @@ private:
bool mDisablePrefetch;
bool mBlockDotOnion;
bool mFirstTime;
bool mOffline;
bool mNotifyResolution;
bool mOfflineLocalhost;
nsTHashtable<nsCStringHashKey> mLocalDomains;

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

@ -10,7 +10,7 @@
* This is a private interface used by the internals of the networking library.
* It will never be frozen. Do not use it in external code.
*/
[scriptable, uuid(6b16fb1f-5709-4c94-a89f-a22be873c54d)]
[scriptable, uuid(24e598fd-7b1a-436c-9154-14d8b38df8a5)]
interface nsPIDNSService : nsIDNSService
{
/**
@ -31,9 +31,4 @@ interface nsPIDNSService : nsIDNSService
* Whether or not DNS prefetching (aka RESOLVE_SPECULATE) is enabled
*/
attribute boolean prefetchEnabled;
/**
* @return whether the DNS service is offline.
*/
attribute boolean offline;
};