OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/common/child_thread.h" | 5 #include "content/common/child_thread.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/process.h" | 9 #include "base/process.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
11 #include "base/tracked_objects.h" | 11 #include "base/tracked_objects.h" |
12 #include "content/common/child_process.h" | 12 #include "content/common/child_process.h" |
13 #include "content/common/child_process_messages.h" | 13 #include "content/common/child_process_messages.h" |
14 #include "content/common/child_trace_message_filter.h" | 14 #include "content/common/child_trace_message_filter.h" |
15 #include "content/common/fileapi/file_system_dispatcher.h" | 15 #include "content/common/fileapi/file_system_dispatcher.h" |
16 #include "content/common/quota_dispatcher.h" | 16 #include "content/common/quota_dispatcher.h" |
17 #include "content/common/resource_dispatcher.h" | 17 #include "content/common/resource_dispatcher.h" |
18 #include "content/common/socket_stream_dispatcher.h" | 18 #include "content/common/socket_stream_dispatcher.h" |
19 #include "content/public/common/content_switches.h" | 19 #include "content/public/common/content_switches.h" |
20 #include "ipc/ipc_logging.h" | 20 #include "ipc/ipc_logging.h" |
21 #include "ipc/ipc_switches.h" | 21 #include "ipc/ipc_switches.h" |
22 #include "ipc/ipc_sync_channel.h" | 22 #include "ipc/ipc_sync_channel.h" |
23 #include "ipc/ipc_sync_message_filter.h" | 23 #include "ipc/ipc_sync_message_filter.h" |
24 #include "webkit/glue/webkit_glue.h" | 24 #include "webkit/glue/webkit_glue.h" |
25 | 25 |
26 #if defined(OS_WIN) | 26 #if defined(OS_WIN) |
27 #include "content/common/handle_enumerator_win.h" | 27 #include "content/common/handle_enumerator_win.h" |
28 #endif | 28 #endif |
29 | 29 |
30 #if defined(USE_TCMALLOC) | |
31 #include "third_party/tcmalloc/chromium/src/gperftools/malloc_extension.h" | |
32 #endif | |
33 | |
30 using tracked_objects::ThreadData; | 34 using tracked_objects::ThreadData; |
31 | 35 |
32 ChildThread::ChildThread() { | 36 ChildThread::ChildThread() { |
33 channel_name_ = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 37 channel_name_ = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
34 switches::kProcessChannelID); | 38 switches::kProcessChannelID); |
35 Init(); | 39 Init(); |
36 } | 40 } |
37 | 41 |
38 ChildThread::ChildThread(const std::string& channel_name) | 42 ChildThread::ChildThread(const std::string& channel_name) |
39 : channel_name_(channel_name) { | 43 : channel_name_(channel_name) { |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
184 IPC_MESSAGE_HANDLER(ChildProcessMsg_Shutdown, OnShutdown) | 188 IPC_MESSAGE_HANDLER(ChildProcessMsg_Shutdown, OnShutdown) |
185 #if defined(IPC_MESSAGE_LOG_ENABLED) | 189 #if defined(IPC_MESSAGE_LOG_ENABLED) |
186 IPC_MESSAGE_HANDLER(ChildProcessMsg_SetIPCLoggingEnabled, | 190 IPC_MESSAGE_HANDLER(ChildProcessMsg_SetIPCLoggingEnabled, |
187 OnSetIPCLoggingEnabled) | 191 OnSetIPCLoggingEnabled) |
188 #endif | 192 #endif |
189 IPC_MESSAGE_HANDLER(ChildProcessMsg_SetProfilerStatus, | 193 IPC_MESSAGE_HANDLER(ChildProcessMsg_SetProfilerStatus, |
190 OnSetProfilerStatus) | 194 OnSetProfilerStatus) |
191 IPC_MESSAGE_HANDLER(ChildProcessMsg_GetChildProfilerData, | 195 IPC_MESSAGE_HANDLER(ChildProcessMsg_GetChildProfilerData, |
192 OnGetChildProfilerData) | 196 OnGetChildProfilerData) |
193 IPC_MESSAGE_HANDLER(ChildProcessMsg_DumpHandles, OnDumpHandles) | 197 IPC_MESSAGE_HANDLER(ChildProcessMsg_DumpHandles, OnDumpHandles) |
198 #if defined(USE_TCMALLOC) | |
199 IPC_MESSAGE_HANDLER(ChildProcessMsg_GetTcmallocStats, OnGetTcmallocStats) | |
200 #endif | |
194 IPC_MESSAGE_UNHANDLED(handled = false) | 201 IPC_MESSAGE_UNHANDLED(handled = false) |
195 IPC_END_MESSAGE_MAP() | 202 IPC_END_MESSAGE_MAP() |
196 | 203 |
197 if (handled) | 204 if (handled) |
198 return true; | 205 return true; |
199 | 206 |
200 if (msg.routing_id() == MSG_ROUTING_CONTROL) | 207 if (msg.routing_id() == MSG_ROUTING_CONTROL) |
201 return OnControlMessageReceived(msg); | 208 return OnControlMessageReceived(msg); |
202 | 209 |
203 return router_.OnMessageReceived(msg); | 210 return router_.OnMessageReceived(msg); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
239 CommandLine::ForCurrentProcess()->HasSwitch( | 246 CommandLine::ForCurrentProcess()->HasSwitch( |
240 switches::kAuditAllHandles))); | 247 switches::kAuditAllHandles))); |
241 handle_enum->EnumerateHandles(); | 248 handle_enum->EnumerateHandles(); |
242 Send(new ChildProcessHostMsg_DumpHandlesDone); | 249 Send(new ChildProcessHostMsg_DumpHandlesDone); |
243 return; | 250 return; |
244 #endif | 251 #endif |
245 | 252 |
246 NOTIMPLEMENTED(); | 253 NOTIMPLEMENTED(); |
247 } | 254 } |
248 | 255 |
256 #if defined(USE_TCMALLOC) | |
257 void ChildThread::OnGetTcmallocStats() | |
258 { | |
jam
2012/04/24 20:14:08
nit: on previous line
| |
259 std::string result; | |
260 char buffer[1024 * 32]; | |
261 MallocExtension::instance()->GetStats(buffer, sizeof(buffer)); | |
262 result.append(buffer); | |
263 Send(new ChildProcessHostMsg_TcmallocStats(result)); | |
264 } | |
265 #endif | |
266 | |
249 ChildThread* ChildThread::current() { | 267 ChildThread* ChildThread::current() { |
250 return ChildProcess::current()->main_thread(); | 268 return ChildProcess::current()->main_thread(); |
251 } | 269 } |
252 | 270 |
253 bool ChildThread::IsWebFrameValid(WebKit::WebFrame* frame) { | 271 bool ChildThread::IsWebFrameValid(WebKit::WebFrame* frame) { |
254 // Return false so that it is overridden in any process in which it is used. | 272 // Return false so that it is overridden in any process in which it is used. |
255 return false; | 273 return false; |
256 } | 274 } |
257 | 275 |
258 void ChildThread::OnProcessFinalRelease() { | 276 void ChildThread::OnProcessFinalRelease() { |
259 if (on_channel_error_called_) { | 277 if (on_channel_error_called_) { |
260 MessageLoop::current()->Quit(); | 278 MessageLoop::current()->Quit(); |
261 return; | 279 return; |
262 } | 280 } |
263 | 281 |
264 // The child process shutdown sequence is a request response based mechanism, | 282 // The child process shutdown sequence is a request response based mechanism, |
265 // where we send out an initial feeler request to the child process host | 283 // where we send out an initial feeler request to the child process host |
266 // instance in the browser to verify if it's ok to shutdown the child process. | 284 // instance in the browser to verify if it's ok to shutdown the child process. |
267 // The browser then sends back a response if it's ok to shutdown. This avoids | 285 // The browser then sends back a response if it's ok to shutdown. This avoids |
268 // race conditions if the process refcount is 0 but there's an IPC message | 286 // race conditions if the process refcount is 0 but there's an IPC message |
269 // inflight that would addref it. | 287 // inflight that would addref it. |
270 Send(new ChildProcessHostMsg_ShutdownRequest); | 288 Send(new ChildProcessHostMsg_ShutdownRequest); |
271 } | 289 } |
OLD | NEW |