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

Side by Side Diff: gin/isolate_holder.cc

Issue 761903003: Update from https://crrev.com/306655 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years 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
« no previous file with comments | « crypto/rsa_private_key_unittest.cc ('k') | gin/modules/module_registry_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/public/isolate_holder.h" 5 #include "gin/public/isolate_holder.h"
6 6
7 #include <stdlib.h> 7 #include <stdlib.h>
8 #include <string.h> 8 #include <string.h>
9 9
10 #include "base/files/memory_mapped_file.h" 10 #include "base/files/memory_mapped_file.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
13 #include "base/rand_util.h" 13 #include "base/rand_util.h"
14 #include "base/sys_info.h" 14 #include "base/sys_info.h"
15 #include "gin/array_buffer.h" 15 #include "gin/array_buffer.h"
16 #include "gin/debug_impl.h" 16 #include "gin/debug_impl.h"
17 #include "gin/function_template.h" 17 #include "gin/function_template.h"
18 #include "gin/per_isolate_data.h" 18 #include "gin/per_isolate_data.h"
19 #include "gin/public/v8_platform.h" 19 #include "gin/public/v8_platform.h"
20 #include "gin/run_microtasks_observer.h" 20 #include "gin/run_microtasks_observer.h"
21 21
22 #ifdef V8_USE_EXTERNAL_STARTUP_DATA 22 #ifdef V8_USE_EXTERNAL_STARTUP_DATA
23 #ifdef OS_MACOSX
24 #include "base/mac/foundation_util.h"
25 #endif // OS_MACOSX
23 #include "base/path_service.h" 26 #include "base/path_service.h"
24 #endif // V8_USE_EXTERNAL_STARTUP_DATA 27 #endif // V8_USE_EXTERNAL_STARTUP_DATA
25 28
26 namespace gin { 29 namespace gin {
27 30
28 namespace { 31 namespace {
29 32
30 v8::ArrayBuffer::Allocator* g_array_buffer_allocator = NULL; 33 v8::ArrayBuffer::Allocator* g_array_buffer_allocator = NULL;
31 34
32 bool GenerateEntropy(unsigned char* buffer, size_t amount) { 35 bool GenerateEntropy(unsigned char* buffer, size_t amount) {
(...skipping 28 matching lines...) Expand all
61 : !g_mapped_snapshot->Initialize(base::File(snapshot_fd))) { 64 : !g_mapped_snapshot->Initialize(base::File(snapshot_fd))) {
62 delete g_mapped_snapshot; 65 delete g_mapped_snapshot;
63 g_mapped_snapshot = NULL; 66 g_mapped_snapshot = NULL;
64 LOG(ERROR) << "Couldn't mmap v8 snapshot data file"; 67 LOG(ERROR) << "Couldn't mmap v8 snapshot data file";
65 return false; 68 return false;
66 } 69 }
67 } 70 }
68 71
69 return true; 72 return true;
70 } 73 }
74
75 #if !defined(OS_MACOSX)
76 const int v8_snapshot_dir =
77 #if defined(OS_ANDROID)
78 base::DIR_ANDROID_APP_DATA;
79 #elif defined(OS_POSIX)
80 base::DIR_EXE;
81 #endif // defined(OS_ANDROID)
82 #endif // !defined(OS_MACOSX)
83
71 #endif // V8_USE_EXTERNAL_STARTUP_DATA 84 #endif // V8_USE_EXTERNAL_STARTUP_DATA
72 85
73 } // namespace 86 } // namespace
74 87
75 88
76 #ifdef V8_USE_EXTERNAL_STARTUP_DATA 89 #ifdef V8_USE_EXTERNAL_STARTUP_DATA
77 // static 90 // static
78 bool IsolateHolder::LoadV8Snapshot() { 91 bool IsolateHolder::LoadV8Snapshot() {
79 if (g_mapped_natives && g_mapped_snapshot) 92 if (g_mapped_natives && g_mapped_snapshot)
80 return true; 93 return true;
81 94
95 #if !defined(OS_MACOSX)
82 base::FilePath data_path; 96 base::FilePath data_path;
83 PathService::Get( 97 PathService::Get(v8_snapshot_dir, &data_path);
84 #if defined(OS_ANDROID)
85 base::DIR_ANDROID_APP_DATA,
86 #elif defined(OS_POSIX)
87 base::DIR_EXE,
88 #endif
89 &data_path);
90 DCHECK(!data_path.empty()); 98 DCHECK(!data_path.empty());
91 99
92 base::FilePath natives_path = data_path.AppendASCII("natives_blob.bin"); 100 base::FilePath natives_path = data_path.AppendASCII("natives_blob.bin");
93 base::FilePath snapshot_path = data_path.AppendASCII("snapshot_blob.bin"); 101 base::FilePath snapshot_path = data_path.AppendASCII("snapshot_blob.bin");
102 #else // !defined(OS_MACOSX)
103 base::FilePath natives_path = base::mac::PathForFrameworkBundleResource(
104 CFSTR("natives_blob.bin"));
105 base::FilePath snapshot_path = base::mac::PathForFrameworkBundleResource(
106 CFSTR("snapshot_blob.bin"));
107 DCHECK(!natives_path.empty());
108 DCHECK(!snapshot_path.empty());
109 #endif // !defined(OS_MACOSX)
94 110
95 return MapV8Files(&natives_path, &snapshot_path); 111 return MapV8Files(&natives_path, &snapshot_path);
96 } 112 }
97 113
98 //static 114 //static
99 bool IsolateHolder::LoadV8SnapshotFD(int natives_fd, int snapshot_fd) { 115 bool IsolateHolder::LoadV8SnapshotFD(int natives_fd, int snapshot_fd) {
100 if (g_mapped_natives && g_mapped_snapshot) 116 if (g_mapped_natives && g_mapped_snapshot)
101 return true; 117 return true;
102 118
103 return MapV8Files(NULL, NULL, natives_fd, snapshot_fd); 119 return MapV8Files(NULL, NULL, natives_fd, snapshot_fd);
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 g_array_buffer_allocator = allocator; 190 g_array_buffer_allocator = allocator;
175 if (mode == gin::IsolateHolder::kStrictMode) { 191 if (mode == gin::IsolateHolder::kStrictMode) {
176 static const char v8_flags[] = "--use_strict"; 192 static const char v8_flags[] = "--use_strict";
177 v8::V8::SetFlagsFromString(v8_flags, sizeof(v8_flags) - 1); 193 v8::V8::SetFlagsFromString(v8_flags, sizeof(v8_flags) - 1);
178 } 194 }
179 v8::V8::SetEntropySource(&GenerateEntropy); 195 v8::V8::SetEntropySource(&GenerateEntropy);
180 #ifdef V8_USE_EXTERNAL_STARTUP_DATA 196 #ifdef V8_USE_EXTERNAL_STARTUP_DATA
181 v8::StartupData natives; 197 v8::StartupData natives;
182 natives.data = reinterpret_cast<const char*>(g_mapped_natives->data()); 198 natives.data = reinterpret_cast<const char*>(g_mapped_natives->data());
183 natives.raw_size = static_cast<int>(g_mapped_natives->length()); 199 natives.raw_size = static_cast<int>(g_mapped_natives->length());
184 natives.compressed_size = static_cast<int>(g_mapped_natives->length());
185 v8::V8::SetNativesDataBlob(&natives); 200 v8::V8::SetNativesDataBlob(&natives);
186 201
187 v8::StartupData snapshot; 202 v8::StartupData snapshot;
188 snapshot.data = reinterpret_cast<const char*>(g_mapped_snapshot->data()); 203 snapshot.data = reinterpret_cast<const char*>(g_mapped_snapshot->data());
189 snapshot.raw_size = static_cast<int>(g_mapped_snapshot->length()); 204 snapshot.raw_size = static_cast<int>(g_mapped_snapshot->length());
190 snapshot.compressed_size = static_cast<int>(g_mapped_snapshot->length());
191 v8::V8::SetSnapshotDataBlob(&snapshot); 205 v8::V8::SetSnapshotDataBlob(&snapshot);
192 #endif // V8_USE_EXTERNAL_STARTUP_DATA 206 #endif // V8_USE_EXTERNAL_STARTUP_DATA
193 v8::V8::Initialize(); 207 v8::V8::Initialize();
194 v8_is_initialized = true; 208 v8_is_initialized = true;
195 } 209 }
196 210
197 void IsolateHolder::AddRunMicrotasksObserver() { 211 void IsolateHolder::AddRunMicrotasksObserver() {
198 DCHECK(!task_observer_.get()); 212 DCHECK(!task_observer_.get());
199 task_observer_.reset(new RunMicrotasksObserver(isolate_));; 213 task_observer_.reset(new RunMicrotasksObserver(isolate_));;
200 base::MessageLoop::current()->AddTaskObserver(task_observer_.get()); 214 base::MessageLoop::current()->AddTaskObserver(task_observer_.get());
201 } 215 }
202 216
203 void IsolateHolder::RemoveRunMicrotasksObserver() { 217 void IsolateHolder::RemoveRunMicrotasksObserver() {
204 DCHECK(task_observer_.get()); 218 DCHECK(task_observer_.get());
205 base::MessageLoop::current()->RemoveTaskObserver(task_observer_.get()); 219 base::MessageLoop::current()->RemoveTaskObserver(task_observer_.get());
206 task_observer_.reset(); 220 task_observer_.reset();
207 } 221 }
208 222
209 } // namespace gin 223 } // namespace gin
OLDNEW
« no previous file with comments | « crypto/rsa_private_key_unittest.cc ('k') | gin/modules/module_registry_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698