blob: 56dff88af141fc4303eefe5e88ac963542865795 [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
Sam Maier40b73fc2025-05-30 14:15:5619#if BUILDFLAG(IS_ANDROID) && BUILDFLAG(USE_V8_CONTEXT_SNAPSHOT)
20namespace {
21void registerContextSnapshotAndroid(
22 std::map<std::string, std::variant<base::FilePath, base::ScopedFD>>&
23 files) {
24#ifdef __LP64__
25 files[kV8ContextSnapshot64DataDescriptor] =
26#else
27 files[kV8ContextSnapshot32DataDescriptor] =
28#endif // __LP64__
29 base::FilePath(FILE_PATH_LITERAL("assets"))
30 .Append(FILE_PATH_LITERAL(BUILDFLAG(V8_CONTEXT_SNAPSHOT_FILENAME)));
31}
32} // namespace
33#endif // BUILDFLAG(IS_ANDROID)
34
Victor Hugo Vianna Silva00692722025-03-18 19:51:4835std::map<std::string, std::variant<base::FilePath, base::ScopedFD>>
Leszek Swirskic062a07f2024-05-02 10:51:0936GetV8SnapshotFilesToPreload(base::CommandLine& process_command_line) {
Victor Hugo Vianna Silva00692722025-03-18 19:51:4837 std::map<std::string, std::variant<base::FilePath, base::ScopedFD>> files;
Xiaohan Wang1ecfd002022-01-19 22:33:1038#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
Nico Weber8f59b102022-11-30 03:48:3939#if BUILDFLAG(USE_V8_CONTEXT_SNAPSHOT)
Matthew Dentonc46d14cb2023-01-11 00:59:2140 files[kV8ContextSnapshotDataDescriptor] = base::FilePath(
41 FILE_PATH_LITERAL(BUILDFLAG(V8_CONTEXT_SNAPSHOT_FILENAME)));
Ken Rockot8dda88882019-12-04 05:56:2242#else
Matthew Dentonc46d14cb2023-01-11 00:59:2143 files[kV8SnapshotDataDescriptor] =
44 base::FilePath(FILE_PATH_LITERAL("snapshot_blob.bin"));
Ken Rockot8dda88882019-12-04 05:56:2245#endif
Xiaohan Wang1ecfd002022-01-19 22:33:1046#elif BUILDFLAG(IS_ANDROID)
Leszek Swirskic062a07f2024-05-02 10:51:0947#if !BUILDFLAG(USE_V8_CONTEXT_SNAPSHOT) || BUILDFLAG(INCLUDE_BOTH_V8_SNAPSHOTS)
48#if BUILDFLAG(INCLUDE_BOTH_V8_SNAPSHOTS)
49 if (base::FeatureList::IsEnabled(features::kUseContextSnapshot)) {
50 process_command_line.AppendSwitch(switches::kUseContextSnapshotSwitch);
Sam Maier40b73fc2025-05-30 14:15:5651 registerContextSnapshotAndroid(files);
Leszek Swirskic062a07f2024-05-02 10:51:0952 }
53#endif // BUILDFLAG(INCLUDE_BOTH_V8_SNAPSHOTS)
Sam Maier40b73fc2025-05-30 14:15:5654#ifdef __LP64__
Matthew Dentonc46d14cb2023-01-11 00:59:2155 files[kV8Snapshot64DataDescriptor] =
56 base::FilePath(FILE_PATH_LITERAL("assets/snapshot_blob_64.bin"));
Sam Maier40b73fc2025-05-30 14:15:5657#else
Matthew Dentonc46d14cb2023-01-11 00:59:2158 files[kV8Snapshot32DataDescriptor] =
59 base::FilePath(FILE_PATH_LITERAL("assets/snapshot_blob_32.bin"));
Sam Maier40b73fc2025-05-30 14:15:5660#endif // __LP64__
Nico Weber8f59b102022-11-30 03:48:3961#elif BUILDFLAG(USE_V8_CONTEXT_SNAPSHOT)
Sam Maier40b73fc2025-05-30 14:15:5662 registerContextSnapshotAndroid(files);
63#endif // !BUILDFLAG(USE_V8_CONTEXT_SNAPSHOT) ||
64 // BUILDFLAG(INCLUDE_BOTH_V8_SNAPSHOTS)
Matthew Dentonc46d14cb2023-01-11 00:59:2165#endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
66 return files;
Ken Rockot8dda88882019-12-04 05:56:2267}
68
69} // namespace content