Bug 1652470 [wpt PR 24579] - Update mozrunner to 8.0.0, a=testonly
[gecko.git] / startupcache / StartupCacheChild.cpp
blob3fabc8dddd4e94101ae7915327c72591af266f03
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/. */
7 #include "mozilla/scache/StartupCacheChild.h"
9 #include "mozilla/scache/StartupCache.h"
10 #include "mozilla/dom/ContentParent.h"
12 namespace mozilla {
13 namespace scache {
15 void StartupCacheChild::Init(bool wantCacheData) {
16 mWantCacheData = wantCacheData;
18 auto* cache = StartupCache::GetSingleton();
19 if (cache) {
20 Unused << cache->InitChild(wantCacheData ? this : nullptr);
23 if (!wantCacheData) {
24 // If the parent process isn't expecting any cache data from us, we're
25 // done.
26 Send__delete__(this, AutoTArray<EntryData, 0>());
30 void StartupCacheChild::SendEntriesAndFinalize(StartupCache::Table& entries) {
31 MOZ_RELEASE_ASSERT(mWantCacheData);
32 nsTArray<EntryData> dataArray;
33 for (auto iter = entries.iter(); !iter.done(); iter.next()) {
34 const auto& key = iter.get().key();
35 auto& value = iter.get().value();
37 if (!value.mData ||
38 value.mRequestedOrder == kStartupCacheEntryNotRequested) {
39 continue;
42 auto data = dataArray.AppendElement();
44 data->key() = key;
45 if (value.mFlags.contains(StartupCacheEntryFlags::AddedThisSession)) {
46 data->data().AppendElements(
47 reinterpret_cast<const uint8_t*>(value.mData.get()),
48 value.mUncompressedSize);
52 mWantCacheData = false;
53 Send__delete__(this, dataArray);
56 void StartupCacheChild::ActorDestroy(ActorDestroyReason aWhy) {
57 auto* cache = StartupCache::GetSingleton();
58 if (cache) {
59 cache->mChildActor = nullptr;
63 } // namespace scache
64 } // namespace mozilla