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

Side by Side Diff: chromecast/browser/cast_content_browser_client.cc

Issue 1156873002: Load v8 snapshots directly from APK (and store them uncompressed) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@v8initializer
Patch Set: Keep extracting for components/ Created 5 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "chromecast/browser/cast_content_browser_client.h" 5 #include "chromecast/browser/cast_content_browser_client.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/base_switches.h" 9 #include "base/base_switches.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 20 matching lines...) Expand all
31 #include "content/public/browser/browser_thread.h" 31 #include "content/public/browser/browser_thread.h"
32 #include "content/public/browser/certificate_request_result_type.h" 32 #include "content/public/browser/certificate_request_result_type.h"
33 #include "content/public/browser/client_certificate_delegate.h" 33 #include "content/public/browser/client_certificate_delegate.h"
34 #include "content/public/browser/render_process_host.h" 34 #include "content/public/browser/render_process_host.h"
35 #include "content/public/browser/resource_dispatcher_host.h" 35 #include "content/public/browser/resource_dispatcher_host.h"
36 #include "content/public/browser/web_contents.h" 36 #include "content/public/browser/web_contents.h"
37 #include "content/public/common/content_descriptors.h" 37 #include "content/public/common/content_descriptors.h"
38 #include "content/public/common/content_switches.h" 38 #include "content/public/common/content_switches.h"
39 #include "content/public/common/url_constants.h" 39 #include "content/public/common/url_constants.h"
40 #include "content/public/common/web_preferences.h" 40 #include "content/public/common/web_preferences.h"
41 #include "gin/v8_initializer.h"
42 #include "media/audio/audio_manager_factory.h" 41 #include "media/audio/audio_manager_factory.h"
43 #include "net/ssl/ssl_cert_request_info.h" 42 #include "net/ssl/ssl_cert_request_info.h"
44 #include "net/url_request/url_request_context_getter.h" 43 #include "net/url_request/url_request_context_getter.h"
45 #include "ui/gl/gl_switches.h" 44 #include "ui/gl/gl_switches.h"
46 45
47 #if defined(OS_ANDROID) 46 #if defined(OS_ANDROID)
48 #include "components/crash/browser/crash_dump_manager_android.h" 47 #include "components/crash/browser/crash_dump_manager_android.h"
49 #include "components/external_video_surface/browser/android/external_video_surfa ce_container_impl.h" 48 #include "components/external_video_surface/browser/android/external_video_surfa ce_container_impl.h"
50 #endif // defined(OS_ANDROID) 49 #endif // defined(OS_ANDROID)
51 50
52 namespace chromecast { 51 namespace chromecast {
53 namespace shell { 52 namespace shell {
54 53
55 CastContentBrowserClient::CastContentBrowserClient() 54 CastContentBrowserClient::CastContentBrowserClient()
56 : v8_natives_fd_(-1), 55 : url_request_context_factory_(new URLRequestContextFactory()) {
57 v8_snapshot_fd_(-1),
58 url_request_context_factory_(new URLRequestContextFactory()) {
59 } 56 }
60 57
61 CastContentBrowserClient::~CastContentBrowserClient() { 58 CastContentBrowserClient::~CastContentBrowserClient() {
62 content::BrowserThread::DeleteSoon( 59 content::BrowserThread::DeleteSoon(
63 content::BrowserThread::IO, 60 content::BrowserThread::IO,
64 FROM_HERE, 61 FROM_HERE,
65 url_request_context_factory_.release()); 62 url_request_context_factory_.release());
66 } 63 }
67 64
68 content::BrowserMainParts* CastContentBrowserClient::CreateBrowserMainParts( 65 content::BrowserMainParts* CastContentBrowserClient::CreateBrowserMainParts(
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 if (scheme == url::kFileScheme) { 143 if (scheme == url::kFileScheme) {
147 return base::CommandLine::ForCurrentProcess()->HasSwitch( 144 return base::CommandLine::ForCurrentProcess()->HasSwitch(
148 switches::kEnableLocalFileAccesses); 145 switches::kEnableLocalFileAccesses);
149 } 146 }
150 147
151 return false; 148 return false;
152 } 149 }
153 150
154 void CastContentBrowserClient::AppendMappedFileCommandLineSwitches( 151 void CastContentBrowserClient::AppendMappedFileCommandLineSwitches(
155 base::CommandLine* command_line) { 152 base::CommandLine* command_line) {
153 #if defined(OS_POSIX) && !defined(OS_MACOSX)
154 #if defined(V8_USE_EXTERNAL_STARTUP_DATA)
156 std::string process_type = 155 std::string process_type =
157 command_line->GetSwitchValueNative(switches::kProcessType); 156 command_line->GetSwitchValueASCII(switches::kProcessType);
158
159 #if defined(V8_USE_EXTERNAL_STARTUP_DATA)
160 if (process_type != switches::kZygoteProcess) { 157 if (process_type != switches::kZygoteProcess) {
161 DCHECK(natives_fd_exists()); 158 DCHECK(v8_files_.natives_fd.is_valid());
162 command_line->AppendSwitch(::switches::kV8NativesPassedByFD); 159 command_line->AppendSwitch(::switches::kV8NativesPassedByFD);
163 if (snapshot_fd_exists()) 160 if (v8_files_.snapshot_fd.is_valid()) {
164 command_line->AppendSwitch(::switches::kV8SnapshotPassedByFD); 161 command_line->AppendSwitch(::switches::kV8SnapshotPassedByFD);
162 }
165 } 163 }
164 #endif // V8_USE_EXTERNAL_STARTUP_DATA
165 #endif // OS_POSIX && !OS_MACOSX
166 } 166 }
167 167
168 #endif // V8_USE_EXTERNAL_STARTUP_DATA 168 #endif // V8_USE_EXTERNAL_STARTUP_DATA
169 void CastContentBrowserClient::AppendExtraCommandLineSwitches( 169 void CastContentBrowserClient::AppendExtraCommandLineSwitches(
170 base::CommandLine* command_line, 170 base::CommandLine* command_line,
171 int child_process_id) { 171 int child_process_id) {
172 std::string process_type = 172 std::string process_type =
173 command_line->GetSwitchValueNative(switches::kProcessType); 173 command_line->GetSwitchValueNative(switches::kProcessType);
174 base::CommandLine* browser_command_line = 174 base::CommandLine* browser_command_line =
175 base::CommandLine::ForCurrentProcess(); 175 base::CommandLine::ForCurrentProcess();
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 325
326 void CastContentBrowserClient::GetAdditionalMappedFilesForChildProcess( 326 void CastContentBrowserClient::GetAdditionalMappedFilesForChildProcess(
327 const base::CommandLine& command_line, 327 const base::CommandLine& command_line,
328 int child_process_id, 328 int child_process_id,
329 content::FileDescriptorInfo* mappings 329 content::FileDescriptorInfo* mappings
330 #if defined(OS_ANDROID) 330 #if defined(OS_ANDROID)
331 , std::map<int, base::MemoryMappedFile::Region>* regions 331 , std::map<int, base::MemoryMappedFile::Region>* regions
332 #endif 332 #endif
333 ) { 333 ) {
334 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) 334 #if defined(V8_USE_EXTERNAL_STARTUP_DATA)
335 if (!natives_fd_exists()) { 335 if (!v8_files_.natives_fd.is_valid()) {
336 int v8_natives_fd = -1; 336 gin::V8Initializer::OpenV8FilesForChildProcesses(&v8_files_);
337 int v8_snapshot_fd = -1;
338 if (gin::V8Initializer::OpenV8FilesForChildProcesses(&v8_natives_fd,
339 &v8_snapshot_fd)) {
340 v8_natives_fd_.reset(v8_natives_fd);
341 v8_snapshot_fd_.reset(v8_snapshot_fd);
342 }
343 } 337 }
344 // V8 can't start up without the source of the natives, but it can 338 DCHECK(v8_files_.natives_fd.is_valid());
345 // start up (slower) without the snapshot. 339 mappings->Share(kV8NativesDataDescriptor, v8_files_.natives_fd.get());
346 DCHECK(natives_fd_exists()); 340 #if defined(OS_ANDROID)
347 mappings->Share(kV8NativesDataDescriptor, v8_natives_fd_.get()); 341 regions->insert(
348 mappings->Share(kV8SnapshotDataDescriptor, v8_snapshot_fd_.get()); 342 std::make_pair(kV8NativesDataDescriptor, v8_files_.natives_region));
343 #endif
344 if (v8_files_.snapshot_fd.is_valid()) {
345 mappings->Share(kV8SnapshotDataDescriptor, v8_files_.snapshot_fd.get());
346 #if defined(OS_ANDROID)
347 regions->insert(
348 std::make_pair(kV8SnapshotDataDescriptor, v8_files_.snapshot_region));
349 #endif
350 }
349 #endif // V8_USE_EXTERNAL_STARTUP_DATA 351 #endif // V8_USE_EXTERNAL_STARTUP_DATA
350 #if defined(OS_ANDROID) 352 #if defined(OS_ANDROID)
351 const int flags_open_read = base::File::FLAG_OPEN | base::File::FLAG_READ; 353 const int flags_open_read = base::File::FLAG_OPEN | base::File::FLAG_READ;
352 base::FilePath pak_file_path; 354 base::FilePath pak_file_path;
353 CHECK(PathService::Get(FILE_CAST_PAK, &pak_file_path)); 355 CHECK(PathService::Get(FILE_CAST_PAK, &pak_file_path));
354 base::File pak_file(pak_file_path, flags_open_read); 356 base::File pak_file(pak_file_path, flags_open_read);
355 if (!pak_file.IsValid()) { 357 if (!pak_file.IsValid()) {
356 NOTREACHED() << "Failed to open file when creating renderer process: " 358 NOTREACHED() << "Failed to open file when creating renderer process: "
357 << "cast_shell.pak"; 359 << "cast_shell.pak";
358 } 360 }
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 process_type, dumps_path, false /* upload */); 434 process_type, dumps_path, false /* upload */);
433 // StartUploaderThread() even though upload is diferred. 435 // StartUploaderThread() even though upload is diferred.
434 // Breakpad-related memory is freed in the uploader thread. 436 // Breakpad-related memory is freed in the uploader thread.
435 crash_handler->StartUploaderThread(); 437 crash_handler->StartUploaderThread();
436 return crash_handler; 438 return crash_handler;
437 } 439 }
438 #endif // !defined(OS_ANDROID) 440 #endif // !defined(OS_ANDROID)
439 441
440 } // namespace shell 442 } // namespace shell
441 } // namespace chromecast 443 } // namespace chromecast
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698