Avi Drissman | 4e1b7bc3 | 2022-09-15 14:03:50 | [diff] [blame] | 1 | // Copyright 2019 The Chromium Authors |
Ken Rockot | 8dda8888 | 2019-12-04 05:56:22 | [diff] [blame] | 2 | // 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 Silva | 0069272 | 2025-03-18 19:51:48 | [diff] [blame] | 7 | #include <variant> |
| 8 | |
Leszek Swirski | c062a07f | 2024-05-02 10:51:09 | [diff] [blame] | 9 | #include "base/command_line.h" |
| 10 | #include "base/feature_list.h" |
Ken Rockot | 8dda8888 | 2019-12-04 05:56:22 | [diff] [blame] | 11 | #include "build/build_config.h" |
| 12 | #include "content/public/common/content_descriptor_keys.h" |
Leszek Swirski | c062a07f | 2024-05-02 10:51:09 | [diff] [blame] | 13 | #include "content/public/common/content_features.h" |
| 14 | #include "content/public/common/content_switches.h" |
Nico Weber | 8f59b10 | 2022-11-30 03:48:39 | [diff] [blame] | 15 | #include "tools/v8_context_snapshot/buildflags.h" |
Ken Rockot | 8dda8888 | 2019-12-04 05:56:22 | [diff] [blame] | 16 | |
| 17 | namespace content { |
| 18 | |
Jiawei Wang | 0df6b0c | 2025-09-23 15:16:53 | [diff] [blame] | 19 | #if BUILDFLAG(IS_ANDROID) && (BUILDFLAG(USE_V8_CONTEXT_SNAPSHOT) || \ |
| 20 | BUILDFLAG(INCLUDE_BOTH_V8_SNAPSHOTS)) |
Sam Maier | 40b73fc | 2025-05-30 14:15:56 | [diff] [blame] | 21 | namespace { |
| 22 | void 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 Silva | 0069272 | 2025-03-18 19:51:48 | [diff] [blame] | 36 | std::map<std::string, std::variant<base::FilePath, base::ScopedFD>> |
Leszek Swirski | c062a07f | 2024-05-02 10:51:09 | [diff] [blame] | 37 | GetV8SnapshotFilesToPreload(base::CommandLine& process_command_line) { |
Victor Hugo Vianna Silva | 0069272 | 2025-03-18 19:51:48 | [diff] [blame] | 38 | std::map<std::string, std::variant<base::FilePath, base::ScopedFD>> files; |
Xiaohan Wang | 1ecfd00 | 2022-01-19 22:33:10 | [diff] [blame] | 39 | #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) |
Nico Weber | 8f59b10 | 2022-11-30 03:48:39 | [diff] [blame] | 40 | #if BUILDFLAG(USE_V8_CONTEXT_SNAPSHOT) |
Matthew Denton | c46d14cb | 2023-01-11 00:59:21 | [diff] [blame] | 41 | files[kV8ContextSnapshotDataDescriptor] = base::FilePath( |
| 42 | FILE_PATH_LITERAL(BUILDFLAG(V8_CONTEXT_SNAPSHOT_FILENAME))); |
Ken Rockot | 8dda8888 | 2019-12-04 05:56:22 | [diff] [blame] | 43 | #else |
Matthew Denton | c46d14cb | 2023-01-11 00:59:21 | [diff] [blame] | 44 | files[kV8SnapshotDataDescriptor] = |
| 45 | base::FilePath(FILE_PATH_LITERAL("snapshot_blob.bin")); |
Ken Rockot | 8dda8888 | 2019-12-04 05:56:22 | [diff] [blame] | 46 | #endif |
Xiaohan Wang | 1ecfd00 | 2022-01-19 22:33:10 | [diff] [blame] | 47 | #elif BUILDFLAG(IS_ANDROID) |
Leszek Swirski | c062a07f | 2024-05-02 10:51:09 | [diff] [blame] | 48 | #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 Maier | 40b73fc | 2025-05-30 14:15:56 | [diff] [blame] | 52 | registerContextSnapshotAndroid(files); |
Leszek Swirski | c062a07f | 2024-05-02 10:51:09 | [diff] [blame] | 53 | } |
| 54 | #endif // BUILDFLAG(INCLUDE_BOTH_V8_SNAPSHOTS) |
Sam Maier | 40b73fc | 2025-05-30 14:15:56 | [diff] [blame] | 55 | #ifdef __LP64__ |
Matthew Denton | c46d14cb | 2023-01-11 00:59:21 | [diff] [blame] | 56 | files[kV8Snapshot64DataDescriptor] = |
| 57 | base::FilePath(FILE_PATH_LITERAL("assets/snapshot_blob_64.bin")); |
Sam Maier | 40b73fc | 2025-05-30 14:15:56 | [diff] [blame] | 58 | #else |
Matthew Denton | c46d14cb | 2023-01-11 00:59:21 | [diff] [blame] | 59 | files[kV8Snapshot32DataDescriptor] = |
| 60 | base::FilePath(FILE_PATH_LITERAL("assets/snapshot_blob_32.bin")); |
Sam Maier | 40b73fc | 2025-05-30 14:15:56 | [diff] [blame] | 61 | #endif // __LP64__ |
Nico Weber | 8f59b10 | 2022-11-30 03:48:39 | [diff] [blame] | 62 | #elif BUILDFLAG(USE_V8_CONTEXT_SNAPSHOT) |
Sam Maier | 40b73fc | 2025-05-30 14:15:56 | [diff] [blame] | 63 | registerContextSnapshotAndroid(files); |
| 64 | #endif // !BUILDFLAG(USE_V8_CONTEXT_SNAPSHOT) || |
| 65 | // BUILDFLAG(INCLUDE_BOTH_V8_SNAPSHOTS) |
Matthew Denton | c46d14cb | 2023-01-11 00:59:21 | [diff] [blame] | 66 | #endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) |
| 67 | return files; |
Ken Rockot | 8dda8888 | 2019-12-04 05:56:22 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | } // namespace content |