Bug 1866894 - Update failing subtest for content-visibility-auto-resize.html. r=fredw
[gecko.git] / netwerk / dns / TRRServiceChild.cpp
blob37be446f8f77f21848d5cfdcd2b3022c1e9c8f51
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set sw=2 ts=8 et tw=80 : */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "mozilla/net/TRRServiceChild.h"
8 #include "mozilla/Atomics.h"
9 #include "mozilla/ClearOnShutdown.h"
10 #include "mozilla/Services.h"
11 #include "mozilla/StaticPtr.h"
12 #include "nsHttpConnectionInfo.h"
13 #include "nsIDNService.h"
14 #include "nsIObserverService.h"
15 #include "nsServiceManagerUtils.h"
16 #include "TRRService.h"
18 namespace mozilla {
19 namespace net {
21 static StaticRefPtr<nsIDNSService> sDNSService;
22 static Atomic<TRRServiceChild*> sTRRServiceChild;
24 NS_IMPL_ISUPPORTS(TRRServiceChild, nsIObserver, nsISupportsWeakReference)
26 TRRServiceChild::TRRServiceChild() {
27 MOZ_ASSERT(NS_IsMainThread());
28 sTRRServiceChild = this;
31 TRRServiceChild::~TRRServiceChild() {
32 MOZ_ASSERT(NS_IsMainThread());
33 sTRRServiceChild = nullptr;
36 /* static */
37 TRRServiceChild* TRRServiceChild::GetSingleton() {
38 MOZ_ASSERT(NS_IsMainThread());
39 return sTRRServiceChild;
42 void TRRServiceChild::Init(const bool& aCaptiveIsPassed,
43 const bool& aParentalControlEnabled,
44 nsTArray<nsCString>&& aDNSSuffixList) {
45 nsCOMPtr<nsIDNSService> dns =
46 do_GetService("@mozilla.org/network/dns-service;1");
47 sDNSService = dns;
48 ClearOnShutdown(&sDNSService);
49 MOZ_ASSERT(sDNSService);
51 TRRService* trrService = TRRService::Get();
52 MOZ_ASSERT(trrService);
54 trrService->mCaptiveIsPassed = aCaptiveIsPassed;
55 trrService->mParentalControlEnabled = aParentalControlEnabled;
56 trrService->RebuildSuffixList(std::move(aDNSSuffixList));
58 nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
59 obs->AddObserver(this, "network:connectivity-service:dns-checks-complete",
60 true);
61 obs->AddObserver(this, "network:connectivity-service:ip-checks-complete",
62 true);
65 NS_IMETHODIMP
66 TRRServiceChild::Observe(nsISupports* aSubject, const char* aTopic,
67 const char16_t* aData) {
68 if (!strcmp(aTopic, "network:connectivity-service:ip-checks-complete") ||
69 !strcmp(aTopic, "network:connectivity-service:dns-checks-complete")) {
70 Unused << SendNotifyNetworkConnectivityServiceObservers(
71 nsPrintfCString("%s-from-socket-process", aTopic));
74 return NS_OK;
77 mozilla::ipc::IPCResult TRRServiceChild::RecvUpdatePlatformDNSInformation(
78 nsTArray<nsCString>&& aDNSSuffixList) {
79 TRRService::Get()->RebuildSuffixList(std::move(aDNSSuffixList));
80 return IPC_OK();
83 mozilla::ipc::IPCResult TRRServiceChild::RecvUpdateParentalControlEnabled(
84 const bool& aEnabled) {
85 TRRService::Get()->mParentalControlEnabled = aEnabled;
86 return IPC_OK();
89 mozilla::ipc::IPCResult TRRServiceChild::RecvClearDNSCache(
90 const bool& aTrrToo) {
91 Unused << sDNSService->ClearCache(aTrrToo);
92 return IPC_OK();
95 mozilla::ipc::IPCResult TRRServiceChild::RecvSetDetectedTrrURI(
96 const nsCString& aURI) {
97 TRRService::Get()->SetDetectedTrrURI(aURI);
98 return IPC_OK();
101 mozilla::ipc::IPCResult TRRServiceChild::RecvSetDefaultTRRConnectionInfo(
102 Maybe<HttpConnectionInfoCloneArgs>&& aArgs) {
103 if (!aArgs) {
104 TRRService::Get()->SetDefaultTRRConnectionInfo(nullptr);
105 return IPC_OK();
108 RefPtr<nsHttpConnectionInfo> cinfo =
109 nsHttpConnectionInfo::DeserializeHttpConnectionInfoCloneArgs(aArgs.ref());
110 TRRService::Get()->SetDefaultTRRConnectionInfo(cinfo);
111 return IPC_OK();
114 mozilla::ipc::IPCResult TRRServiceChild::RecvUpdateEtcHosts(
115 nsTArray<nsCString>&& aHosts) {
116 TRRService::Get()->AddEtcHosts(aHosts);
117 return IPC_OK();
120 } // namespace net
121 } // namespace mozilla