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"
15 void StartupCacheChild::Init(bool wantCacheData
) {
16 mWantCacheData
= wantCacheData
;
18 auto* cache
= StartupCache::GetSingleton();
20 Unused
<< cache
->InitChild(wantCacheData
? this : nullptr);
24 // If the parent process isn't expecting any cache data from us, we're
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();
38 value
.mRequestedOrder
== kStartupCacheEntryNotRequested
) {
42 auto data
= dataArray
.AppendElement();
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();
59 cache
->mChildActor
= nullptr;
64 } // namespace mozilla