| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/app/chrome_main.h" | 5 #include "chrome/app/chrome_main.h" |
| 6 | 6 |
| 7 #include "app/app_paths.h" | 7 #include "app/app_paths.h" |
| 8 #include "base/at_exit.h" | 8 #include "base/at_exit.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/debug/debugger.h" | 10 #include "base/debug/debugger.h" |
| 11 #include "base/i18n/icu_util.h" | 11 #include "base/i18n/icu_util.h" |
| 12 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
| 13 #include "base/mac/scoped_nsautorelease_pool.h" | 13 #include "base/mac/scoped_nsautorelease_pool.h" |
| 14 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
| 15 #include "base/metrics/stats_counters.h" | 15 #include "base/metrics/stats_counters.h" |
| 16 #include "base/metrics/stats_table.h" | 16 #include "base/metrics/stats_table.h" |
| 17 #include "base/path_service.h" | 17 #include "base/path_service.h" |
| 18 #include "base/process_util.h" | 18 #include "base/process_util.h" |
| 19 #include "base/stringprintf.h" | 19 #include "base/stringprintf.h" |
| 20 #include "base/string_number_conversions.h" | 20 #include "base/string_number_conversions.h" |
| 21 #include "base/utf_string_conversions.h" | 21 #include "base/utf_string_conversions.h" |
| 22 #include "build/build_config.h" | 22 #include "build/build_config.h" |
| 23 #include "crypto/nss_util.h" | 23 #include "crypto/nss_util.h" |
| 24 #include "chrome/browser/defaults.h" | 24 #include "chrome/browser/defaults.h" |
| 25 #include "chrome/browser/diagnostics/diagnostics_main.h" | 25 #include "chrome/browser/diagnostics/diagnostics_main.h" |
| 26 #include "chrome/browser/mac/relauncher.h" |
| 26 #include "chrome/browser/platform_util.h" | 27 #include "chrome/browser/platform_util.h" |
| 27 #include "chrome/common/chrome_constants.h" | 28 #include "chrome/common/chrome_constants.h" |
| 28 #include "chrome/common/chrome_content_client.h" | 29 #include "chrome/common/chrome_content_client.h" |
| 29 #include "chrome/common/chrome_content_plugin_client.h" | 30 #include "chrome/common/chrome_content_plugin_client.h" |
| 30 #include "chrome/common/chrome_paths.h" | 31 #include "chrome/common/chrome_paths.h" |
| 31 #include "chrome/common/chrome_paths_internal.h" | 32 #include "chrome/common/chrome_paths_internal.h" |
| 32 #include "chrome/common/chrome_switches.h" | 33 #include "chrome/common/chrome_switches.h" |
| 33 #include "chrome/common/chrome_version_info.h" | 34 #include "chrome/common/chrome_version_info.h" |
| 34 #include "chrome/common/logging_chrome.h" | 35 #include "chrome/common/logging_chrome.h" |
| 35 #include "chrome/common/profiling.h" | 36 #include "chrome/common/profiling.h" |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 // The zygote process opens the resources for the renderers. | 291 // The zygote process opens the resources for the renderers. |
| 291 process_type == switches::kZygoteProcess || | 292 process_type == switches::kZygoteProcess || |
| 292 #endif | 293 #endif |
| 293 process_type == switches::kRendererProcess || | 294 process_type == switches::kRendererProcess || |
| 294 process_type == switches::kExtensionProcess || | 295 process_type == switches::kExtensionProcess || |
| 295 process_type == switches::kUtilityProcess; | 296 process_type == switches::kUtilityProcess; |
| 296 } | 297 } |
| 297 | 298 |
| 298 // Returns true if this process is a child of the browser process. | 299 // Returns true if this process is a child of the browser process. |
| 299 bool SubprocessIsBrowserChild(const std::string& process_type) { | 300 bool SubprocessIsBrowserChild(const std::string& process_type) { |
| 300 if (process_type.empty() || process_type == switches::kServiceProcess) { | 301 if (process_type.empty() || |
| 302 #if defined(OS_MACOSX) |
| 303 process_type == switches::kRelauncherProcess || |
| 304 #endif |
| 305 process_type == switches::kServiceProcess) { |
| 301 return false; | 306 return false; |
| 302 } | 307 } |
| 303 return true; | 308 return true; |
| 304 } | 309 } |
| 305 | 310 |
| 306 #if defined(OS_MACOSX) | 311 #if defined(OS_MACOSX) |
| 307 // Update the name shown in Activity Monitor so users are less likely to ask | 312 // Update the name shown in Activity Monitor so users are less likely to ask |
| 308 // why Chrome has so many processes. | 313 // why Chrome has so many processes. |
| 309 void SetMacProcessName(const std::string& process_type) { | 314 void SetMacProcessName(const std::string& process_type) { |
| 310 // Don't worry about the browser process, its gets the stock name. | 315 // Don't worry about the browser process, its gets the stock name. |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 { switches::kWorkerProcess, WorkerMain }, | 498 { switches::kWorkerProcess, WorkerMain }, |
| 494 { switches::kPpapiPluginProcess, PpapiPluginMain }, | 499 { switches::kPpapiPluginProcess, PpapiPluginMain }, |
| 495 { switches::kPpapiBrokerProcess, PpapiBrokerMain }, | 500 { switches::kPpapiBrokerProcess, PpapiBrokerMain }, |
| 496 { switches::kUtilityProcess, UtilityMain }, | 501 { switches::kUtilityProcess, UtilityMain }, |
| 497 { switches::kGpuProcess, GpuMain }, | 502 { switches::kGpuProcess, GpuMain }, |
| 498 { switches::kServiceProcess, ServiceProcessMain }, | 503 { switches::kServiceProcess, ServiceProcessMain }, |
| 499 | 504 |
| 500 #if defined(OS_MACOSX) | 505 #if defined(OS_MACOSX) |
| 501 // TODO(port): Use OOP profile import - http://crbug.com/22142 . | 506 // TODO(port): Use OOP profile import - http://crbug.com/22142 . |
| 502 { switches::kProfileImportProcess, ProfileImportMain }, | 507 { switches::kProfileImportProcess, ProfileImportMain }, |
| 508 { switches::kRelauncherProcess, mac_relauncher::RelauncherMain }, |
| 503 #endif | 509 #endif |
| 504 #if !defined(DISABLE_NACL) | 510 #if !defined(DISABLE_NACL) |
| 505 { switches::kNaClLoaderProcess, NaClMain }, | 511 { switches::kNaClLoaderProcess, NaClMain }, |
| 506 #ifdef _WIN64 // The broker process is used only on Win64. | 512 #ifdef _WIN64 // The broker process is used only on Win64. |
| 507 { switches::kNaClBrokerProcess, NaClBrokerMain }, | 513 { switches::kNaClBrokerProcess, NaClBrokerMain }, |
| 508 #endif | 514 #endif |
| 509 #endif // DISABLE_NACL | 515 #endif // DISABLE_NACL |
| 510 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 516 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
| 511 // Zygote startup is special -- see RunZygote comments above | 517 // Zygote startup is special -- see RunZygote comments above |
| 512 // for why we don't use ZygoteMain directly. | 518 // for why we don't use ZygoteMain directly. |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 598 browser_pid = static_cast<base::ProcessId>(browser_pid_int); | 604 browser_pid = static_cast<base::ProcessId>(browser_pid_int); |
| 599 DCHECK_NE(browser_pid_int, 0); | 605 DCHECK_NE(browser_pid_int, 0); |
| 600 #elif defined(OS_POSIX) | 606 #elif defined(OS_POSIX) |
| 601 // On linux, we're in the zygote here; so we need the parent process' id. | 607 // On linux, we're in the zygote here; so we need the parent process' id. |
| 602 browser_pid = base::GetParentProcessId(base::GetCurrentProcId()); | 608 browser_pid = base::GetParentProcessId(base::GetCurrentProcId()); |
| 603 #endif | 609 #endif |
| 604 | 610 |
| 605 #if defined(OS_MACOSX) | 611 #if defined(OS_MACOSX) |
| 606 SendTaskPortToParentProcess(); | 612 SendTaskPortToParentProcess(); |
| 607 #endif | 613 #endif |
| 614 } |
| 608 | 615 |
| 609 #if defined(OS_POSIX) | 616 #if defined(OS_POSIX) |
| 617 if (!process_type.empty()) { |
| 610 // When you hit Ctrl-C in a terminal running the browser | 618 // When you hit Ctrl-C in a terminal running the browser |
| 611 // process, a SIGINT is delivered to the entire process group. | 619 // process, a SIGINT is delivered to the entire process group. |
| 612 // When debugging the browser process via gdb, gdb catches the | 620 // When debugging the browser process via gdb, gdb catches the |
| 613 // SIGINT for the browser process (and dumps you back to the gdb | 621 // SIGINT for the browser process (and dumps you back to the gdb |
| 614 // console) but doesn't for the child processes, killing them. | 622 // console) but doesn't for the child processes, killing them. |
| 615 // The fix is to have child processes ignore SIGINT; they'll die | 623 // The fix is to have child processes ignore SIGINT; they'll die |
| 616 // on their own when the browser process goes away. | 624 // on their own when the browser process goes away. |
| 617 // | 625 // |
| 618 // Note that we *can't* rely on BeingDebugged to catch this case because we | 626 // Note that we *can't* rely on BeingDebugged to catch this case because we |
| 619 // are the child process, which is not being debugged. | 627 // are the child process, which is not being debugged. |
| 620 // TODO(evanm): move this to some shared subprocess-init function. | 628 // TODO(evanm): move this to some shared subprocess-init function. |
| 621 if (!base::debug::BeingDebugged()) | 629 if (!base::debug::BeingDebugged()) |
| 622 signal(SIGINT, SIG_IGN); | 630 signal(SIGINT, SIG_IGN); |
| 631 } |
| 623 #endif | 632 #endif |
| 624 } | 633 |
| 625 SetupCRT(command_line); | 634 SetupCRT(command_line); |
| 626 | 635 |
| 627 #if defined(USE_NSS) | 636 #if defined(USE_NSS) |
| 628 crypto::EarlySetupForNSSInit(); | 637 crypto::EarlySetupForNSSInit(); |
| 629 #endif | 638 #endif |
| 630 | 639 |
| 631 // Initialize the Chrome path provider. | 640 // Initialize the Chrome path provider. |
| 632 app::RegisterPathProvider(); | 641 app::RegisterPathProvider(); |
| 633 ui::RegisterPathProvider(); | 642 ui::RegisterPathProvider(); |
| 634 chrome::RegisterPathProvider(); | 643 chrome::RegisterPathProvider(); |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 839 | 848 |
| 840 if (SubprocessNeedsResourceBundle(process_type)) | 849 if (SubprocessNeedsResourceBundle(process_type)) |
| 841 ResourceBundle::CleanupSharedInstance(); | 850 ResourceBundle::CleanupSharedInstance(); |
| 842 | 851 |
| 843 logging::CleanupChromeLogging(); | 852 logging::CleanupChromeLogging(); |
| 844 | 853 |
| 845 chrome_main::LowLevelShutdown(); | 854 chrome_main::LowLevelShutdown(); |
| 846 | 855 |
| 847 return exit_code; | 856 return exit_code; |
| 848 } | 857 } |
| OLD | NEW |