From 6cd518bee91151029c6e524f5b75714da17e54fa Mon Sep 17 00:00:00 2001 From: Valentin Gosu Date: Thu, 30 Sep 2021 11:58:52 +0000 Subject: [PATCH] Bug 1732961 - TRR should not be ignoring enterprise policy value of network.trr.uri/mode r=nhnt11 In bug 1626057 we added support for steering. There we made the distinction between a default network.trr.uri pref, and a user-set one by using `Preferences::HasUserValue`. However, it seems that enterprise policies change the default branch of the pref, so this would lead to it having a lower priority than DoHRollout or steering. In bug 1713036 we introduced `network.trr.default_provider_uri` and made `network.trr.uri` an empty string, so checking hasUserValue isn't required anymore. Differential Revision: https://phabricator.services.mozilla.com/D126961 --- netwerk/dns/TRRService.cpp | 4 ++-- netwerk/dns/TRRServiceBase.cpp | 3 +-- netwerk/dns/TRRServiceBase.h | 1 - netwerk/dns/TRRServiceParent.cpp | 8 ++++---- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/netwerk/dns/TRRService.cpp b/netwerk/dns/TRRService.cpp index b58867dde7fb..5960037afc68 100644 --- a/netwerk/dns/TRRService.cpp +++ b/netwerk/dns/TRRService.cpp @@ -231,9 +231,9 @@ bool TRRService::GetParentalControlEnabledInternal() { void TRRService::SetDetectedTrrURI(const nsACString& aURI) { LOG(("SetDetectedTrrURI(%s", nsPromiseFlatCString(aURI).get())); // If the user has set a custom URI then we don't want to override that. - // If the URI is set via doh-rollout.uri, mURIPrefHasUserValue will be false + // If the URI is set via doh-rollout.uri, mURIPref will be empty // (see TRRServiceBase::OnTRRURIChange) - if (mURIPrefHasUserValue) { + if (!mURIPref.IsEmpty()) { LOG(("Already has user value. Not setting URI")); return; } diff --git a/netwerk/dns/TRRServiceBase.cpp b/netwerk/dns/TRRServiceBase.cpp index 3320f8b9a4e0..571f393b242c 100644 --- a/netwerk/dns/TRRServiceBase.cpp +++ b/netwerk/dns/TRRServiceBase.cpp @@ -74,7 +74,7 @@ void TRRServiceBase::CheckURIPrefs() { mURISetByDetection = false; // The user has set a custom URI so it takes precedence. - if (mURIPrefHasUserValue) { + if (!mURIPref.IsEmpty()) { MaybeSetPrivateURI(mURIPref); return; } @@ -142,7 +142,6 @@ void TRRServiceBase::OnTRRModeChange() { } void TRRServiceBase::OnTRRURIChange() { - mURIPrefHasUserValue = Preferences::HasUserValue("network.trr.uri"); Preferences::GetCString("network.trr.uri", mURIPref); Preferences::GetCString(kRolloutURIPref, mRolloutURIPref); Preferences::GetCString("network.trr.default_provider_uri", mDefaultURIPref); diff --git a/netwerk/dns/TRRServiceBase.h b/netwerk/dns/TRRServiceBase.h index 4ca143231055..ae4331f0834a 100644 --- a/netwerk/dns/TRRServiceBase.h +++ b/netwerk/dns/TRRServiceBase.h @@ -41,7 +41,6 @@ class TRRServiceBase { nsCString mPrivateURI; // Pref caches should only be used on the main thread. - bool mURIPrefHasUserValue = false; nsCString mURIPref; nsCString mRolloutURIPref; nsCString mDefaultURIPref; diff --git a/netwerk/dns/TRRServiceParent.cpp b/netwerk/dns/TRRServiceParent.cpp index d40ba0d5d496..e7dc63ef77f0 100644 --- a/netwerk/dns/TRRServiceParent.cpp +++ b/netwerk/dns/TRRServiceParent.cpp @@ -106,15 +106,15 @@ bool TRRServiceParent::MaybeSetPrivateURI(const nsACString& aURI) { } void TRRServiceParent::SetDetectedTrrURI(const nsACString& aURI) { - if (mURIPrefHasUserValue) { + if (!mURIPref.IsEmpty()) { return; } mURISetByDetection = MaybeSetPrivateURI(aURI); - RefPtr self = this; - nsCString uri(aURI); gIOService->CallOrWaitForSocketProcess( - [self, uri]() { Unused << self->SendSetDetectedTrrURI(uri); }); + [self = RefPtr{this}, uri = nsAutoCString(aURI)]() { + Unused << self->SendSetDetectedTrrURI(uri); + }); } void TRRServiceParent::GetTrrURI(nsACString& aURI) { aURI = mPrivateURI; }