blob: 02b1ac8507b0e1a0066ef18dcb9934dea54bca98 [file] [log] [blame]
Avi Drissman4e1b7bc32022-09-15 14:03:501// Copyright 2019 The Chromium Authors
Ken Rockot8dda88882019-12-04 05:56:222// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "content/browser/v8_snapshot_files.h"
6
Victor Hugo Vianna Silva00692722025-03-18 19:51:487#include <variant>
8
Leszek Swirskic062a07f2024-05-02 10:51:099#include "base/command_line.h"
10#include "base/feature_list.h"
Ken Rockot8dda88882019-12-04 05:56:2211#include "build/build_config.h"
12#include "content/public/common/content_descriptor_keys.h"
Leszek Swirskic062a07f2024-05-02 10:51:0913#include "content/public/common/content_features.h"
14#include "content/public/common/content_switches.h"
Nico Weber8f59b102022-11-30 03:48:3915#include "tools/v8_context_snapshot/buildflags.h"
Ken Rockot8dda88882019-12-04 05:56:2216
17namespace content {
18
Jiawei Wang0df6b0c2025-09-23 15:16:5319#if BUILDFLAG(IS_ANDROID) && (BUILDFLAG(USE_V8_CONTEXT_SNAPSHOT) || \
20 BUILDFLAG(INCLUDE_BOTH_V8_SNAPSHOTS))
Sam Maier40b73fc2025-05-30 14:15:5621namespace {
22void registerContextSnapshotAndroid(
23 std::map<std::string, std::variant<base::FilePath, base::ScopedFD>>&
24 files) {
25#ifdef __LP64__
26 files[kV8ContextSnapshot64DataDescriptor] =
27#else
28 files[kV8ContextSnapshot32DataDescriptor] =
29#endif // __LP64__
30 base::FilePath(FILE_PATH_LITERAL("assets"))
31 .Append(FILE_PATH_LITERAL(BUILDFLAG(V8_CONTEXT_SNAPSHOT_FILENAME)));
32}
33} // namespace
34#endif // BUILDFLAG(IS_ANDROID)
35
Victor Hugo Vianna Silva00692722025-03-18 19:51:4836std::map<std::string, std::variant<base::FilePath, base::ScopedFD>>
Leszek Swirskic062a07f2024-05-02 10:51:0937GetV8SnapshotFilesToPreload(base::CommandLine& process_command_line) {
Victor Hugo Vianna Silva00692722025-03-18 19:51:4838 std::map<std::string, std::variant<base::FilePath, base::ScopedFD>> files;
Xiaohan Wang1ecfd002022-01-19 22:33:1039#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
Nico Weber8f59b102022-11-30 03:48:3940#if BUILDFLAG(USE_V8_CONTEXT_SNAPSHOT)
Matthew Dentonc46d14cb2023-01-11 00:59:2141 files[kV8ContextSnapshotDataDescriptor] = base::FilePath(
42 FILE_PATH_LITERAL(BUILDFLAG(V8_CONTEXT_SNAPSHOT_FILENAME)));
Ken Rockot8dda88882019-12-04 05:56:2243#else
Matthew Dentonc46d14cb2023-01-11 00:59:2144 files[kV8SnapshotDataDescriptor] =
45 base::FilePath(FILE_PATH_LITERAL("snapshot_blob.bin"));
Ken Rockot8dda88882019-12-04 05:56:2246#endif
Xiaohan Wang1ecfd002022-01-19 22:33:1047#elif BUILDFLAG(IS_ANDROID)
Leszek Swirskic062a07f2024-05-02 10:51:0948#if !BUILDFLAG(USE_V8_CONTEXT_SNAPSHOT) || BUILDFLAG(INCLUDE_BOTH_V8_SNAPSHOTS)
49#if BUILDFLAG(INCLUDE_BOTH_V8_SNAPSHOTS)
50 if (base::FeatureList::IsEnabled(features::kUseContextSnapshot)) {
51 process_command_line.AppendSwitch(switches::kUseContextSnapshotSwitch);
Sam Maier40b73fc2025-05-30 14:15:5652 registerContextSnapshotAndroid(files);
Leszek Swirskic062a07f2024-05-02 10:51:0953 }
54#endif // BUILDFLAG(INCLUDE_BOTH_V8_SNAPSHOTS)
Sam Maier40b73fc2025-05-30 14:15:5655#ifdef __LP64__
Matthew Dentonc46d14cb2023-01-11 00:59:2156 files[kV8Snapshot64DataDescriptor] =
57 base::FilePath(FILE_PATH_LITERAL("assets/snapshot_blob_64.bin"));
Sam Maier40b73fc2025-05-30 14:15:5658#else
Matthew Dentonc46d14cb2023-01-11 00:59:2159 files[kV8Snapshot32DataDescriptor] =
60 base::FilePath(FILE_PATH_LITERAL("assets/snapshot_blob_32.bin"));
Sam Maier40b73fc2025-05-30 14:15:5661#endif // __LP64__
Nico Weber8f59b102022-11-30 03:48:3962#elif BUILDFLAG(USE_V8_CONTEXT_SNAPSHOT)
Sam Maier40b73fc2025-05-30 14:15:5663 registerContextSnapshotAndroid(files);
64#endif // !BUILDFLAG(USE_V8_CONTEXT_SNAPSHOT) ||
65 // BUILDFLAG(INCLUDE_BOTH_V8_SNAPSHOTS)
Matthew Dentonc46d14cb2023-01-11 00:59:2166#endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
67 return files;
Ken Rockot8dda88882019-12-04 05:56:2268}
69
70} // namespace content