Index: chrome/common/child_process.cc |
diff --git a/chrome/common/child_process.cc b/chrome/common/child_process.cc |
index 328ca143772fea668da59b4a89c14b8a85511fa2..40b01962efb1b43ca7d2b3a98788ba21bc018bc7 100644 |
--- a/chrome/common/child_process.cc |
+++ b/chrome/common/child_process.cc |
@@ -17,6 +17,59 @@ |
static void SigUSR1Handler(int signal) { } |
#endif |
+#if defined(OS_MACOSX) |
+#include "ipc/ipc_switches.h" |
+#include "base/thread.h" |
+#include "chrome/common/mach_ipc_mac.h" |
+ |
+class MachSendTask : public Task { |
+ public: |
+ MachSendTask(const std::string& channel_name) : channel_name_(channel_name) {} |
+ |
+ virtual void Run() { |
+ // TODO(thakis): Put these somewhere central. |
+ const int kMachPortMessageID = 57; |
Mark Mentovai
2010/01/11 20:22:46
This line and the next are “duplicatious.” I know
|
+ const std::string kMachChannelPrefix = "com.Google.Chrome"; |
Mark Mentovai
2010/01/11 20:22:46
Same thing here applies about the dots.
|
+ |
+ const int kMachPortMessageSendWaitMs = 5000; |
+ std::string channel_name = kMachChannelPrefix + channel_name_; |
+printf("Creating send port %s\n", channel_name.c_str()); |
Mark Mentovai
2010/01/11 20:22:46
t’let
|
+ MachPortSender sender(channel_name.c_str()); |
+ MachSendMessage message(kMachPortMessageID); |
+ |
+ // add some ports to be translated for us |
Mark Mentovai
2010/01/11 20:22:46
Comments ought to be complete sentences with capit
|
+// message.AddDescriptor(MachMsgPortDescriptor(mach_task_self())); |
Mark Mentovai
2010/01/11 20:22:46
Huh?
|
+ message.AddDescriptor(MachMsgPortDescriptor(mach_task_self(), MACH_MSG_TYPE_COPY_SEND)); |
Mark Mentovai
2010/01/11 20:22:46
80
|
+ |
+ kern_return_t result = sender.SendMessage(message, |
+ kMachPortMessageSendWaitMs); |
+ |
+ // TODO(thakis): Log error somewhere? (don't printf in any case :-P) |
+ // (error codes are listed in mach/message.h) |
+ fprintf(stderr, "send result: 0x%lx\n", (unsigned long)result); |
Mark Mentovai
2010/01/11 20:22:46
Observe the TODO from 47, and don't printf in any
|
+ if (result != KERN_SUCCESS) |
+ fprintf(stderr, "(Failed :-( )\n"); |
+ } |
+ private: |
+ std::string channel_name_; |
+}; |
+ |
+class MachSendThread : public base::Thread { |
+ public: |
+ MachSendThread() : base::Thread("MachSendThread") {} |
+ |
+ void DoIt() { |
+ DCHECK(message_loop()); |
+ std::string name = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
+ switches::kProcessChannelID); |
+printf("main thread: %s\n", name.c_str()); |
+ message_loop()->PostTask( |
+ FROM_HERE, |
+ new MachSendTask(name)); |
+ } |
+}; |
+#endif |
+ |
ChildProcess* ChildProcess::child_process_; |
ChildProcess::ChildProcess() |
@@ -27,6 +80,14 @@ ChildProcess::ChildProcess() |
child_process_ = this; |
io_thread_.StartWithOptions(base::Thread::Options(MessageLoop::TYPE_IO, 0)); |
+ |
+#if defined(OS_MACOSX) |
+ { |
+ MachSendThread mach_thread; |
+ CHECK(mach_thread.Start()); |
+ mach_thread.DoIt(); |
+ } |
+#endif |
} |
ChildProcess::~ChildProcess() { |