gin: Hide V8 context snapshot behind a build flag

We had V8 context snapshot in C++ code regardless V8 settings,
but it introduced some complex errors.
This CL disables usages of V8 context snapshot if a GN flag
"v8_use_external_startup_data" is not true, because V8 context
snapshot depends on what is built with the flag.


Bug: 764576
Change-Id: If9b1cc497a6f6122f213b83ed2f9746d9af8bb62
Reviewed-on: https://chromium-review.googlesource.com/788631
Reviewed-by: Kinuko Yasuda <[email protected]>
Reviewed-by: Ross McIlroy <[email protected]>
Commit-Queue: Hitoshi Yoshida <[email protected]>
Cr-Commit-Position: refs/heads/master@{#519208}
diff --git a/gin/v8_initializer.h b/gin/v8_initializer.h
index 065fecb..0c0da3c7 100644
--- a/gin/v8_initializer.h
+++ b/gin/v8_initializer.h
@@ -33,8 +33,20 @@
                                         const char** snapshot_data_out,
                                         int* snapshot_size_out);
 
+  // Get address and size information for currently loaded V8 context snapshot.
+  // If no snapshot is loaded, the return values are nullptr and 0.
+  static void GetV8ContextSnapshotData(v8::StartupData* snapshot);
+
 #if defined(V8_USE_EXTERNAL_STARTUP_DATA)
 
+  // Load V8 snapshot from default resources, if they are available.
+  static void LoadV8Snapshot();
+  // Load V8 natives source from default resources. Contains asserts
+  // so that it will not return if natives cannot be loaded.
+  static void LoadV8Natives();
+  // Load V8 context snapshot from default resources, if they are available.
+  static void LoadV8ContextSnapshot();
+
   // Load V8 snapshot from user provided platform file descriptors.
   // The offset and size arguments, if non-zero, specify the portions
   // of the files to be loaded. Since the VM can boot with or without
@@ -48,13 +60,11 @@
   static void LoadV8NativesFromFD(base::PlatformFile natives_fd,
                                   int64_t natives_offset,
                                   int64_t natives_size);
-
-  // Load V8 snapshot from default resources, if they are available.
-  static void LoadV8Snapshot();
-
-  // Load V8 natives source from default resources. Contains asserts
-  // so that it will not return if natives cannot be loaded.
-  static void LoadV8Natives();
+  // Load V8 context snapshot from user provided platform file descriptors.
+  // Other details are same with LoadV8SnapshotFromFD.
+  static void LoadV8ContextSnapshotFromFD(base::PlatformFile snapshot_fd,
+                                          int64_t snapshot_offset,
+                                          int64_t snapshot_size);
 
 #if defined(OS_ANDROID)
   static base::FilePath GetNativesFilePath();
@@ -63,18 +73,6 @@
 
 #endif  // V8_USE_EXTERNAL_STARTUP_DATA
 
-  // Load V8 context snapshot from user provided platform file descriptors.
-  // Other details are same with LoadV8SnapshotFromFD.
-  static void LoadV8ContextSnapshotFromFD(base::PlatformFile snapshot_fd,
-                                          int64_t snapshot_offset,
-                                          int64_t snapshot_size);
-
-  // Load V8 context snapshot from default resources, if they are available.
-  static void LoadV8ContextSnapshot();
-
-  // Get address and size information for currently loaded V8 context snapshot.
-  // If no snapshot is loaded, the return values are nullptr and 0.
-  static void GetV8ContextSnapshotData(v8::StartupData* snapshot);
 };
 
 }  // namespace gin