Bug 1838739 - Initialize result of SetAsGPUOutOfMemoryError. r=webgpu-reviewers,nical
[gecko.git] / netwerk / dns / NativeDNSResolverOverrideParent.cpp
blob7be0c210a57e2c5806b879344528148db72a6b1d
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 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 "NativeDNSResolverOverrideParent.h"
9 #include "mozilla/ClearOnShutdown.h"
10 #include "mozilla/net/SocketProcessParent.h"
11 #include "nsIOService.h"
12 #include "DNS.h"
14 namespace mozilla {
15 namespace net {
17 NS_IMPL_ISUPPORTS(NativeDNSResolverOverrideParent, nsINativeDNSResolverOverride)
19 static StaticRefPtr<NativeDNSResolverOverrideParent>
20 gNativeDNSResolverOverrideParent;
22 // static
23 already_AddRefed<nsINativeDNSResolverOverride>
24 NativeDNSResolverOverrideParent::GetSingleton() {
25 if (gNativeDNSResolverOverrideParent) {
26 return do_AddRef(gNativeDNSResolverOverrideParent);
29 if (!gIOService) {
30 return nullptr;
33 gNativeDNSResolverOverrideParent = new NativeDNSResolverOverrideParent();
34 ClearOnShutdown(&gNativeDNSResolverOverrideParent);
36 auto initTask = []() {
37 Unused << SocketProcessParent::GetSingleton()
38 ->SendPNativeDNSResolverOverrideConstructor(
39 gNativeDNSResolverOverrideParent);
41 gIOService->CallOrWaitForSocketProcess(initTask);
42 return do_AddRef(gNativeDNSResolverOverrideParent);
45 NS_IMETHODIMP NativeDNSResolverOverrideParent::AddIPOverride(
46 const nsACString& aHost, const nsACString& aIPLiteral) {
47 NetAddr tempAddr;
48 if (!aIPLiteral.Equals("N/A"_ns) &&
49 NS_FAILED(tempAddr.InitFromString(aIPLiteral))) {
50 return NS_ERROR_UNEXPECTED;
53 RefPtr<NativeDNSResolverOverrideParent> self = this;
54 nsCString host(aHost);
55 nsCString ip(aIPLiteral);
56 auto task = [self{std::move(self)}, host, ip]() {
57 Unused << self->SendAddIPOverride(host, ip);
59 gIOService->CallOrWaitForSocketProcess(task);
60 return NS_OK;
63 NS_IMETHODIMP NativeDNSResolverOverrideParent::SetCnameOverride(
64 const nsACString& aHost, const nsACString& aCNAME) {
65 if (aCNAME.IsEmpty()) {
66 return NS_ERROR_UNEXPECTED;
69 RefPtr<NativeDNSResolverOverrideParent> self = this;
70 nsCString host(aHost);
71 nsCString cname(aCNAME);
72 auto task = [self{std::move(self)}, host, cname]() {
73 Unused << self->SendSetCnameOverride(host, cname);
75 gIOService->CallOrWaitForSocketProcess(task);
76 return NS_OK;
79 NS_IMETHODIMP NativeDNSResolverOverrideParent::ClearHostOverride(
80 const nsACString& aHost) {
81 RefPtr<NativeDNSResolverOverrideParent> self = this;
82 nsCString host(aHost);
83 auto task = [self{std::move(self)}, host]() {
84 Unused << self->SendClearHostOverride(host);
86 gIOService->CallOrWaitForSocketProcess(task);
87 return NS_OK;
90 NS_IMETHODIMP NativeDNSResolverOverrideParent::ClearOverrides() {
91 RefPtr<NativeDNSResolverOverrideParent> self = this;
92 auto task = [self{std::move(self)}]() {
93 Unused << self->SendClearOverrides();
95 gIOService->CallOrWaitForSocketProcess(task);
96 return NS_OK;
99 } // namespace net
100 } // namespace mozilla