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 09:40:54 +00:00
Родитель ec269a8014
Коммит b805de3013
6 изменённых файлов: 36 добавлений и 9 удалений

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

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

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

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

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

@ -663,6 +663,16 @@ void TRRService::RebuildSuffixList(nsTArray<nsCString>&& aSuffixList) {
}
}
void TRRService::ConfirmationContext::SetState(
enum ConfirmationState aNewState) {
mState = aNewState;
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 +696,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 +739,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 +817,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

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

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

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

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

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

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