netwerk/ipc/SocketProcessParent.cpp
author Kershaw Chang <kershaw@mozilla.com>
Fri, 11 Jan 2019 18:57:23 +0000
changeset 453535 c083f11eb58d
parent 453470 4e94bbb90315
child 453472 edbda5ee5fd5
permissions -rw-r--r--
Bug 1513057 - P1: Start the new socket process basics (prefs, full xpcom init, logging, no sandboxing) r=mayhemer,dragana Differential Revision: https://phabricator.services.mozilla.com/D14148

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "SocketProcessParent.h"
#include "SocketProcessHost.h"
#include "mozilla/Move.h"

namespace mozilla {
namespace net {

SocketProcessParent::SocketProcessParent(SocketProcessHost* aHost)
    : mHost(aHost) {
  MOZ_ASSERT(mHost);

  MOZ_COUNT_CTOR(SocketProcessParent);
}

SocketProcessParent::~SocketProcessParent() {
  MOZ_COUNT_DTOR(SocketProcessParent);
}

void SocketProcessParent::ActorDestroy(ActorDestroyReason aWhy) {
  if (mHost) {
    mHost->OnChannelClosed();
  }
}

// To ensure that IPDL is finished before SocketParent gets deleted.
class DeferredDeleteSocketProcessParent : public Runnable {
 public:
  explicit DeferredDeleteSocketProcessParent(
      UniquePtr<SocketProcessParent>&& aParent)
      : Runnable("net::DeferredDeleteSocketProcessParent"),
        mParent(std::move(aParent)) {}

  NS_IMETHODIMP Run() override { return NS_OK; }

 private:
  UniquePtr<SocketProcessParent> mParent;
};

/* static */ void SocketProcessParent::Destroy(
    UniquePtr<SocketProcessParent>&& aParent) {
  NS_DispatchToMainThread(
      new DeferredDeleteSocketProcessParent(std::move(aParent)));
}

}  // namespace net
}  // namespace mozilla