EndpointForReportParent.cpp (1549B)
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 file, 5 * You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #include "mozilla/dom/EndpointForReportParent.h" 8 9 #include "mozilla/dom/ReportingHeader.h" 10 #include "mozilla/ipc/PBackgroundSharedTypes.h" 11 #include "nsIThread.h" 12 #include "nsThreadUtils.h" 13 14 namespace mozilla::dom { 15 16 EndpointForReportParent::EndpointForReportParent() 17 : mPBackgroundThread(NS_GetCurrentThread()), mActive(true) {} 18 19 EndpointForReportParent::~EndpointForReportParent() = default; 20 21 void EndpointForReportParent::ActorDestroy(ActorDestroyReason aWhy) { 22 mActive = false; 23 } 24 25 void EndpointForReportParent::Run( 26 const nsAString& aGroupName, 27 const mozilla::ipc::PrincipalInfo& aPrincipalInfo) { 28 RefPtr<EndpointForReportParent> self = this; 29 30 NS_DispatchToMainThread(NS_NewRunnableFunction( 31 "EndpointForReportParent::Run", 32 [self, aGroupName = nsString(aGroupName), aPrincipalInfo]() { 33 nsAutoCString uri; 34 ReportingHeader::GetEndpointForReport(aGroupName, aPrincipalInfo, uri); 35 self->mPBackgroundThread->Dispatch(NS_NewRunnableFunction( 36 "EndpointForReportParent::Answer", [self, uri]() { 37 if (self->mActive) { 38 (void)self->Send__delete__(self, uri); 39 } 40 })); 41 })); 42 } 43 44 } // namespace mozilla::dom