| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 // TODO(port): the ifdefs in here are a first step towards trying to determine | 5 // TODO(port): the ifdefs in here are a first step towards trying to determine |
| 6 // the correct abstraction for all the OS functionality required at this | 6 // the correct abstraction for all the OS functionality required at this |
| 7 // stage of process initialization. It should not be taken as a final | 7 // stage of process initialization. It should not be taken as a final |
| 8 // abstraction. | 8 // abstraction. |
| 9 | 9 |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 #endif | 73 #endif |
| 74 | 74 |
| 75 #if defined(OS_LINUX) | 75 #if defined(OS_LINUX) |
| 76 #include "chrome/browser/renderer_host/render_sandbox_host_linux.h" | 76 #include "chrome/browser/renderer_host/render_sandbox_host_linux.h" |
| 77 #include "chrome/browser/zygote_host_linux.h" | 77 #include "chrome/browser/zygote_host_linux.h" |
| 78 #endif | 78 #endif |
| 79 | 79 |
| 80 #if defined(OS_MACOSX) | 80 #if defined(OS_MACOSX) |
| 81 #include "app/l10n_util_mac.h" | 81 #include "app/l10n_util_mac.h" |
| 82 #include "base/mac_util.h" | 82 #include "base/mac_util.h" |
| 83 #include "base/mach_ipc_mac.h" |
| 84 #include "chrome/app/breakpad_mac.h" |
| 85 #include "chrome/browser/mach_broker_mac.h" |
| 83 #include "chrome/common/chrome_paths_internal.h" | 86 #include "chrome/common/chrome_paths_internal.h" |
| 84 #include "chrome/app/breakpad_mac.h" | |
| 85 #include "grit/chromium_strings.h" | 87 #include "grit/chromium_strings.h" |
| 86 #include "third_party/WebKit/WebKit/mac/WebCoreSupport/WebSystemInterface.h" | 88 #include "third_party/WebKit/WebKit/mac/WebCoreSupport/WebSystemInterface.h" |
| 87 #endif | 89 #endif |
| 88 | 90 |
| 89 #if defined(OS_POSIX) | 91 #if defined(OS_POSIX) |
| 90 #include "base/global_descriptors_posix.h" | 92 #include "base/global_descriptors_posix.h" |
| 91 #endif | 93 #endif |
| 92 | 94 |
| 93 #if defined(OS_WIN) | 95 #if defined(OS_WIN) |
| 94 #include "sandbox/src/sandbox.h" | 96 #include "sandbox/src/sandbox.h" |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 } else if (process_type == switches::kExtensionProcess) { | 404 } else if (process_type == switches::kExtensionProcess) { |
| 403 name_id = IDS_WORKER_APP_NAME; | 405 name_id = IDS_WORKER_APP_NAME; |
| 404 } else if (process_type == switches::kUtilityProcess) { | 406 } else if (process_type == switches::kUtilityProcess) { |
| 405 name_id = IDS_UTILITY_APP_NAME; | 407 name_id = IDS_UTILITY_APP_NAME; |
| 406 } | 408 } |
| 407 if (name_id) { | 409 if (name_id) { |
| 408 NSString* app_name = l10n_util::GetNSString(name_id); | 410 NSString* app_name = l10n_util::GetNSString(name_id); |
| 409 mac_util::SetProcessName(reinterpret_cast<CFStringRef>(app_name)); | 411 mac_util::SetProcessName(reinterpret_cast<CFStringRef>(app_name)); |
| 410 } | 412 } |
| 411 } | 413 } |
| 414 |
| 415 // Completes the Mach IPC handshake by sending this process' task port to the |
| 416 // parent process. The parent is listening on the Mach port given by |
| 417 // |GetMachPortName()|. The task port is used by the parent to get CPU/memory |
| 418 // stats to display in the task manager. |
| 419 void SendTaskPortToParentProcess() { |
| 420 const mach_msg_timeout_t kTimeoutMs = 100; |
| 421 const int32_t kMessageId = 0; |
| 422 std::string mach_port_name = MachBroker::GetMachPortName(); |
| 423 |
| 424 base::MachSendMessage child_message(kMessageId); |
| 425 if (!child_message.AddDescriptor(mach_task_self())) { |
| 426 LOG(ERROR) << "child AddDescriptor(mach_task_self()) failed."; |
| 427 return; |
| 428 } |
| 429 |
| 430 base::MachPortSender child_sender(mach_port_name.c_str()); |
| 431 kern_return_t err = child_sender.SendMessage(child_message, kTimeoutMs); |
| 432 if (err != KERN_SUCCESS) { |
| 433 LOG(ERROR) << StringPrintf("child SendMessage() failed: 0x%x %s", err, |
| 434 mach_error_string(err)); |
| 435 } |
| 436 } |
| 412 #endif // defined(OS_MACOSX) | 437 #endif // defined(OS_MACOSX) |
| 413 | 438 |
| 414 void InitializeStatsTable(base::ProcessId browser_pid, | 439 void InitializeStatsTable(base::ProcessId browser_pid, |
| 415 const CommandLine & parsed_command_line) { | 440 const CommandLine & parsed_command_line) { |
| 416 // Initialize the Stats Counters table. With this initialized, | 441 // Initialize the Stats Counters table. With this initialized, |
| 417 // the StatsViewer can be utilized to read counters outside of | 442 // the StatsViewer can be utilized to read counters outside of |
| 418 // Chrome. These lines can be commented out to effectively turn | 443 // Chrome. These lines can be commented out to effectively turn |
| 419 // counters 'off'. The table is created and exists for the life | 444 // counters 'off'. The table is created and exists for the life |
| 420 // of the process. It is not cleaned up. | 445 // of the process. It is not cleaned up. |
| 421 if (parsed_command_line.HasSwitch(switches::kEnableStatsTable) || | 446 if (parsed_command_line.HasSwitch(switches::kEnableStatsTable) || |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 581 #if defined(OS_WIN) | 606 #if defined(OS_WIN) |
| 582 std::string channel_name = | 607 std::string channel_name = |
| 583 parsed_command_line.GetSwitchValueASCII(switches::kProcessChannelID); | 608 parsed_command_line.GetSwitchValueASCII(switches::kProcessChannelID); |
| 584 | 609 |
| 585 int browser_pid_int; | 610 int browser_pid_int; |
| 586 base::StringToInt(channel_name, &browser_pid_int); | 611 base::StringToInt(channel_name, &browser_pid_int); |
| 587 browser_pid = static_cast<base::ProcessId>(browser_pid_int); | 612 browser_pid = static_cast<base::ProcessId>(browser_pid_int); |
| 588 DCHECK_NE(browser_pid, 0u); | 613 DCHECK_NE(browser_pid, 0u); |
| 589 #elif defined(OS_MACOSX) | 614 #elif defined(OS_MACOSX) |
| 590 browser_pid = base::GetCurrentProcId(); | 615 browser_pid = base::GetCurrentProcId(); |
| 616 SendTaskPortToParentProcess(); |
| 591 #elif defined(OS_POSIX) | 617 #elif defined(OS_POSIX) |
| 592 // On linux, we're in the zygote here; so we need the parent process' id. | 618 // On linux, we're in the zygote here; so we need the parent process' id. |
| 593 browser_pid = base::GetParentProcessId(base::GetCurrentProcId()); | 619 browser_pid = base::GetParentProcessId(base::GetCurrentProcId()); |
| 594 #endif | 620 #endif |
| 595 | 621 |
| 596 #if defined(OS_POSIX) | 622 #if defined(OS_POSIX) |
| 597 // When you hit Ctrl-C in a terminal running the browser | 623 // When you hit Ctrl-C in a terminal running the browser |
| 598 // process, a SIGINT is delivered to the entire process group. | 624 // process, a SIGINT is delivered to the entire process group. |
| 599 // When debugging the browser process via gdb, gdb catches the | 625 // When debugging the browser process via gdb, gdb catches the |
| 600 // SIGINT for the browser process (and dumps you back to the gdb | 626 // SIGINT for the browser process (and dumps you back to the gdb |
| (...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 936 | 962 |
| 937 logging::CleanupChromeLogging(); | 963 logging::CleanupChromeLogging(); |
| 938 | 964 |
| 939 #if defined(OS_MACOSX) && defined(GOOGLE_CHROME_BUILD) | 965 #if defined(OS_MACOSX) && defined(GOOGLE_CHROME_BUILD) |
| 940 // TODO(mark): See the TODO(mark) above at InitCrashReporter. | 966 // TODO(mark): See the TODO(mark) above at InitCrashReporter. |
| 941 DestructCrashReporter(); | 967 DestructCrashReporter(); |
| 942 #endif // OS_MACOSX && GOOGLE_CHROME_BUILD | 968 #endif // OS_MACOSX && GOOGLE_CHROME_BUILD |
| 943 | 969 |
| 944 return rv; | 970 return rv; |
| 945 } | 971 } |
| OLD | NEW |