tor-browser

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

CacheInvalidator.cpp (1295B)


      1 /* -*- Mode: C++; tab-width: 13; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=13 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 "CacheInvalidator.h"
      8 
      9 namespace mozilla {
     10 
     11 void CacheInvalidator::InvalidateCaches() const {
     12  // The only sane approach is to require caches to remove invalidators.
     13  while (!mCaches.empty()) {
     14    const auto& itr = mCaches.begin();
     15    const auto pEntry = *itr;
     16    pEntry->OnInvalidate();
     17    MOZ_ASSERT(mCaches.find(pEntry) == mCaches.end());
     18  }
     19 }
     20 
     21 // -
     22 
     23 void AbstractCache::ResetInvalidators(InvalidatorListT&& newList) {
     24  for (const auto& cur : mInvalidators) {
     25    if (cur) {
     26      (void)cur->mCaches.erase(this);
     27    }
     28  }
     29 
     30  mInvalidators = std::move(newList);
     31 
     32  for (const auto& cur : mInvalidators) {
     33    // Don't assert that we insert, since there may be dupes in `invalidators`.
     34    // (and it's not worth removing the dupes)
     35    if (cur) {
     36      (void)cur->mCaches.insert(this);
     37    }
     38  }
     39 }
     40 
     41 void AbstractCache::AddInvalidator(const CacheInvalidator& x) {
     42  mInvalidators.push_back(&x);
     43  x.mCaches.insert(this);
     44 }
     45 
     46 }  // namespace mozilla