Popular sites on the NTP: Favicons!
[chromium-blink-merge.git] / gin / v8_initializer.h
blobe18143692256ec8ee292407eead53525489ee6fd
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
3 // found in the LICENSE file.
5 #ifndef GIN_V8_INITIALIZER_H_
6 #define GIN_V8_INITIALIZER_H_
8 #include "base/files/file.h"
9 #include "base/files/memory_mapped_file.h"
10 #include "gin/array_buffer.h"
11 #include "gin/gin_export.h"
12 #include "gin/public/isolate_holder.h"
13 #include "gin/public/v8_platform.h"
14 #include "v8/include/v8.h"
16 namespace gin {
18 class GIN_EXPORT V8Initializer {
19 public:
20 // This should be called by IsolateHolder::Initialize().
21 static void Initialize(gin::IsolateHolder::ScriptMode mode);
23 // Get address and size information for currently loaded snapshot.
24 // If no snapshot is loaded, the return values are null for addresses
25 // and 0 for sizes.
26 static void GetV8ExternalSnapshotData(const char** natives_data_out,
27 int* natives_size_out,
28 const char** snapshot_data_out,
29 int* snapshot_size_out);
31 #if defined(V8_USE_EXTERNAL_STARTUP_DATA)
33 // Load V8 snapshot from user provided platform file descriptors.
34 // The offset and size arguments, if non-zero, specify the portions
35 // of the files to be loaded. Since the VM can boot with or without
36 // the snapshot, this function does not return a status.
37 static void LoadV8SnapshotFromFD(base::PlatformFile snapshot_fd,
38 int64 snapshot_offset,
39 int64 snapshot_size);
40 // Similar to LoadV8SnapshotFromFD, but for the source of the natives.
41 // Without the natives we cannot continue, so this function contains
42 // release mode asserts and won't return if it fails.
43 static void LoadV8NativesFromFD(base::PlatformFile natives_fd,
44 int64 natives_offset,
45 int64 natives_size);
47 // Load V8 snapshot from default resources, if they are available.
48 static void LoadV8Snapshot();
50 // Load V8 natives source from default resources. Contains asserts
51 // so that it will not return if natives cannot be loaded.
52 static void LoadV8Natives();
54 // Opens (unless already cached) and returns the V8 natives file.
55 // Use with LoadV8NativesFromFD().
56 // Asserts if the file does not exist.
57 static base::PlatformFile GetOpenNativesFileForChildProcesses(
58 base::MemoryMappedFile::Region* region_out);
60 // Opens (unless already cached) and returns the V8 snapshot file.
61 // Use with LoadV8SnapshotFromFD().
62 // Will return -1 if the file does not exist.
63 static base::PlatformFile GetOpenSnapshotFileForChildProcesses(
64 base::MemoryMappedFile::Region* region_out);
65 #endif // V8_USE_EXTERNAL_STARTUP_DATA
68 } // namespace gin
70 #endif // GIN_V8_INITIALIZER_H_