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

Side by Side Diff: content/app/content_main_runner.cc

Issue 944913002: Transfer v8 snapshot files as file descriptors to child processes on Posix (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix iOS Created 5 years, 10 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/public/app/content_main_runner.h" 5 #include "content/public/app/content_main_runner.h"
6 6
7 #include <stdlib.h> 7 #include <stdlib.h>
8 8
9 #include "base/allocator/allocator_extension.h" 9 #include "base/allocator/allocator_extension.h"
10 #include "base/at_exit.h" 10 #include "base/at_exit.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 #include "ipc/ipc_switches.h" 46 #include "ipc/ipc_switches.h"
47 #include "media/base/media.h" 47 #include "media/base/media.h"
48 #include "sandbox/win/src/sandbox_types.h" 48 #include "sandbox/win/src/sandbox_types.h"
49 #include "ui/base/ui_base_paths.h" 49 #include "ui/base/ui_base_paths.h"
50 #include "ui/base/ui_base_switches.h" 50 #include "ui/base/ui_base_switches.h"
51 51
52 #ifdef V8_USE_EXTERNAL_STARTUP_DATA 52 #ifdef V8_USE_EXTERNAL_STARTUP_DATA
53 #include "gin/public/isolate_holder.h" 53 #include "gin/public/isolate_holder.h"
54 #endif 54 #endif
55 55
56 #if defined(OS_ANDROID)
57 #include "content/public/common/content_descriptors.h"
58 #endif
59
60 #if defined(USE_TCMALLOC) 56 #if defined(USE_TCMALLOC)
61 #include "third_party/tcmalloc/chromium/src/gperftools/malloc_extension.h" 57 #include "third_party/tcmalloc/chromium/src/gperftools/malloc_extension.h"
62 #if defined(TYPE_PROFILING) 58 #if defined(TYPE_PROFILING)
63 #include "base/allocator/type_profiler.h" 59 #include "base/allocator/type_profiler.h"
64 #include "base/allocator/type_profiler_tcmalloc.h" 60 #include "base/allocator/type_profiler_tcmalloc.h"
65 #endif 61 #endif
66 #endif 62 #endif
67 63
68 #if !defined(OS_IOS) 64 #if !defined(OS_IOS)
69 #include "content/app/mojo/mojo_init.h" 65 #include "content/app/mojo/mojo_init.h"
(...skipping 21 matching lines...) Expand all
91 #endif // !OS_IOS 87 #endif // !OS_IOS
92 #endif // OS_WIN 88 #endif // OS_WIN
93 89
94 #if defined(OS_POSIX) 90 #if defined(OS_POSIX)
95 #include <signal.h> 91 #include <signal.h>
96 92
97 #include "base/posix/global_descriptors.h" 93 #include "base/posix/global_descriptors.h"
98 #include "content/public/common/content_descriptors.h" 94 #include "content/public/common/content_descriptors.h"
99 95
100 #if !defined(OS_MACOSX) 96 #if !defined(OS_MACOSX)
97 #include "content/public/common/content_descriptors.h"
101 #include "content/public/common/zygote_fork_delegate_linux.h" 98 #include "content/public/common/zygote_fork_delegate_linux.h"
102 #endif 99 #endif
103 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) 100 #if !defined(OS_MACOSX) && !defined(OS_ANDROID)
104 #include "content/zygote/zygote_main.h" 101 #include "content/zygote/zygote_main.h"
105 #endif 102 #endif
106 103
107 #endif // OS_POSIX 104 #endif // OS_POSIX
108 105
109 #if !defined(OS_MACOSX) && defined(USE_TCMALLOC) 106 #if !defined(OS_MACOSX) && defined(USE_TCMALLOC)
110 extern "C" { 107 extern "C" {
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 // needs to be enabled. 488 // needs to be enabled.
492 const char* profiling = getenv(tracked_objects::kAlternateProfilerTime); 489 const char* profiling = getenv(tracked_objects::kAlternateProfilerTime);
493 if (profiling && 490 if (profiling &&
494 (atoi(profiling) == tracked_objects::TIME_SOURCE_TYPE_TCMALLOC)) { 491 (atoi(profiling) == tracked_objects::TIME_SOURCE_TYPE_TCMALLOC)) {
495 tracked_objects::SetAlternateTimeSource( 492 tracked_objects::SetAlternateTimeSource(
496 MallocExtension::GetBytesAllocatedOnCurrentThread, 493 MallocExtension::GetBytesAllocatedOnCurrentThread,
497 tracked_objects::TIME_SOURCE_TYPE_TCMALLOC); 494 tracked_objects::TIME_SOURCE_TYPE_TCMALLOC);
498 } 495 }
499 #endif // !OS_MACOSX && USE_TCMALLOC 496 #endif // !OS_MACOSX && USE_TCMALLOC
500 497
498 #if !defined(OS_IOS)
499 base::GlobalDescriptors* g_fds = base::GlobalDescriptors::GetInstance();
500 #endif
501
501 // On Android, 502 // On Android,
502 // - setlocale() is not supported. 503 // - setlocale() is not supported.
503 // - We do not override the signal handlers so that we can get 504 // - We do not override the signal handlers so that we can get
504 // stack trace when crashing. 505 // stack trace when crashing.
505 // - The ipc_fd is passed through the Java service. 506 // - The ipc_fd is passed through the Java service.
506 // Thus, these are all disabled. 507 // Thus, these are all disabled.
507 #if !defined(OS_ANDROID) && !defined(OS_IOS) 508 #if !defined(OS_ANDROID) && !defined(OS_IOS)
508 // Set C library locale to make sure CommandLine can parse argument values 509 // Set C library locale to make sure CommandLine can parse argument values
509 // in correct encoding. 510 // in correct encoding.
510 setlocale(LC_ALL, ""); 511 setlocale(LC_ALL, "");
511 512
512 SetupSignalHandlers(); 513 SetupSignalHandlers();
513
514 base::GlobalDescriptors* g_fds = base::GlobalDescriptors::GetInstance();
515 g_fds->Set(kPrimaryIPCChannel, 514 g_fds->Set(kPrimaryIPCChannel,
516 kPrimaryIPCChannel + base::GlobalDescriptors::kBaseDescriptor); 515 kPrimaryIPCChannel + base::GlobalDescriptors::kBaseDescriptor);
517 #endif // !OS_ANDROID && !OS_IOS 516 #endif // !OS_ANDROID && !OS_IOS
518 517
519 #if defined(OS_LINUX) || defined(OS_OPENBSD) 518 #if defined(OS_LINUX) || defined(OS_OPENBSD)
520 g_fds->Set(kCrashDumpSignal, 519 g_fds->Set(kCrashDumpSignal,
521 kCrashDumpSignal + base::GlobalDescriptors::kBaseDescriptor); 520 kCrashDumpSignal + base::GlobalDescriptors::kBaseDescriptor);
522 #endif 521 #endif // OS_LINUX || OS_OPENBSD
522
523 523
524 #endif // !OS_WIN 524 #endif // !OS_WIN
525 525
526 is_initialized_ = true; 526 is_initialized_ = true;
527 delegate_ = params.delegate; 527 delegate_ = params.delegate;
528 528
529 // The exit manager is in charge of calling the dtors of singleton objects. 529 // The exit manager is in charge of calling the dtors of singleton objects.
530 // On Android, AtExitManager is set up when library is loaded. 530 // On Android, AtExitManager is set up when library is loaded.
531 // On iOS, it's set up in main(), which can't call directly through to here. 531 // On iOS, it's set up in main(), which can't call directly through to here.
532 // A consequence of this is that you can't use the ctor/dtor-based 532 // A consequence of this is that you can't use the ctor/dtor-based
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
672 672
673 #if defined(USE_NSS) 673 #if defined(USE_NSS)
674 crypto::EarlySetupForNSSInit(); 674 crypto::EarlySetupForNSSInit();
675 #endif 675 #endif
676 676
677 ui::RegisterPathProvider(); 677 ui::RegisterPathProvider();
678 RegisterPathProvider(); 678 RegisterPathProvider();
679 RegisterContentSchemes(true); 679 RegisterContentSchemes(true);
680 680
681 #if defined(OS_ANDROID) 681 #if defined(OS_ANDROID)
682 int icudata_fd = base::GlobalDescriptors::GetInstance()->MaybeGet( 682 int icudata_fd = g_fds->MaybeGet(kAndroidICUDataDescriptor);
683 kAndroidICUDataDescriptor);
684 if (icudata_fd != -1) { 683 if (icudata_fd != -1) {
685 auto icudata_region = base::GlobalDescriptors::GetInstance()->GetRegion( 684 auto icudata_region = g_fds->GetRegion(kAndroidICUDataDescriptor);
686 kAndroidICUDataDescriptor);
687 CHECK(base::i18n::InitializeICUWithFileDescriptor(icudata_fd, 685 CHECK(base::i18n::InitializeICUWithFileDescriptor(icudata_fd,
688 icudata_region)); 686 icudata_region));
689 } else { 687 } else {
690 CHECK(base::i18n::InitializeICU()); 688 CHECK(base::i18n::InitializeICU());
691 } 689 }
690 #else
691 CHECK(base::i18n::InitializeICU());
692 #endif // OS_ANDROID
692 693
693 #if defined(V8_USE_EXTERNAL_STARTUP_DATA) 694 #if defined(V8_USE_EXTERNAL_STARTUP_DATA)
694 int v8_natives_fd = base::GlobalDescriptors::GetInstance()->MaybeGet( 695 #if defined(OS_POSIX) && !defined(OS_MACOSX)
695 kV8NativesDataDescriptor); 696 #if !defined(OS_ANDROID)
696 int v8_snapshot_fd = base::GlobalDescriptors::GetInstance()->MaybeGet( 697 // kV8NativesDataDescriptor and kV8SnapshotDataDescriptor are shared with
697 kV8SnapshotDataDescriptor); 698 // child processes. On Android they are set in
699 // ChildProcessService::InternalInitChildProcess, otherwise set them here.
700 if (!process_type.empty() && process_type != switches::kZygoteProcess) {
701 g_fds->Set(
702 kV8NativesDataDescriptor,
703 kV8NativesDataDescriptor + base::GlobalDescriptors::kBaseDescriptor);
704 g_fds->Set(
705 kV8SnapshotDataDescriptor,
706 kV8SnapshotDataDescriptor + base::GlobalDescriptors::kBaseDescriptor);
707 }
708 #endif // !OS_ANDROID
709 int v8_natives_fd = g_fds->MaybeGet(kV8NativesDataDescriptor);
710 int v8_snapshot_fd = g_fds->MaybeGet(kV8SnapshotDataDescriptor);
698 if (v8_natives_fd != -1 && v8_snapshot_fd != -1) { 711 if (v8_natives_fd != -1 && v8_snapshot_fd != -1) {
699 auto v8_natives_region = 712 auto v8_natives_region = g_fds->GetRegion(kV8NativesDataDescriptor);
700 base::GlobalDescriptors::GetInstance()->GetRegion( 713 auto v8_snapshot_region = g_fds->GetRegion(kV8SnapshotDataDescriptor);
701 kV8NativesDataDescriptor);
702 auto v8_snapshot_region =
703 base::GlobalDescriptors::GetInstance()->GetRegion(
704 kV8SnapshotDataDescriptor);
705 CHECK(gin::IsolateHolder::LoadV8SnapshotFd( 714 CHECK(gin::IsolateHolder::LoadV8SnapshotFd(
706 v8_natives_fd, v8_natives_region.offset, v8_natives_region.size, 715 v8_natives_fd, v8_natives_region.offset, v8_natives_region.size,
707 v8_snapshot_fd, v8_snapshot_region.offset, v8_snapshot_region.size)); 716 v8_snapshot_fd, v8_snapshot_region.offset, v8_snapshot_region.size));
708 } else { 717 } else {
709 CHECK(gin::IsolateHolder::LoadV8Snapshot()); 718 CHECK(gin::IsolateHolder::LoadV8Snapshot());
710 } 719 }
711 #endif // V8_USE_EXTERNAL_STARTUP_DATA
712
713 #else 720 #else
714 CHECK(base::i18n::InitializeICU());
715 #if defined(V8_USE_EXTERNAL_STARTUP_DATA)
716 CHECK(gin::IsolateHolder::LoadV8Snapshot()); 721 CHECK(gin::IsolateHolder::LoadV8Snapshot());
722 #endif // OS_POSIX && !OS_MACOSX
717 #endif // V8_USE_EXTERNAL_STARTUP_DATA 723 #endif // V8_USE_EXTERNAL_STARTUP_DATA
718 #endif // OS_ANDROID
719 724
720 if (delegate_) 725 if (delegate_)
721 delegate_->PreSandboxStartup(); 726 delegate_->PreSandboxStartup();
722 727
723 if (!process_type.empty()) 728 if (!process_type.empty())
724 CommonSubprocessInit(process_type); 729 CommonSubprocessInit(process_type);
725 730
726 #if defined(OS_WIN) 731 #if defined(OS_WIN)
727 CHECK(InitializeSandbox(params.sandbox_info)); 732 CHECK(InitializeSandbox(params.sandbox_info));
728 #elif defined(OS_MACOSX) && !defined(OS_IOS) 733 #elif defined(OS_MACOSX) && !defined(OS_IOS)
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
822 827
823 DISALLOW_COPY_AND_ASSIGN(ContentMainRunnerImpl); 828 DISALLOW_COPY_AND_ASSIGN(ContentMainRunnerImpl);
824 }; 829 };
825 830
826 // static 831 // static
827 ContentMainRunner* ContentMainRunner::Create() { 832 ContentMainRunner* ContentMainRunner::Create() {
828 return new ContentMainRunnerImpl(); 833 return new ContentMainRunnerImpl();
829 } 834 }
830 835
831 } // namespace content 836 } // namespace content
OLDNEW
« no previous file with comments | « chrome/browser/chrome_content_browser_client.cc ('k') | content/public/common/content_descriptors.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698