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