summaryrefslogtreecommitdiffstats
path: root/netwerk/dns/TRRServiceBase.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /netwerk/dns/TRRServiceBase.h
parentInitial commit. (diff)
downloadfirefox-upstream/124.0.1.tar.xz
firefox-upstream/124.0.1.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--netwerk/dns/TRRServiceBase.h90
1 files changed, 90 insertions, 0 deletions
diff --git a/netwerk/dns/TRRServiceBase.h b/netwerk/dns/TRRServiceBase.h
new file mode 100644
index 0000000000..a7f85fc95d
--- /dev/null
+++ b/netwerk/dns/TRRServiceBase.h
@@ -0,0 +1,90 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef TRRServiceBase_h_
+#define TRRServiceBase_h_
+
+#include "mozilla/Atomics.h"
+#include "mozilla/DataMutex.h"
+#include "mozilla/net/rust_helper.h"
+#include "nsString.h"
+#include "nsIDNSService.h"
+#include "nsIProtocolProxyService2.h"
+
+class nsICancelable;
+class nsIProxyInfo;
+
+namespace mozilla {
+namespace net {
+
+class nsHttpConnectionInfo;
+
+static const char kRolloutURIPref[] = "doh-rollout.uri";
+static const char kRolloutModePref[] = "doh-rollout.mode";
+
+class TRRServiceBase : public nsIProxyConfigChangedCallback {
+ public:
+ NS_DECL_THREADSAFE_ISUPPORTS
+
+ TRRServiceBase();
+ nsIDNSService::ResolverMode Mode() { return mMode; }
+ virtual void GetURI(nsACString& result) = 0;
+ already_AddRefed<nsHttpConnectionInfo> TRRConnectionInfo();
+ // Called to initialize the connection info. Once the connection info is
+ // created first time, mTRRConnectionInfoInited will be set to true.
+ virtual void InitTRRConnectionInfo();
+ bool TRRConnectionInfoInited() const { return mTRRConnectionInfoInited; }
+
+ protected:
+ virtual ~TRRServiceBase();
+
+ virtual bool MaybeSetPrivateURI(const nsACString& aURI) = 0;
+ void ProcessURITemplate(nsACString& aURI);
+ // Checks the network.trr.uri or the doh-rollout.uri prefs and sets the URI
+ // in order of preference:
+ // 1. The value of network.trr.uri if it is not the default one, meaning
+ // is was set by an explicit user action
+ // 2. The value of doh-rollout.uri if it exists
+ // this is set by the rollout addon
+ // 3. The default value of network.trr.uri
+ void CheckURIPrefs();
+
+ void OnTRRModeChange();
+ void OnTRRURIChange();
+
+ void DoReadEtcHostsFile(ParsingCallback aCallback);
+ virtual void ReadEtcHostsFile() = 0;
+ // Called to create a connection info that will be used by TRRServiceChannel.
+ // Note that when this function is called, mDefaultTRRConnectionInfo will be
+ // set to null to invalidate the connection info.
+ // When the connection info is created, SetDefaultTRRConnectionInfo() is
+ // called to set the result to mDefaultTRRConnectionInfo.
+ // Note that this method does nothing when mTRRConnectionInfoInited is false.
+ // We want to starting updating the connection info after it's create first
+ // time.
+ void AsyncCreateTRRConnectionInfo(const nsACString& aURI);
+ void AsyncCreateTRRConnectionInfoInternal(const nsACString& aURI);
+ virtual void SetDefaultTRRConnectionInfo(nsHttpConnectionInfo* aConnInfo);
+ void RegisterProxyChangeListener();
+ void UnregisterProxyChangeListener();
+
+ nsCString mPrivateURI; // protected by mMutex
+ // Pref caches should only be used on the main thread.
+ nsCString mURIPref;
+ nsCString mRolloutURIPref;
+ nsCString mDefaultURIPref;
+ nsCString mOHTTPURIPref;
+
+ Atomic<nsIDNSService::ResolverMode, Relaxed> mMode{
+ nsIDNSService::MODE_NATIVEONLY};
+ Atomic<bool, Relaxed> mURISetByDetection{false};
+ Atomic<bool, Relaxed> mTRRConnectionInfoInited{false};
+ DataMutex<RefPtr<nsHttpConnectionInfo>> mDefaultTRRConnectionInfo;
+};
+
+} // namespace net
+} // namespace mozilla
+
+#endif // TRRServiceBase_h_