tor-browser

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

ActorChild.cpp (1564B)


      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 "mozilla/dom/cache/ActorChild.h"
      8 
      9 #include "mozilla/dom/cache/CacheWorkerRef.h"
     10 #include "nsThreadUtils.h"
     11 
     12 namespace mozilla::dom::cache {
     13 
     14 void CacheActorChild::SetWorkerRef(SafeRefPtr<CacheWorkerRef> aWorkerRef) {
     15  // Some of the Cache actors can have multiple DOM objects associated with
     16  // them.  In this case the workerRef will be added multiple times.  This is
     17  // permitted, but the workerRef should be the same each time.
     18  if (mWorkerRef) {
     19    // XXX Here, we don't use aWorkerRef, so we unnecessarily add-refed... This
     20    // might be a case to show in the raw pointer guideline as a possible
     21    // exception, if warranted by performance analyses.
     22 
     23    MOZ_DIAGNOSTIC_ASSERT(mWorkerRef == aWorkerRef);
     24    return;
     25  }
     26 
     27  mWorkerRef = std::move(aWorkerRef);
     28  if (mWorkerRef) {
     29    mWorkerRef->AddActor(*this);
     30  }
     31 }
     32 
     33 void CacheActorChild::RemoveWorkerRef() {
     34  MOZ_ASSERT_IF(!NS_IsMainThread(), mWorkerRef);
     35  if (mWorkerRef) {
     36    mWorkerRef->RemoveActor(*this);
     37    mWorkerRef = nullptr;
     38  }
     39 }
     40 
     41 const SafeRefPtr<CacheWorkerRef>& CacheActorChild::GetWorkerRefPtr() const {
     42  return mWorkerRef;
     43 }
     44 
     45 CacheActorChild::~CacheActorChild() { MOZ_DIAGNOSTIC_ASSERT(!mWorkerRef); }
     46 
     47 }  // namespace mozilla::dom::cache