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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 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.
4
5 #include "base/at_exit.h"
6 #include "base/bind.h"
7 #include "base/command_line.h"
8 #include "base/files/file_util.h"
9 #include "base/location.h"
10 #include "base/macros.h"
11 #include "base/memory/ptr_util.h"
12 #include "base/message_loop/message_loop.h"
13 #include "base/run_loop.h"
14 #include "base/single_thread_task_runner.h"
15 #include "base/task_scheduler/task_scheduler.h"
16 #include "base/threading/thread_task_runner_handle.h"
17 #include "gin/array_buffer.h"
18 #include "gin/modules/console.h"
19 #include "gin/modules/module_runner_delegate.h"
20 #include "gin/public/isolate_holder.h"
21 #include "gin/try_catch.h"
22 #include "gin/v8_initializer.h"
23 #include "mojo/edk/embedder/embedder.h"
24 #include "third_party/WebKit/public/web/WebKit.h"
25 #include "third_party/WebKit/public/web/WebV8SnapshotUtil.h"
26 #include "v8/include/v8.h"
27
28 namespace gin {
29 namespace {
30
31 class GinBlinkPlatform final : public blink::Platform {
32 public:
33 bool IsToTakeV8Snapshot() override { return true; }
34 };
35
36 } // namespace
37 } // namespace gin
38
39 // This program takes a snapshot of V8 contexts and writes it out as a file.
40 // We assume those contexts made in this program are used in Blink.
41 //
42 // Usage:
43 // % blink_v8_snapshot_generator --output_file=<filename>
44 int main(int argc, char** argv) {
45 base::AtExitManager at_exit;
46 base::CommandLine::Init(argc, argv);
47 #ifdef V8_USE_EXTERNAL_STARTUP_DATA
48 gin::V8Initializer::LoadV8Snapshot();
49 gin::V8Initializer::LoadV8Natives();
50 #endif
51
52 // Set up environment to make Blink and V8 workable.
53 base::MessageLoop message_loop;
54 base::TaskScheduler::CreateAndStartWithDefaultParams("TakeSnapshot");
55 mojo::edk::Init();
56
57 // Take snapshot
58 gin::GinBlinkPlatform platform;
59 blink::Initialize(&platform);
60 v8::StartupData blob = blink::WebV8SnapshotUtil::TakeSnapshot();
61
62 // Save snapshot as a file. Filename is given in a command line option.
63 base::FilePath file_path =
64 base::CommandLine::ForCurrentProcess()->GetSwitchValuePath("output_file");
65 CHECK(!file_path.empty());
66 base::WriteFile(file_path, blob.data, blob.raw_size);
67
68 delete[] blob.data;
69
70 return 0;
71 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698