1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef TRRServiceBase_h_
7 #define TRRServiceBase_h_
9 #include "mozilla/Atomics.h"
10 #include "mozilla/DataMutex.h"
11 #include "mozilla/net/rust_helper.h"
13 #include "nsIDNSService.h"
14 #include "nsIProtocolProxyService2.h"
22 class nsHttpConnectionInfo
;
24 static const char kRolloutURIPref
[] = "doh-rollout.uri";
25 static const char kRolloutModePref
[] = "doh-rollout.mode";
27 class TRRServiceBase
: public nsIProxyConfigChangedCallback
{
29 NS_DECL_THREADSAFE_ISUPPORTS
32 nsIDNSService::ResolverMode
Mode() { return mMode
; }
33 virtual void GetURI(nsACString
& result
) = 0;
34 already_AddRefed
<nsHttpConnectionInfo
> TRRConnectionInfo();
35 // Called to initialize the connection info. Once the connection info is
36 // created first time, mTRRConnectionInfoInited will be set to true.
37 virtual void InitTRRConnectionInfo();
38 bool TRRConnectionInfoInited() const { return mTRRConnectionInfoInited
; }
41 virtual ~TRRServiceBase();
43 virtual bool MaybeSetPrivateURI(const nsACString
& aURI
) = 0;
44 void ProcessURITemplate(nsACString
& aURI
);
45 // Checks the network.trr.uri or the doh-rollout.uri prefs and sets the URI
46 // in order of preference:
47 // 1. The value of network.trr.uri if it is not the default one, meaning
48 // is was set by an explicit user action
49 // 2. The value of doh-rollout.uri if it exists
50 // this is set by the rollout addon
51 // 3. The default value of network.trr.uri
54 void OnTRRModeChange();
55 void OnTRRURIChange();
57 void DoReadEtcHostsFile(ParsingCallback aCallback
);
58 virtual void ReadEtcHostsFile() = 0;
59 // Called to create a connection info that will be used by TRRServiceChannel.
60 // Note that when this function is called, mDefaultTRRConnectionInfo will be
61 // set to null to invalidate the connection info.
62 // When the connection info is created, SetDefaultTRRConnectionInfo() is
63 // called to set the result to mDefaultTRRConnectionInfo.
64 // Note that this method does nothing when mTRRConnectionInfoInited is false.
65 // We want to starting updating the connection info after it's create first
67 void AsyncCreateTRRConnectionInfo(const nsACString
& aURI
);
68 void AsyncCreateTRRConnectionInfoInternal(const nsACString
& aURI
);
69 virtual void SetDefaultTRRConnectionInfo(nsHttpConnectionInfo
* aConnInfo
);
70 void RegisterProxyChangeListener();
71 void UnregisterProxyChangeListener();
73 nsCString mPrivateURI
; // protected by mMutex
74 // Pref caches should only be used on the main thread.
76 nsCString mRolloutURIPref
;
77 nsCString mDefaultURIPref
;
78 nsCString mOHTTPURIPref
;
80 Atomic
<nsIDNSService::ResolverMode
, Relaxed
> mMode
{
81 nsIDNSService::MODE_NATIVEONLY
};
82 Atomic
<bool, Relaxed
> mURISetByDetection
{false};
83 Atomic
<bool, Relaxed
> mTRRConnectionInfoInited
{false};
84 DataMutex
<RefPtr
<nsHttpConnectionInfo
>> mDefaultTRRConnectionInfo
;
88 } // namespace mozilla
90 #endif // TRRServiceBase_h_