Bug 1472338: part 2) Change `clipboard.readText()` to read from the clipboard asynchr...
[gecko.git] / dom / reporting / EndpointForReportParent.cpp
blobd8bd9d3170b5b332ee0de10f0f721ed70088da9c
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/. */
7 #include "mozilla/dom/EndpointForReportParent.h"
8 #include "mozilla/dom/ReportingHeader.h"
9 #include "mozilla/ipc/PBackgroundSharedTypes.h"
10 #include "mozilla/Unused.h"
11 #include "nsIThread.h"
12 #include "nsThreadUtils.h"
14 namespace mozilla {
15 namespace dom {
17 EndpointForReportParent::EndpointForReportParent()
18 : mPBackgroundThread(NS_GetCurrentThread()), mActive(true) {}
20 EndpointForReportParent::~EndpointForReportParent() = default;
22 void EndpointForReportParent::ActorDestroy(ActorDestroyReason aWhy) {
23 mActive = false;
26 void EndpointForReportParent::Run(
27 const nsString& aGroupName,
28 const mozilla::ipc::PrincipalInfo& aPrincipalInfo) {
29 RefPtr<EndpointForReportParent> self = this;
31 NS_DispatchToMainThread(NS_NewRunnableFunction(
32 "EndpointForReportParent::Run", [self, 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 Unused << self->Send__delete__(self, uri);
40 }));
41 }));
44 } // namespace dom
45 } // namespace mozilla