/src/mozilla-central/js/xpconnect/loader/ScriptCacheActors.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* vim: set ts=8 sts=4 et sw=4 tw=99: */ |
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/ScriptPreloader.h" |
8 | | #include "ScriptPreloader-inl.h" |
9 | | #include "mozilla/loader/ScriptCacheActors.h" |
10 | | |
11 | | #include "mozilla/dom/ContentParent.h" |
12 | | |
13 | | namespace mozilla { |
14 | | namespace loader { |
15 | | |
16 | | void |
17 | | ScriptCacheChild::Init(const Maybe<FileDescriptor>& cacheFile, bool wantCacheData) |
18 | 0 | { |
19 | 0 | mWantCacheData = wantCacheData; |
20 | 0 |
|
21 | 0 | auto& cache = ScriptPreloader::GetChildSingleton(); |
22 | 0 | Unused << cache.InitCache(cacheFile, this); |
23 | 0 |
|
24 | 0 | if (!wantCacheData) { |
25 | 0 | // If the parent process isn't expecting any cache data from us, we're |
26 | 0 | // done. |
27 | 0 | Send__delete__(this, AutoTArray<ScriptData, 0>()); |
28 | 0 | } |
29 | 0 | } |
30 | | |
31 | | // Finalize the script cache for the content process, and send back data about |
32 | | // any scripts executed up to this point. |
33 | | void |
34 | | ScriptCacheChild::SendScriptsAndFinalize(ScriptPreloader::ScriptHash& scripts) |
35 | 0 | { |
36 | 0 | MOZ_ASSERT(mWantCacheData); |
37 | 0 |
|
38 | 0 | AutoSafeJSAPI jsapi; |
39 | 0 |
|
40 | 0 | auto matcher = ScriptPreloader::Match<ScriptPreloader::ScriptStatus::Saved>(); |
41 | 0 |
|
42 | 0 | nsTArray<ScriptData> dataArray; |
43 | 0 | for (auto& script : IterHash(scripts, matcher)) { |
44 | 0 | if (!script->mSize && !script->XDREncode(jsapi.cx())) { |
45 | 0 | continue; |
46 | 0 | } |
47 | 0 | |
48 | 0 | auto data = dataArray.AppendElement(); |
49 | 0 |
|
50 | 0 | data->url() = script->mURL; |
51 | 0 | data->cachePath() = script->mCachePath; |
52 | 0 | data->loadTime() = script->mLoadTime; |
53 | 0 |
|
54 | 0 | if (script->HasBuffer()) { |
55 | 0 | auto& xdrData = script->Buffer(); |
56 | 0 | data->xdrData().AppendElements(xdrData.begin(), xdrData.length()); |
57 | 0 | script->FreeData(); |
58 | 0 | } |
59 | 0 | } |
60 | 0 |
|
61 | 0 | Send__delete__(this, dataArray); |
62 | 0 | } |
63 | | |
64 | | void |
65 | | ScriptCacheChild::ActorDestroy(ActorDestroyReason aWhy) |
66 | 0 | { |
67 | 0 | auto& cache = ScriptPreloader::GetChildSingleton(); |
68 | 0 | cache.mChildActor = nullptr; |
69 | 0 | } |
70 | | |
71 | | |
72 | | IPCResult |
73 | | ScriptCacheParent::Recv__delete__(nsTArray<ScriptData>&& scripts) |
74 | 0 | { |
75 | 0 | if (!mWantCacheData && scripts.Length()) { |
76 | 0 | return IPC_FAIL(this, "UnexpectedScriptData"); |
77 | 0 | } |
78 | 0 |
|
79 | 0 | // We don't want any more data from the process at this point. |
80 | 0 | mWantCacheData = false; |
81 | 0 |
|
82 | 0 | // Merge the child's script data with the parent's. |
83 | 0 | auto parent = static_cast<dom::ContentParent*>(Manager()); |
84 | 0 | auto processType = ScriptPreloader::GetChildProcessType(parent->GetRemoteType()); |
85 | 0 |
|
86 | 0 | auto& cache = ScriptPreloader::GetChildSingleton(); |
87 | 0 | for (auto& script : scripts) { |
88 | 0 | cache.NoteScript(script.url(), script.cachePath(), processType, |
89 | 0 | std::move(script.xdrData()), script.loadTime()); |
90 | 0 | } |
91 | 0 |
|
92 | 0 | return IPC_OK(); |
93 | 0 | } |
94 | | |
95 | | void |
96 | | ScriptCacheParent::ActorDestroy(ActorDestroyReason aWhy) |
97 | 0 | {} |
98 | | |
99 | | } // namespace loader |
100 | | } // namespace mozilla |