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 "content/browser/mach_broker_mac.h" | 5 #include "content/browser/mach_broker_mac.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/mac/foundation_util.h" | 9 #include "base/mac/foundation_util.h" |
10 #include "base/mach_ipc_mac.h" | 10 #include "base/mach_ipc_mac.h" |
11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
12 #include "base/stringprintf.h" | 12 #include "base/stringprintf.h" |
13 #include "base/sys_string_conversions.h" | 13 #include "base/sys_string_conversions.h" |
14 #include "base/threading/platform_thread.h" | 14 #include "base/threading/platform_thread.h" |
15 #include "content/browser/renderer_host/render_process_host.h" | 15 #include "content/browser/renderer_host/render_process_host_impl.h" |
16 #include "content/common/child_process_info.h" | 16 #include "content/common/child_process_info.h" |
17 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
18 #include "content/public/browser/notification_service.h" | 18 #include "content/public/browser/notification_service.h" |
19 #include "content/public/browser/notification_types.h" | 19 #include "content/public/browser/notification_types.h" |
20 #include "content/public/common/content_switches.h" | 20 #include "content/public/common/content_switches.h" |
21 | 21 |
22 using content::BrowserThread; | 22 using content::BrowserThread; |
23 | 23 |
24 namespace { | 24 namespace { |
25 // Prints a string representation of a Mach error code. | 25 // Prints a string representation of a Mach error code. |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 void MachBroker::Observe(int type, | 204 void MachBroker::Observe(int type, |
205 const content::NotificationSource& source, | 205 const content::NotificationSource& source, |
206 const content::NotificationDetails& details) { | 206 const content::NotificationDetails& details) { |
207 // TODO(rohitrao): These notifications do not always carry the proper PIDs, | 207 // TODO(rohitrao): These notifications do not always carry the proper PIDs, |
208 // especially when the renderer is already gone or has crashed. Find a better | 208 // especially when the renderer is already gone or has crashed. Find a better |
209 // way to listen for child process deaths. http://crbug.com/55734 | 209 // way to listen for child process deaths. http://crbug.com/55734 |
210 base::ProcessHandle handle = 0; | 210 base::ProcessHandle handle = 0; |
211 switch (type) { | 211 switch (type) { |
212 case content::NOTIFICATION_RENDERER_PROCESS_CLOSED: | 212 case content::NOTIFICATION_RENDERER_PROCESS_CLOSED: |
213 handle = | 213 handle = |
214 content::Details<RenderProcessHost::RendererClosedDetails>(details)-> | 214 content::Details<content::RenderProcessHost::RendererClosedDetails>( |
215 handle; | 215 details)->handle; |
216 break; | 216 break; |
217 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: | 217 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: |
218 handle = content::Source<RenderProcessHost>(source)->GetHandle(); | 218 handle = content::Source<content::RenderProcessHost>(source)-> |
| 219 GetHandle(); |
219 break; | 220 break; |
220 case content::NOTIFICATION_CHILD_PROCESS_CRASHED: | 221 case content::NOTIFICATION_CHILD_PROCESS_CRASHED: |
221 case content::NOTIFICATION_CHILD_PROCESS_HOST_DISCONNECTED: | 222 case content::NOTIFICATION_CHILD_PROCESS_HOST_DISCONNECTED: |
222 handle = content::Details<ChildProcessInfo>(details)->handle(); | 223 handle = content::Details<ChildProcessInfo>(details)->handle(); |
223 break; | 224 break; |
224 default: | 225 default: |
225 NOTREACHED() << "Unexpected notification"; | 226 NOTREACHED() << "Unexpected notification"; |
226 break; | 227 break; |
227 } | 228 } |
228 InvalidatePid(handle); | 229 InvalidatePid(handle); |
229 } | 230 } |
230 | 231 |
231 // static | 232 // static |
232 std::string MachBroker::GetMachPortName() { | 233 std::string MachBroker::GetMachPortName() { |
233 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 234 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
234 const bool is_child = command_line->HasSwitch(switches::kProcessType); | 235 const bool is_child = command_line->HasSwitch(switches::kProcessType); |
235 | 236 |
236 // In non-browser (child) processes, use the parent's pid. | 237 // In non-browser (child) processes, use the parent's pid. |
237 const pid_t pid = is_child ? getppid() : getpid(); | 238 const pid_t pid = is_child ? getppid() : getpid(); |
238 return base::StringPrintf("%s.rohitfork.%d", base::mac::BaseBundleID(), pid); | 239 return base::StringPrintf("%s.rohitfork.%d", base::mac::BaseBundleID(), pid); |
239 } | 240 } |
OLD | NEW |