Bug 1737198 - Part 8: Expose Confirmation State for testing. r=kershaw,necko-reviewers

Differential Revision: https://phabricator.services.mozilla.com/D132671
This commit is contained in:
Nihanth Subramanya 2021-12-02 13:21:55 +00:00
parent e35125acf0
commit a2d8d6fe02
6 changed files with 44 additions and 9 deletions

View File

@ -322,7 +322,12 @@ ChildDNSService::GetCurrentTrrMode(nsIDNSService::ResolverMode* aMode) {
NS_IMETHODIMP
ChildDNSService::GetCurrentTrrConfirmationState(uint32_t* aConfirmationState) {
return NS_ERROR_NOT_IMPLEMENTED;
if (!mTRRServiceParent) {
return NS_ERROR_NOT_AVAILABLE;
}
*aConfirmationState = mTRRServiceParent->GetConfirmationState();
return NS_OK;
}
NS_IMETHODIMP

View File

@ -19,6 +19,7 @@ namespace net {
parent:
async NotifyNetworkConnectivityServiceObservers(nsCString aTopic);
async InitTRRConnectionInfo();
async SetConfirmationState(uint32_t aNewState);
child:
async __delete__();

View File

@ -663,6 +663,24 @@ void TRRService::RebuildSuffixList(nsTArray<nsCString>&& aSuffixList) {
}
}
void TRRService::ConfirmationContext::SetState(
enum ConfirmationState aNewState) {
mState = aNewState;
if (XRE_IsParentProcess()) {
return;
}
MOZ_ASSERT(XRE_IsSocketProcess());
MOZ_ASSERT(NS_IsMainThread());
TRRServiceChild* child = TRRServiceChild::GetSingleton();
if (child && child->CanSend()) {
LOG(("TRRService::SendSetConfirmationState"));
Unused << child->SendSetConfirmationState(mState);
}
}
void TRRService::ConfirmationContext::HandleEvent(ConfirmationEvent aEvent) {
MutexAutoLock lock(OwningObject()->mLock);
HandleEvent(aEvent, lock);
@ -686,26 +704,26 @@ void TRRService::ConfirmationContext::HandleEvent(ConfirmationEvent aEvent,
if (TRR_DISABLED(mode)) {
LOG(("TRR is disabled. mConfirmation.mState -> CONFIRM_OFF"));
mState = CONFIRM_OFF;
SetState(CONFIRM_OFF);
return;
}
if (mode == nsIDNSService::MODE_TRRONLY) {
LOG(("TRR_ONLY_MODE. mConfirmation.mState -> CONFIRM_DISABLED"));
mState = CONFIRM_DISABLED;
SetState(CONFIRM_DISABLED);
return;
}
if (service->mConfirmationNS.Equals("skip"_ns)) {
LOG((
"mConfirmationNS == skip. mConfirmation.mState -> CONFIRM_DISABLED"));
mState = CONFIRM_DISABLED;
SetState(CONFIRM_DISABLED);
return;
}
// The next call to maybeConfirm will transition to CONFIRM_TRYING_OK
LOG(("mConfirmation.mState -> CONFIRM_OK"));
mState = CONFIRM_OK;
SetState(CONFIRM_OK);
};
auto maybeConfirm = [&](const char* aReason) {
@ -729,10 +747,10 @@ void TRRService::ConfirmationContext::HandleEvent(ConfirmationEvent aEvent,
if (mState == CONFIRM_FAILED) {
LOG(("mConfirmation.mState -> CONFIRM_TRYING_FAILED"));
mState = CONFIRM_TRYING_FAILED;
SetState(CONFIRM_TRYING_FAILED);
} else {
LOG(("mConfirmation.mState -> CONFIRM_TRYING_OK"));
mState = CONFIRM_TRYING_OK;
SetState(CONFIRM_TRYING_OK);
}
nsCOMPtr<nsITimer> timer = std::move(mTimer);
@ -807,13 +825,13 @@ void TRRService::ConfirmationContext::HandleEvent(ConfirmationEvent aEvent,
}
break;
case ConfirmationEvent::ConfirmOK:
mState = CONFIRM_OK;
SetState(CONFIRM_OK);
mTask = nullptr;
break;
case ConfirmationEvent::ConfirmFail:
MOZ_ASSERT(mState == CONFIRM_TRYING_OK ||
mState == CONFIRM_TRYING_FAILED);
mState = CONFIRM_FAILED;
SetState(CONFIRM_FAILED);
mTask = nullptr;
// retry failed NS confirmation

View File

@ -235,6 +235,8 @@ class TRRService : public TRRServiceBase,
// confirmation.
nsCString mFailedLookups;
void SetState(enum ConfirmationState aNewState);
public:
// Called when a confirmation completes successfully or when the
// confirmation context changes.

View File

@ -202,5 +202,11 @@ mozilla::ipc::IPCResult TRRServiceParent::RecvInitTRRConnectionInfo() {
return IPC_OK();
}
mozilla::ipc::IPCResult TRRServiceParent::RecvSetConfirmationState(
uint32_t aNewState) {
mConfirmationState = aNewState;
return IPC_OK();
}
} // namespace net
} // namespace mozilla

View File

@ -34,12 +34,15 @@ class TRRServiceParent : public TRRServiceBase,
mozilla::ipc::IPCResult RecvNotifyNetworkConnectivityServiceObservers(
const nsCString& aTopic);
mozilla::ipc::IPCResult RecvInitTRRConnectionInfo();
mozilla::ipc::IPCResult RecvSetConfirmationState(uint32_t aNewState);
uint32_t GetConfirmationState() { return mConfirmationState; }
private:
virtual ~TRRServiceParent();
virtual void ActorDestroy(ActorDestroyReason why) override;
void prefsChanged(const char* aName);
void SetDefaultTRRConnectionInfo(nsHttpConnectionInfo* aConnInfo) override;
uint32_t mConfirmationState = 0;
};
} // namespace net