OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "gin/v8_initializer.h" | 5 #include "gin/v8_initializer.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 | 56 |
57 OpenedFileMap::mapped_type& GetOpenedFile(const char* file) { | 57 OpenedFileMap::mapped_type& GetOpenedFile(const char* file) { |
58 OpenedFileMap& opened_files(g_opened_files.Get()); | 58 OpenedFileMap& opened_files(g_opened_files.Get()); |
59 if (opened_files.find(file) == opened_files.end()) { | 59 if (opened_files.find(file) == opened_files.end()) { |
60 opened_files[file] = std::make_pair(base::kInvalidPlatformFile, | 60 opened_files[file] = std::make_pair(base::kInvalidPlatformFile, |
61 base::MemoryMappedFile::Region()); | 61 base::MemoryMappedFile::Region()); |
62 } | 62 } |
63 return opened_files[file]; | 63 return opened_files[file]; |
64 } | 64 } |
65 | 65 |
| 66 const char kNativesFileName[] = "natives_blob.bin"; |
| 67 |
66 #if defined(OS_ANDROID) | 68 #if defined(OS_ANDROID) |
67 const char kNativesFileName64[] = "natives_blob_64.bin"; | |
68 const char kSnapshotFileName64[] = "snapshot_blob_64.bin"; | 69 const char kSnapshotFileName64[] = "snapshot_blob_64.bin"; |
69 const char kNativesFileName32[] = "natives_blob_32.bin"; | |
70 const char kSnapshotFileName32[] = "snapshot_blob_32.bin"; | 70 const char kSnapshotFileName32[] = "snapshot_blob_32.bin"; |
71 | 71 |
72 #if defined(__LP64__) | 72 #if defined(__LP64__) |
73 #define kNativesFileName kNativesFileName64 | |
74 #define kSnapshotFileName kSnapshotFileName64 | 73 #define kSnapshotFileName kSnapshotFileName64 |
75 #else | 74 #else |
76 #define kNativesFileName kNativesFileName32 | |
77 #define kSnapshotFileName kSnapshotFileName32 | 75 #define kSnapshotFileName kSnapshotFileName32 |
78 #endif | 76 #endif |
79 | 77 |
80 #else // defined(OS_ANDROID) | 78 #else // defined(OS_ANDROID) |
81 const char kNativesFileName[] = "natives_blob.bin"; | |
82 const char kSnapshotFileName[] = "snapshot_blob.bin"; | 79 const char kSnapshotFileName[] = "snapshot_blob.bin"; |
83 #endif // defined(OS_ANDROID) | 80 #endif // defined(OS_ANDROID) |
84 | 81 |
85 void GetV8FilePath(const char* file_name, base::FilePath* path_out) { | 82 void GetV8FilePath(const char* file_name, base::FilePath* path_out) { |
86 #if !defined(OS_MACOSX) | 83 #if !defined(OS_MACOSX) |
87 base::FilePath data_path; | 84 base::FilePath data_path; |
88 #if defined(OS_ANDROID) | 85 #if defined(OS_ANDROID) |
89 // This is the path within the .apk. | 86 // This is the path within the .apk. |
90 data_path = base::FilePath(FILE_PATH_LITERAL("assets")); | 87 data_path = base::FilePath(FILE_PATH_LITERAL("assets")); |
91 #elif defined(OS_POSIX) | 88 #elif defined(OS_POSIX) |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 base::PlatformFile V8Initializer::GetOpenSnapshotFileForChildProcesses( | 378 base::PlatformFile V8Initializer::GetOpenSnapshotFileForChildProcesses( |
382 base::MemoryMappedFile::Region* region_out) { | 379 base::MemoryMappedFile::Region* region_out) { |
383 const OpenedFileMap::mapped_type& opened = | 380 const OpenedFileMap::mapped_type& opened = |
384 OpenFileIfNecessary(kSnapshotFileName); | 381 OpenFileIfNecessary(kSnapshotFileName); |
385 *region_out = opened.second; | 382 *region_out = opened.second; |
386 return opened.first; | 383 return opened.first; |
387 } | 384 } |
388 | 385 |
389 #if defined(OS_ANDROID) | 386 #if defined(OS_ANDROID) |
390 // static | 387 // static |
391 base::PlatformFile V8Initializer::GetOpenNativesFileForChildProcesses( | |
392 base::MemoryMappedFile::Region* region_out, | |
393 bool abi_32_bit) { | |
394 const char* natives_file = | |
395 abi_32_bit ? kNativesFileName32 : kNativesFileName64; | |
396 const OpenedFileMap::mapped_type& opened = OpenFileIfNecessary(natives_file); | |
397 *region_out = opened.second; | |
398 return opened.first; | |
399 } | |
400 | |
401 // static | |
402 base::PlatformFile V8Initializer::GetOpenSnapshotFileForChildProcesses( | 388 base::PlatformFile V8Initializer::GetOpenSnapshotFileForChildProcesses( |
403 base::MemoryMappedFile::Region* region_out, | 389 base::MemoryMappedFile::Region* region_out, |
404 bool abi_32_bit) { | 390 bool abi_32_bit) { |
405 const char* snapshot_file = | 391 const char* snapshot_file = |
406 abi_32_bit ? kSnapshotFileName32 : kSnapshotFileName64; | 392 abi_32_bit ? kSnapshotFileName32 : kSnapshotFileName64; |
407 const OpenedFileMap::mapped_type& opened = OpenFileIfNecessary(snapshot_file); | 393 const OpenedFileMap::mapped_type& opened = OpenFileIfNecessary(snapshot_file); |
408 *region_out = opened.second; | 394 *region_out = opened.second; |
409 return opened.first; | 395 return opened.first; |
410 } | 396 } |
411 | 397 |
412 // static | 398 // static |
413 base::FilePath V8Initializer::GetNativesFilePath(bool abi_32_bit) { | 399 base::FilePath V8Initializer::GetNativesFilePath() { |
414 base::FilePath path; | 400 base::FilePath path; |
415 GetV8FilePath(abi_32_bit ? kNativesFileName32 : kNativesFileName64, &path); | 401 GetV8FilePath(kNativesFileName, &path); |
416 return path; | 402 return path; |
417 } | 403 } |
418 | 404 |
419 // static | 405 // static |
420 base::FilePath V8Initializer::GetSnapshotFilePath(bool abi_32_bit) { | 406 base::FilePath V8Initializer::GetSnapshotFilePath(bool abi_32_bit) { |
421 base::FilePath path; | 407 base::FilePath path; |
422 GetV8FilePath(abi_32_bit ? kSnapshotFileName32 : kSnapshotFileName64, &path); | 408 GetV8FilePath(abi_32_bit ? kSnapshotFileName32 : kSnapshotFileName64, &path); |
423 return path; | 409 return path; |
424 } | 410 } |
425 #endif // defined(OS_ANDROID) | 411 #endif // defined(OS_ANDROID) |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 *snapshot_data_out = | 483 *snapshot_data_out = |
498 reinterpret_cast<const char*>(g_mapped_snapshot->data()); | 484 reinterpret_cast<const char*>(g_mapped_snapshot->data()); |
499 *snapshot_size_out = static_cast<int>(g_mapped_snapshot->length()); | 485 *snapshot_size_out = static_cast<int>(g_mapped_snapshot->length()); |
500 } else { | 486 } else { |
501 *snapshot_data_out = NULL; | 487 *snapshot_data_out = NULL; |
502 *snapshot_size_out = 0; | 488 *snapshot_size_out = 0; |
503 } | 489 } |
504 } | 490 } |
505 | 491 |
506 } // namespace gin | 492 } // namespace gin |
OLD | NEW |