tor-browser

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

IPDLActor.h (1493B)


      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 #ifndef MOZILLA_LAYERS_IPDLACTOR_H
      8 #define MOZILLA_LAYERS_IPDLACTOR_H
      9 
     10 #include "mozilla/ipc/ProtocolUtils.h"
     11 #include "mozilla/layers/CompositableForwarder.h"
     12 #include "gfxPlatform.h"
     13 
     14 namespace mozilla {
     15 namespace layers {
     16 
     17 /// A base class to facilitate the deallocation of IPDL actors.
     18 ///
     19 /// Implements the parent side of the simple deallocation handshake.
     20 /// Override the Destroy method rather than the ActorDestroy method.
     21 template <typename Protocol>
     22 class ParentActor : public Protocol {
     23 public:
     24  ParentActor() : mDestroyed(false) {}
     25 
     26  ~ParentActor() { MOZ_ASSERT(mDestroyed); }
     27 
     28  bool CanSend() const { return !mDestroyed; }
     29 
     30  // Override this rather than ActorDestroy
     31  virtual void Destroy() {}
     32 
     33  mozilla::ipc::IPCResult RecvDestroy() final {
     34    DestroyIfNeeded();
     35    (void)Protocol::Send__delete__(this);
     36    return IPC_OK();
     37  }
     38 
     39  typedef ipc::IProtocol::ActorDestroyReason Why;
     40 
     41  void ActorDestroy(Why) override { DestroyIfNeeded(); }
     42 
     43 protected:
     44  void DestroyIfNeeded() {
     45    if (!mDestroyed) {
     46      Destroy();
     47      mDestroyed = true;
     48    }
     49  }
     50 
     51 private:
     52  bool mDestroyed;
     53 };
     54 
     55 }  // namespace layers
     56 }  // namespace mozilla
     57 
     58 #endif