Skip to content

Commit

Permalink
Bug 1687587 - Move no-op DNS listener to nsHTMLDNSPrefetch.cpp. r=smaug
Browse files Browse the repository at this point in the history
No reason it lives in a header file.

Depends on D102367

Differential Revision: https://phabricator.services.mozilla.com/D102368
  • Loading branch information
emilio committed Jan 20, 2021
1 parent a70873c commit 7273a90
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 29 deletions.
39 changes: 23 additions & 16 deletions dom/html/nsHTMLDNSPrefetch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,32 @@ using namespace mozilla;
using namespace mozilla::dom;
using namespace mozilla::net;

class NoOpDNSListener final : public nsIDNSListener {
// This class exists to give a safe callback no-op DNSListener
public:
NS_DECL_THREADSAFE_ISUPPORTS
NS_DECL_NSIDNSLISTENER

NoOpDNSListener() = default;

private:
~NoOpDNSListener() = default;
};


NS_IMPL_ISUPPORTS(NoOpDNSListener, nsIDNSListener)

NS_IMETHODIMP
NoOpDNSListener::OnLookupComplete(nsICancelable* request, nsIDNSRecord* rec,
nsresult status) {
return NS_OK;
}

static NS_DEFINE_CID(kDNSServiceCID, NS_DNSSERVICE_CID);
static bool sInitialized = false;
static nsIDNSService* sDNSService = nullptr;
static nsHTMLDNSPrefetch::nsDeferrals* sPrefetches = nullptr;
static nsHTMLDNSPrefetch::nsListener* sDNSListener = nullptr;
static NoOpDNSListener* sDNSListener = nullptr;

nsresult nsHTMLDNSPrefetch::Initialize() {
if (sInitialized) {
Expand All @@ -57,7 +78,7 @@ nsresult nsHTMLDNSPrefetch::Initialize() {
sPrefetches = new nsHTMLDNSPrefetch::nsDeferrals();
NS_ADDREF(sPrefetches);

sDNSListener = new nsHTMLDNSPrefetch::nsListener();
sDNSListener = new NoOpDNSListener();
NS_ADDREF(sDNSListener);

sPrefetches->Activate();
Expand Down Expand Up @@ -274,23 +295,9 @@ void nsHTMLDNSPrefetch::LinkDestroyed(Link* aLink) {
}
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////

NS_IMPL_ISUPPORTS(nsHTMLDNSPrefetch::nsListener, nsIDNSListener)

NS_IMETHODIMP
nsHTMLDNSPrefetch::nsListener::OnLookupComplete(nsICancelable* request,
nsIDNSRecord* rec,
nsresult status) {
return NS_OK;
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////

nsHTMLDNSPrefetch::nsDeferrals::nsDeferrals()
: mHead(0), mTail(0), mActiveLoaderCount(0), mTimerArmed(false) {
mTimer = NS_NewTimer();
;
}

nsHTMLDNSPrefetch::nsDeferrals::~nsDeferrals() {
Expand Down
13 changes: 0 additions & 13 deletions dom/html/nsHTMLDNSPrefetch.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#define nsHTMLDNSPrefetch_h___

#include "nsCOMPtr.h"
#include "nsIDNSListener.h"
#include "nsIObserver.h"
#include "nsIRequest.h"
#include "nsIWebProgressListener.h"
Expand Down Expand Up @@ -84,18 +83,6 @@ class nsHTMLDNSPrefetch {
uint32_t flags, nsresult aReason);

public:
class nsListener final : public nsIDNSListener {
// This class exists to give a safe callback no-op DNSListener
public:
NS_DECL_THREADSAFE_ISUPPORTS
NS_DECL_NSIDNSLISTENER

nsListener() = default;

private:
~nsListener() = default;
};

class nsDeferrals final : public nsIWebProgressListener,
public nsSupportsWeakReference,
public nsIObserver {
Expand Down

0 comments on commit 7273a90

Please sign in to comment.