OLD | NEW |
---|---|
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/common/child_process.h" | 5 #include "chrome/common/child_process.h" |
6 | 6 |
7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/process_util.h" | 9 #include "base/process_util.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
11 #include "chrome/common/child_thread.h" | 11 #include "chrome/common/child_thread.h" |
12 #include "grit/chromium_strings.h" | 12 #include "grit/chromium_strings.h" |
13 | 13 |
14 #if defined(OS_POSIX) | 14 #if defined(OS_POSIX) |
15 #include <signal.h> | 15 #include <signal.h> |
16 | 16 |
17 static void SigUSR1Handler(int signal) { } | 17 static void SigUSR1Handler(int signal) { } |
18 #endif | 18 #endif |
19 | 19 |
20 #if defined(OS_MACOSX) | |
21 #include "ipc/ipc_switches.h" | |
22 #include "base/thread.h" | |
23 #include "chrome/common/mach_ipc_mac.h" | |
24 | |
25 class MachSendTask : public Task { | |
26 public: | |
27 MachSendTask(const std::string& channel_name) : channel_name_(channel_name) {} | |
28 | |
29 virtual void Run() { | |
30 // TODO(thakis): Put these somewhere central. | |
31 const int kMachPortMessageID = 57; | |
Mark Mentovai
2010/01/11 20:22:46
This line and the next are “duplicatious.” I know
| |
32 const std::string kMachChannelPrefix = "com.Google.Chrome"; | |
Mark Mentovai
2010/01/11 20:22:46
Same thing here applies about the dots.
| |
33 | |
34 const int kMachPortMessageSendWaitMs = 5000; | |
35 std::string channel_name = kMachChannelPrefix + channel_name_; | |
36 printf("Creating send port %s\n", channel_name.c_str()); | |
Mark Mentovai
2010/01/11 20:22:46
t’let
| |
37 MachPortSender sender(channel_name.c_str()); | |
38 MachSendMessage message(kMachPortMessageID); | |
39 | |
40 // add some ports to be translated for us | |
Mark Mentovai
2010/01/11 20:22:46
Comments ought to be complete sentences with capit
| |
41 // message.AddDescriptor(MachMsgPortDescriptor(mach_task_self())); | |
Mark Mentovai
2010/01/11 20:22:46
Huh?
| |
42 message.AddDescriptor(MachMsgPortDescriptor(mach_task_self(), MACH_MSG_TYPE_ COPY_SEND)); | |
Mark Mentovai
2010/01/11 20:22:46
80
| |
43 | |
44 kern_return_t result = sender.SendMessage(message, | |
45 kMachPortMessageSendWaitMs); | |
46 | |
47 // TODO(thakis): Log error somewhere? (don't printf in any case :-P) | |
48 // (error codes are listed in mach/message.h) | |
49 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
| |
50 if (result != KERN_SUCCESS) | |
51 fprintf(stderr, "(Failed :-( )\n"); | |
52 } | |
53 private: | |
54 std::string channel_name_; | |
55 }; | |
56 | |
57 class MachSendThread : public base::Thread { | |
58 public: | |
59 MachSendThread() : base::Thread("MachSendThread") {} | |
60 | |
61 void DoIt() { | |
62 DCHECK(message_loop()); | |
63 std::string name = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | |
64 switches::kProcessChannelID); | |
65 printf("main thread: %s\n", name.c_str()); | |
66 message_loop()->PostTask( | |
67 FROM_HERE, | |
68 new MachSendTask(name)); | |
69 } | |
70 }; | |
71 #endif | |
72 | |
20 ChildProcess* ChildProcess::child_process_; | 73 ChildProcess* ChildProcess::child_process_; |
21 | 74 |
22 ChildProcess::ChildProcess() | 75 ChildProcess::ChildProcess() |
23 : ref_count_(0), | 76 : ref_count_(0), |
24 shutdown_event_(true, false), | 77 shutdown_event_(true, false), |
25 io_thread_("Chrome_ChildIOThread") { | 78 io_thread_("Chrome_ChildIOThread") { |
26 DCHECK(!child_process_); | 79 DCHECK(!child_process_); |
27 child_process_ = this; | 80 child_process_ = this; |
28 | 81 |
29 io_thread_.StartWithOptions(base::Thread::Options(MessageLoop::TYPE_IO, 0)); | 82 io_thread_.StartWithOptions(base::Thread::Options(MessageLoop::TYPE_IO, 0)); |
83 | |
84 #if defined(OS_MACOSX) | |
85 { | |
86 MachSendThread mach_thread; | |
87 CHECK(mach_thread.Start()); | |
88 mach_thread.DoIt(); | |
89 } | |
90 #endif | |
30 } | 91 } |
31 | 92 |
32 ChildProcess::~ChildProcess() { | 93 ChildProcess::~ChildProcess() { |
33 DCHECK(child_process_ == this); | 94 DCHECK(child_process_ == this); |
34 | 95 |
35 // Signal this event before destroying the child process. That way all | 96 // Signal this event before destroying the child process. That way all |
36 // background threads can cleanup. | 97 // background threads can cleanup. |
37 // For example, in the renderer the RenderThread instances will be able to | 98 // For example, in the renderer the RenderThread instances will be able to |
38 // notice shutdown before the render process begins waiting for them to exit. | 99 // notice shutdown before the render process begins waiting for them to exit. |
39 shutdown_event_.Signal(); | 100 shutdown_event_.Signal(); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
88 << ") paused waiting for debugger to attach @ pid"; | 149 << ") paused waiting for debugger to attach @ pid"; |
89 // Install a signal handler so that pause can be woken. | 150 // Install a signal handler so that pause can be woken. |
90 struct sigaction sa; | 151 struct sigaction sa; |
91 memset(&sa, 0, sizeof(sa)); | 152 memset(&sa, 0, sizeof(sa)); |
92 sa.sa_handler = SigUSR1Handler; | 153 sa.sa_handler = SigUSR1Handler; |
93 sigaction(SIGUSR1, &sa, NULL); | 154 sigaction(SIGUSR1, &sa, NULL); |
94 | 155 |
95 pause(); | 156 pause(); |
96 #endif // defined(OS_POSIX) | 157 #endif // defined(OS_POSIX) |
97 } | 158 } |
OLD | NEW |