tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

ClientSourceChild.cpp (2266B)


      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/. */
      6 
      7 #include "ClientSourceChild.h"
      8 
      9 #include "ClientSource.h"
     10 #include "ClientSourceOpChild.h"
     11 #include "mozilla/dom/ClientIPCTypes.h"
     12 
     13 namespace mozilla::dom {
     14 
     15 using mozilla::ipc::IPCResult;
     16 
     17 void ClientSourceChild::ActorDestroy(ActorDestroyReason aReason) {
     18  if (mSource) {
     19    mSource->RevokeActor(this);
     20 
     21    // Revoking the actor link should automatically cause the owner
     22    // to call RevokeOwner() as well.
     23    MOZ_DIAGNOSTIC_ASSERT(!mSource);
     24  }
     25 }
     26 
     27 PClientSourceOpChild* ClientSourceChild::AllocPClientSourceOpChild(
     28    const ClientOpConstructorArgs& aArgs) {
     29  return new ClientSourceOpChild();
     30 }
     31 
     32 bool ClientSourceChild::DeallocPClientSourceOpChild(
     33    PClientSourceOpChild* aActor) {
     34  static_cast<ClientSourceOpChild*>(aActor)->ScheduleDeletion();
     35  return true;
     36 }
     37 
     38 IPCResult ClientSourceChild::RecvPClientSourceOpConstructor(
     39    PClientSourceOpChild* aActor, const ClientOpConstructorArgs& aArgs) {
     40  auto actor = static_cast<ClientSourceOpChild*>(aActor);
     41  actor->Init(aArgs);
     42  return IPC_OK();
     43 }
     44 
     45 mozilla::ipc::IPCResult ClientSourceChild::RecvEvictFromBFCache() {
     46  if (mSource) {
     47    mSource->EvictFromBFCache();
     48  }
     49 
     50  return IPC_OK();
     51 }
     52 
     53 ClientSourceChild::ClientSourceChild(const ClientSourceConstructorArgs& aArgs)
     54    : mSource(nullptr), mTeardownStarted(false) {}
     55 
     56 void ClientSourceChild::SetOwner(ClientThing<ClientSourceChild>* aThing) {
     57  MOZ_DIAGNOSTIC_ASSERT(aThing);
     58  MOZ_DIAGNOSTIC_ASSERT(!mSource);
     59  mSource = static_cast<ClientSource*>(aThing);
     60 }
     61 
     62 void ClientSourceChild::RevokeOwner(ClientThing<ClientSourceChild>* aThing) {
     63  MOZ_DIAGNOSTIC_ASSERT(mSource);
     64  MOZ_DIAGNOSTIC_ASSERT(mSource == static_cast<ClientSource*>(aThing));
     65  mSource = nullptr;
     66 }
     67 
     68 ClientSource* ClientSourceChild::GetSource() const { return mSource; }
     69 
     70 void ClientSourceChild::MaybeStartTeardown() {
     71  if (mTeardownStarted) {
     72    return;
     73  }
     74  mTeardownStarted = true;
     75  (void)SendTeardown();
     76 }
     77 
     78 }  // namespace mozilla::dom