Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Unified Diff: gin/shell/blink_v8_snapshot_generator_main.cc

Issue 2841443005: [Bindings] Create and use V8 context snapshots (Closed)
Patch Set: Support runtime feature on templates Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: gin/shell/blink_v8_snapshot_generator_main.cc
diff --git a/gin/shell/blink_v8_snapshot_generator_main.cc b/gin/shell/blink_v8_snapshot_generator_main.cc
new file mode 100644
index 0000000000000000000000000000000000000000..e3f65f51406f67f280bf07f61057014d75ef1920
--- /dev/null
+++ b/gin/shell/blink_v8_snapshot_generator_main.cc
@@ -0,0 +1,71 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/at_exit.h"
+#include "base/bind.h"
+#include "base/command_line.h"
+#include "base/files/file_util.h"
+#include "base/location.h"
+#include "base/macros.h"
+#include "base/memory/ptr_util.h"
+#include "base/message_loop/message_loop.h"
+#include "base/run_loop.h"
+#include "base/single_thread_task_runner.h"
+#include "base/task_scheduler/task_scheduler.h"
+#include "base/threading/thread_task_runner_handle.h"
+#include "gin/array_buffer.h"
+#include "gin/modules/console.h"
+#include "gin/modules/module_runner_delegate.h"
+#include "gin/public/isolate_holder.h"
+#include "gin/try_catch.h"
+#include "gin/v8_initializer.h"
+#include "mojo/edk/embedder/embedder.h"
+#include "third_party/WebKit/public/web/WebKit.h"
+#include "third_party/WebKit/public/web/WebV8SnapshotUtil.h"
+#include "v8/include/v8.h"
+
+namespace gin {
+namespace {
+
+class GinBlinkPlatform final : public blink::Platform {
+ public:
+ bool IsToTakeV8Snapshot() override { return true; }
+};
+
+} // namespace
+} // namespace gin
+
+// This program takes a snapshot of V8 contexts and writes it out as a file.
+// We assume those contexts made in this program are used in Blink.
+//
+// Usage:
+// % blink_v8_snapshot_generator --output_file=<filename>
+int main(int argc, char** argv) {
+ base::AtExitManager at_exit;
+ base::CommandLine::Init(argc, argv);
+#ifdef V8_USE_EXTERNAL_STARTUP_DATA
+ gin::V8Initializer::LoadV8Snapshot();
+ gin::V8Initializer::LoadV8Natives();
+#endif
+
+ // Set up environment to make Blink and V8 workable.
+ base::MessageLoop message_loop;
+ base::TaskScheduler::CreateAndStartWithDefaultParams("TakeSnapshot");
+ mojo::edk::Init();
+
+ // Take snapshot
+ gin::GinBlinkPlatform platform;
+ blink::Initialize(&platform);
+ v8::StartupData blob = blink::WebV8SnapshotUtil::TakeSnapshot();
+
+ // Save snapshot as a file. Filename is given in a command line option.
+ base::FilePath file_path =
+ base::CommandLine::ForCurrentProcess()->GetSwitchValuePath("output_file");
+ CHECK(!file_path.empty());
+ base::WriteFile(file_path, blob.data, blob.raw_size);
+
+ delete[] blob.data;
+
+ return 0;
+}

Powered by Google App Engine
This is Rietveld 408576698