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/child/child_thread.h" | 5 #include "content/child/child_thread.h" |
6 | 6 |
7 #include "base/allocator/allocator_extension.h" | 7 #include "base/allocator/allocator_extension.h" |
8 #include "base/base_switches.h" | 8 #include "base/base_switches.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
12 #include "base/process/kill.h" | 12 #include "base/process/kill.h" |
13 #include "base/process/process_handle.h" | 13 #include "base/process/process_handle.h" |
14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
15 #include "base/threading/thread_local.h" | 15 #include "base/threading/thread_local.h" |
16 #include "base/tracked_objects.h" | 16 #include "base/tracked_objects.h" |
17 #include "components/tracing/child_trace_message_filter.h" | 17 #include "components/tracing/child_trace_message_filter.h" |
18 #include "content/child/child_histogram_message_filter.h" | 18 #include "content/child/child_histogram_message_filter.h" |
19 #include "content/child/child_process.h" | 19 #include "content/child/child_process.h" |
20 #include "content/child/child_resource_message_filter.h" | 20 #include "content/child/child_resource_message_filter.h" |
21 #include "content/child/fileapi/file_system_dispatcher.h" | 21 #include "content/child/fileapi/file_system_dispatcher.h" |
22 #include "content/child/quota_dispatcher.h" | 22 #include "content/child/quota_dispatcher.h" |
| 23 #include "content/child/quota_message_filter.h" |
23 #include "content/child/resource_dispatcher.h" | 24 #include "content/child/resource_dispatcher.h" |
24 #include "content/child/socket_stream_dispatcher.h" | 25 #include "content/child/socket_stream_dispatcher.h" |
25 #include "content/child/thread_safe_sender.h" | 26 #include "content/child/thread_safe_sender.h" |
26 #include "content/common/child_process_messages.h" | 27 #include "content/common/child_process_messages.h" |
27 #include "content/public/common/content_switches.h" | 28 #include "content/public/common/content_switches.h" |
28 #include "ipc/ipc_logging.h" | 29 #include "ipc/ipc_logging.h" |
29 #include "ipc/ipc_switches.h" | 30 #include "ipc/ipc_switches.h" |
30 #include "ipc/ipc_sync_channel.h" | 31 #include "ipc/ipc_sync_channel.h" |
31 #include "ipc/ipc_sync_message_filter.h" | 32 #include "ipc/ipc_sync_message_filter.h" |
32 #include "webkit/glue/webkit_glue.h" | 33 #include "webkit/glue/webkit_glue.h" |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 new IPC::SyncChannel(channel_name_, | 123 new IPC::SyncChannel(channel_name_, |
123 IPC::Channel::MODE_CLIENT, | 124 IPC::Channel::MODE_CLIENT, |
124 this, | 125 this, |
125 ChildProcess::current()->io_message_loop_proxy(), | 126 ChildProcess::current()->io_message_loop_proxy(), |
126 true, | 127 true, |
127 ChildProcess::current()->GetShutDownEvent())); | 128 ChildProcess::current()->GetShutDownEvent())); |
128 #ifdef IPC_MESSAGE_LOG_ENABLED | 129 #ifdef IPC_MESSAGE_LOG_ENABLED |
129 IPC::Logging::GetInstance()->SetIPCSender(this); | 130 IPC::Logging::GetInstance()->SetIPCSender(this); |
130 #endif | 131 #endif |
131 | 132 |
132 resource_dispatcher_.reset(new ResourceDispatcher(this)); | |
133 socket_stream_dispatcher_.reset(new SocketStreamDispatcher()); | |
134 file_system_dispatcher_.reset(new FileSystemDispatcher()); | |
135 quota_dispatcher_.reset(new QuotaDispatcher()); | |
136 | |
137 sync_message_filter_ = | 133 sync_message_filter_ = |
138 new IPC::SyncMessageFilter(ChildProcess::current()->GetShutDownEvent()); | 134 new IPC::SyncMessageFilter(ChildProcess::current()->GetShutDownEvent()); |
139 thread_safe_sender_ = new ThreadSafeSender( | 135 thread_safe_sender_ = new ThreadSafeSender( |
140 base::MessageLoopProxy::current().get(), sync_message_filter_.get()); | 136 base::MessageLoopProxy::current().get(), sync_message_filter_.get()); |
| 137 |
| 138 resource_dispatcher_.reset(new ResourceDispatcher(this)); |
| 139 socket_stream_dispatcher_.reset(new SocketStreamDispatcher()); |
| 140 file_system_dispatcher_.reset(new FileSystemDispatcher()); |
| 141 |
141 histogram_message_filter_ = new ChildHistogramMessageFilter(); | 142 histogram_message_filter_ = new ChildHistogramMessageFilter(); |
142 resource_message_filter_ = | 143 resource_message_filter_ = |
143 new ChildResourceMessageFilter(resource_dispatcher()); | 144 new ChildResourceMessageFilter(resource_dispatcher()); |
144 | 145 |
| 146 quota_message_filter_ = |
| 147 new QuotaMessageFilter(thread_safe_sender_.get()); |
| 148 quota_dispatcher_.reset(new QuotaDispatcher(thread_safe_sender_.get(), |
| 149 quota_message_filter_.get())); |
| 150 |
145 channel_->AddFilter(histogram_message_filter_.get()); | 151 channel_->AddFilter(histogram_message_filter_.get()); |
146 channel_->AddFilter(sync_message_filter_.get()); | 152 channel_->AddFilter(sync_message_filter_.get()); |
147 channel_->AddFilter(new tracing::ChildTraceMessageFilter( | 153 channel_->AddFilter(new tracing::ChildTraceMessageFilter( |
148 ChildProcess::current()->io_message_loop_proxy())); | 154 ChildProcess::current()->io_message_loop_proxy())); |
149 channel_->AddFilter(resource_message_filter_.get()); | 155 channel_->AddFilter(resource_message_filter_.get()); |
| 156 channel_->AddFilter(quota_message_filter_.get()); |
150 | 157 |
151 #if defined(OS_POSIX) | 158 #if defined(OS_POSIX) |
152 // Check that --process-type is specified so we don't do this in unit tests | 159 // Check that --process-type is specified so we don't do this in unit tests |
153 // and single-process mode. | 160 // and single-process mode. |
154 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kProcessType)) | 161 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kProcessType)) |
155 channel_->AddFilter(new SuicideOnChannelErrorFilter()); | 162 channel_->AddFilter(new SuicideOnChannelErrorFilter()); |
156 #endif | 163 #endif |
157 | 164 |
158 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kTraceToConsole)) { | 165 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kTraceToConsole)) { |
159 std::string category_string = | 166 std::string category_string = |
(...skipping 25 matching lines...) Expand all Loading... |
185 ::HeapProfilerStop, | 192 ::HeapProfilerStop, |
186 ::GetHeapProfile)); | 193 ::GetHeapProfile)); |
187 #endif | 194 #endif |
188 } | 195 } |
189 | 196 |
190 ChildThread::~ChildThread() { | 197 ChildThread::~ChildThread() { |
191 #ifdef IPC_MESSAGE_LOG_ENABLED | 198 #ifdef IPC_MESSAGE_LOG_ENABLED |
192 IPC::Logging::GetInstance()->SetIPCSender(NULL); | 199 IPC::Logging::GetInstance()->SetIPCSender(NULL); |
193 #endif | 200 #endif |
194 | 201 |
| 202 channel_->RemoveFilter(quota_message_filter_.get()); |
195 channel_->RemoveFilter(histogram_message_filter_.get()); | 203 channel_->RemoveFilter(histogram_message_filter_.get()); |
196 channel_->RemoveFilter(sync_message_filter_.get()); | 204 channel_->RemoveFilter(sync_message_filter_.get()); |
197 | 205 |
198 // The ChannelProxy object caches a pointer to the IPC thread, so need to | 206 // The ChannelProxy object caches a pointer to the IPC thread, so need to |
199 // reset it as it's not guaranteed to outlive this object. | 207 // reset it as it's not guaranteed to outlive this object. |
200 // NOTE: this also has the side-effect of not closing the main IPC channel to | 208 // NOTE: this also has the side-effect of not closing the main IPC channel to |
201 // the browser process. This is needed because this is the signal that the | 209 // the browser process. This is needed because this is the signal that the |
202 // browser uses to know that this process has died, so we need it to be alive | 210 // browser uses to know that this process has died, so we need it to be alive |
203 // until this process is shut down, and the OS closes the handle | 211 // until this process is shut down, and the OS closes the handle |
204 // automatically. We used to watch the object handle on Windows to do this, | 212 // automatically. We used to watch the object handle on Windows to do this, |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 } | 297 } |
290 | 298 |
291 bool ChildThread::OnMessageReceived(const IPC::Message& msg) { | 299 bool ChildThread::OnMessageReceived(const IPC::Message& msg) { |
292 // Resource responses are sent to the resource dispatcher. | 300 // Resource responses are sent to the resource dispatcher. |
293 if (resource_dispatcher_->OnMessageReceived(msg)) | 301 if (resource_dispatcher_->OnMessageReceived(msg)) |
294 return true; | 302 return true; |
295 if (socket_stream_dispatcher_->OnMessageReceived(msg)) | 303 if (socket_stream_dispatcher_->OnMessageReceived(msg)) |
296 return true; | 304 return true; |
297 if (file_system_dispatcher_->OnMessageReceived(msg)) | 305 if (file_system_dispatcher_->OnMessageReceived(msg)) |
298 return true; | 306 return true; |
299 if (quota_dispatcher_->OnMessageReceived(msg)) | |
300 return true; | |
301 | 307 |
302 bool handled = true; | 308 bool handled = true; |
303 IPC_BEGIN_MESSAGE_MAP(ChildThread, msg) | 309 IPC_BEGIN_MESSAGE_MAP(ChildThread, msg) |
304 IPC_MESSAGE_HANDLER(ChildProcessMsg_Shutdown, OnShutdown) | 310 IPC_MESSAGE_HANDLER(ChildProcessMsg_Shutdown, OnShutdown) |
305 #if defined(IPC_MESSAGE_LOG_ENABLED) | 311 #if defined(IPC_MESSAGE_LOG_ENABLED) |
306 IPC_MESSAGE_HANDLER(ChildProcessMsg_SetIPCLoggingEnabled, | 312 IPC_MESSAGE_HANDLER(ChildProcessMsg_SetIPCLoggingEnabled, |
307 OnSetIPCLoggingEnabled) | 313 OnSetIPCLoggingEnabled) |
308 #endif | 314 #endif |
309 IPC_MESSAGE_HANDLER(ChildProcessMsg_SetProfilerStatus, | 315 IPC_MESSAGE_HANDLER(ChildProcessMsg_SetProfilerStatus, |
310 OnSetProfilerStatus) | 316 OnSetProfilerStatus) |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 // inflight that would addref it. | 412 // inflight that would addref it. |
407 Send(new ChildProcessHostMsg_ShutdownRequest); | 413 Send(new ChildProcessHostMsg_ShutdownRequest); |
408 } | 414 } |
409 | 415 |
410 void ChildThread::EnsureConnected() { | 416 void ChildThread::EnsureConnected() { |
411 LOG(INFO) << "ChildThread::EnsureConnected()"; | 417 LOG(INFO) << "ChildThread::EnsureConnected()"; |
412 base::KillProcess(base::GetCurrentProcessHandle(), 0, false); | 418 base::KillProcess(base::GetCurrentProcessHandle(), 0, false); |
413 } | 419 } |
414 | 420 |
415 } // namespace content | 421 } // namespace content |
OLD | NEW |