diff options
Diffstat (limited to 'chrome/app/chrome_dll_main.cc')
-rw-r--r-- | chrome/app/chrome_dll_main.cc | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/chrome/app/chrome_dll_main.cc b/chrome/app/chrome_dll_main.cc index 68e8048..70dacf7 100644 --- a/chrome/app/chrome_dll_main.cc +++ b/chrome/app/chrome_dll_main.cc @@ -80,8 +80,10 @@ #if defined(OS_MACOSX) #include "app/l10n_util_mac.h" #include "base/mac_util.h" -#include "chrome/common/chrome_paths_internal.h" +#include "base/mach_ipc_mac.h" #include "chrome/app/breakpad_mac.h" +#include "chrome/browser/mach_broker_mac.h" +#include "chrome/common/chrome_paths_internal.h" #include "grit/chromium_strings.h" #include "third_party/WebKit/WebKit/mac/WebCoreSupport/WebSystemInterface.h" #endif @@ -409,6 +411,29 @@ void SetMacProcessName(const std::string& process_type) { mac_util::SetProcessName(reinterpret_cast<CFStringRef>(app_name)); } } + +// Completes the Mach IPC handshake by sending this process' task port to the +// parent process. The parent is listening on the Mach port given by +// |GetMachPortName()|. The task port is used by the parent to get CPU/memory +// stats to display in the task manager. +void SendTaskPortToParentProcess() { + const mach_msg_timeout_t kTimeoutMs = 100; + const int32_t kMessageId = 0; + std::string mach_port_name = MachBroker::GetMachPortName(); + + base::MachSendMessage child_message(kMessageId); + if (!child_message.AddDescriptor(mach_task_self())) { + LOG(ERROR) << "child AddDescriptor(mach_task_self()) failed."; + return; + } + + base::MachPortSender child_sender(mach_port_name.c_str()); + kern_return_t err = child_sender.SendMessage(child_message, kTimeoutMs); + if (err != KERN_SUCCESS) { + LOG(ERROR) << StringPrintf("child SendMessage() failed: 0x%x %s", err, + mach_error_string(err)); + } +} #endif // defined(OS_MACOSX) void InitializeStatsTable(base::ProcessId browser_pid, @@ -588,6 +613,7 @@ int ChromeMain(int argc, char** argv) { DCHECK_NE(browser_pid, 0u); #elif defined(OS_MACOSX) browser_pid = base::GetCurrentProcId(); + SendTaskPortToParentProcess(); #elif defined(OS_POSIX) // On linux, we're in the zygote here; so we need the parent process' id. browser_pid = base::GetParentProcessId(base::GetCurrentProcId()); |