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/common/child_thread.h" | 5 #include "content/common/child_thread.h" |
6 | 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" |
| 9 #include "base/json/json_writer.h" |
7 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| 11 #include "base/process.h" |
| 12 #include "base/process_util.h" |
8 #include "base/string_util.h" | 13 #include "base/string_util.h" |
9 #include "base/command_line.h" | 14 #include "base/tracked_objects.h" |
10 #include "content/common/child_process.h" | 15 #include "content/common/child_process.h" |
11 #include "content/common/child_process_messages.h" | 16 #include "content/common/child_process_messages.h" |
12 #include "content/common/child_trace_message_filter.h" | 17 #include "content/common/child_trace_message_filter.h" |
13 #include "content/common/file_system/file_system_dispatcher.h" | 18 #include "content/common/file_system/file_system_dispatcher.h" |
14 #include "content/common/quota_dispatcher.h" | 19 #include "content/common/quota_dispatcher.h" |
15 #include "content/common/resource_dispatcher.h" | 20 #include "content/common/resource_dispatcher.h" |
16 #include "content/common/socket_stream_dispatcher.h" | 21 #include "content/common/socket_stream_dispatcher.h" |
17 #include "content/public/common/content_switches.h" | 22 #include "content/public/common/content_switches.h" |
18 #include "ipc/ipc_logging.h" | 23 #include "ipc/ipc_logging.h" |
19 #include "ipc/ipc_sync_channel.h" | 24 #include "ipc/ipc_sync_channel.h" |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 return true; | 181 return true; |
177 | 182 |
178 bool handled = true; | 183 bool handled = true; |
179 IPC_BEGIN_MESSAGE_MAP(ChildThread, msg) | 184 IPC_BEGIN_MESSAGE_MAP(ChildThread, msg) |
180 IPC_MESSAGE_HANDLER(ChildProcessMsg_AskBeforeShutdown, OnAskBeforeShutdown) | 185 IPC_MESSAGE_HANDLER(ChildProcessMsg_AskBeforeShutdown, OnAskBeforeShutdown) |
181 IPC_MESSAGE_HANDLER(ChildProcessMsg_Shutdown, OnShutdown) | 186 IPC_MESSAGE_HANDLER(ChildProcessMsg_Shutdown, OnShutdown) |
182 #if defined(IPC_MESSAGE_LOG_ENABLED) | 187 #if defined(IPC_MESSAGE_LOG_ENABLED) |
183 IPC_MESSAGE_HANDLER(ChildProcessMsg_SetIPCLoggingEnabled, | 188 IPC_MESSAGE_HANDLER(ChildProcessMsg_SetIPCLoggingEnabled, |
184 OnSetIPCLoggingEnabled) | 189 OnSetIPCLoggingEnabled) |
185 #endif | 190 #endif |
| 191 IPC_MESSAGE_HANDLER(ChildProcessMsg_SetProfilerStatus, |
| 192 OnSetProfilerStatus) |
| 193 IPC_MESSAGE_HANDLER(ChildProcessMsg_GetChildProfilerData, |
| 194 OnGetChildProfilerData) |
186 IPC_MESSAGE_HANDLER(ChildProcessMsg_DumpHandles, OnDumpHandles) | 195 IPC_MESSAGE_HANDLER(ChildProcessMsg_DumpHandles, OnDumpHandles) |
187 IPC_MESSAGE_UNHANDLED(handled = false) | 196 IPC_MESSAGE_UNHANDLED(handled = false) |
188 IPC_END_MESSAGE_MAP() | 197 IPC_END_MESSAGE_MAP() |
189 | 198 |
190 if (handled) | 199 if (handled) |
191 return true; | 200 return true; |
192 | 201 |
193 if (msg.routing_id() == MSG_ROUTING_CONTROL) | 202 if (msg.routing_id() == MSG_ROUTING_CONTROL) |
194 return OnControlMessageReceived(msg); | 203 return OnControlMessageReceived(msg); |
195 | 204 |
(...skipping 14 matching lines...) Expand all Loading... |
210 | 219 |
211 #if defined(IPC_MESSAGE_LOG_ENABLED) | 220 #if defined(IPC_MESSAGE_LOG_ENABLED) |
212 void ChildThread::OnSetIPCLoggingEnabled(bool enable) { | 221 void ChildThread::OnSetIPCLoggingEnabled(bool enable) { |
213 if (enable) | 222 if (enable) |
214 IPC::Logging::GetInstance()->Enable(); | 223 IPC::Logging::GetInstance()->Enable(); |
215 else | 224 else |
216 IPC::Logging::GetInstance()->Disable(); | 225 IPC::Logging::GetInstance()->Disable(); |
217 } | 226 } |
218 #endif // IPC_MESSAGE_LOG_ENABLED | 227 #endif // IPC_MESSAGE_LOG_ENABLED |
219 | 228 |
| 229 void ChildThread::OnSetProfilerStatus(bool enable) { |
| 230 tracked_objects::ThreadData::InitializeAndSetTrackingStatus(enable); |
| 231 } |
| 232 |
| 233 void ChildThread::OnGetChildProfilerData( |
| 234 int sequence_number, |
| 235 const std::string& process_type) { |
| 236 scoped_ptr<base::DictionaryValue> value( |
| 237 tracked_objects::ThreadData::ToValue()); |
| 238 value->SetString("process_type", process_type); |
| 239 value->SetInteger("process_id", base::GetCurrentProcId()); |
| 240 |
| 241 std::string pickled_profiler_data; |
| 242 base::JSONWriter::Write(value.get(), false, &pickled_profiler_data); |
| 243 |
| 244 Send(new ChildProcessHostMsg_ChildProfilerData( |
| 245 sequence_number, pickled_profiler_data)); |
| 246 } |
| 247 |
220 void ChildThread::OnDumpHandles() { | 248 void ChildThread::OnDumpHandles() { |
221 #if defined(OS_WIN) | 249 #if defined(OS_WIN) |
222 scoped_refptr<content::HandleEnumerator> handle_enum( | 250 scoped_refptr<content::HandleEnumerator> handle_enum( |
223 new content::HandleEnumerator( | 251 new content::HandleEnumerator( |
224 CommandLine::ForCurrentProcess()->HasSwitch( | 252 CommandLine::ForCurrentProcess()->HasSwitch( |
225 switches::kAuditAllHandles))); | 253 switches::kAuditAllHandles))); |
226 handle_enum->EnumerateHandles(); | 254 handle_enum->EnumerateHandles(); |
227 Send(new ChildProcessHostMsg_DumpHandlesDone); | 255 Send(new ChildProcessHostMsg_DumpHandlesDone); |
228 return; | 256 return; |
229 #endif | 257 #endif |
(...skipping 10 matching lines...) Expand all Loading... |
240 MessageLoop::current()->Quit(); | 268 MessageLoop::current()->Quit(); |
241 return; | 269 return; |
242 } | 270 } |
243 | 271 |
244 // The child process shutdown sequence is a request response based mechanism, | 272 // The child process shutdown sequence is a request response based mechanism, |
245 // where we send out an initial feeler request to the child process host | 273 // where we send out an initial feeler request to the child process host |
246 // instance in the browser to verify if it's ok to shutdown the child process. | 274 // instance in the browser to verify if it's ok to shutdown the child process. |
247 // The browser then sends back a response if it's ok to shutdown. | 275 // The browser then sends back a response if it's ok to shutdown. |
248 Send(new ChildProcessHostMsg_ShutdownRequest); | 276 Send(new ChildProcessHostMsg_ShutdownRequest); |
249 } | 277 } |
OLD | NEW |