OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "chrome/common/child_thread.h" | 5 #include "chrome/common/child_thread.h" |
6 | 6 |
7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "chrome/common/child_process.h" | 9 #include "chrome/common/child_process.h" |
10 #include "chrome/common/chrome_switches.h" | 10 #include "chrome/common/chrome_switches.h" |
11 #include "chrome/common/notification_service.h" | 11 #include "chrome/common/notification_service.h" |
12 #include "chrome/common/plugin_messages.h" | 12 #include "chrome/common/plugin_messages.h" |
13 #include "chrome/common/socket_stream_dispatcher.h" | 13 #include "chrome/common/socket_stream_dispatcher.h" |
14 #include "ipc/ipc_logging.h" | 14 #include "ipc/ipc_logging.h" |
15 #include "ipc/ipc_message.h" | 15 #include "ipc/ipc_message.h" |
| 16 #include "ipc/ipc_sync_message_filter.h" |
16 #include "ipc/ipc_switches.h" | 17 #include "ipc/ipc_switches.h" |
17 #include "webkit/glue/webkit_glue.h" | 18 #include "webkit/glue/webkit_glue.h" |
18 | 19 |
19 | 20 |
20 ChildThread::ChildThread() { | 21 ChildThread::ChildThread() { |
21 channel_name_ = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 22 channel_name_ = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
22 switches::kProcessChannelID); | 23 switches::kProcessChannelID); |
23 Init(); | 24 Init(); |
24 } | 25 } |
25 | 26 |
(...skipping 16 matching lines...) Expand all Loading... |
42 IPC::Channel::MODE_CLIENT, this, NULL, | 43 IPC::Channel::MODE_CLIENT, this, NULL, |
43 ChildProcess::current()->io_message_loop(), true, | 44 ChildProcess::current()->io_message_loop(), true, |
44 ChildProcess::current()->GetShutDownEvent())); | 45 ChildProcess::current()->GetShutDownEvent())); |
45 #ifdef IPC_MESSAGE_LOG_ENABLED | 46 #ifdef IPC_MESSAGE_LOG_ENABLED |
46 IPC::Logging::current()->SetIPCSender(this); | 47 IPC::Logging::current()->SetIPCSender(this); |
47 #endif | 48 #endif |
48 | 49 |
49 resource_dispatcher_.reset(new ResourceDispatcher(this)); | 50 resource_dispatcher_.reset(new ResourceDispatcher(this)); |
50 socket_stream_dispatcher_.reset(new SocketStreamDispatcher()); | 51 socket_stream_dispatcher_.reset(new SocketStreamDispatcher()); |
51 | 52 |
| 53 sync_message_filter_ = |
| 54 new IPC::SyncMessageFilter(ChildProcess::current()->GetShutDownEvent()); |
| 55 channel_->AddFilter(sync_message_filter_.get()); |
| 56 |
52 // When running in unit tests, there is already a NotificationService object. | 57 // When running in unit tests, there is already a NotificationService object. |
53 // Since only one can exist at a time per thread, check first. | 58 // Since only one can exist at a time per thread, check first. |
54 if (!NotificationService::current()) | 59 if (!NotificationService::current()) |
55 notification_service_.reset(new NotificationService); | 60 notification_service_.reset(new NotificationService); |
56 } | 61 } |
57 | 62 |
58 ChildThread::~ChildThread() { | 63 ChildThread::~ChildThread() { |
59 #ifdef IPC_MESSAGE_LOG_ENABLED | 64 #ifdef IPC_MESSAGE_LOG_ENABLED |
60 IPC::Logging::current()->SetIPCSender(NULL); | 65 IPC::Logging::current()->SetIPCSender(NULL); |
61 #endif | 66 #endif |
62 | 67 |
| 68 channel_->RemoveFilter(sync_message_filter_.get()); |
| 69 |
63 // The ChannelProxy object caches a pointer to the IPC thread, so need to | 70 // The ChannelProxy object caches a pointer to the IPC thread, so need to |
64 // reset it as it's not guaranteed to outlive this object. | 71 // reset it as it's not guaranteed to outlive this object. |
65 // NOTE: this also has the side-effect of not closing the main IPC channel to | 72 // NOTE: this also has the side-effect of not closing the main IPC channel to |
66 // the browser process. This is needed because this is the signal that the | 73 // the browser process. This is needed because this is the signal that the |
67 // browser uses to know that this process has died, so we need it to be alive | 74 // browser uses to know that this process has died, so we need it to be alive |
68 // until this process is shut down, and the OS closes the handle | 75 // until this process is shut down, and the OS closes the handle |
69 // automatically. We used to watch the object handle on Windows to do this, | 76 // automatically. We used to watch the object handle on Windows to do this, |
70 // but it wasn't possible to do so on POSIX. | 77 // but it wasn't possible to do so on POSIX. |
71 channel_->ClearIPCMessageLoop(); | 78 channel_->ClearIPCMessageLoop(); |
72 } | 79 } |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 if (socket_stream_dispatcher_->OnMessageReceived(msg)) | 126 if (socket_stream_dispatcher_->OnMessageReceived(msg)) |
120 return; | 127 return; |
121 | 128 |
122 bool handled = true; | 129 bool handled = true; |
123 IPC_BEGIN_MESSAGE_MAP(ChildThread, msg) | 130 IPC_BEGIN_MESSAGE_MAP(ChildThread, msg) |
124 IPC_MESSAGE_HANDLER(PluginProcessMsg_AskBeforeShutdown, OnAskBeforeShutdown) | 131 IPC_MESSAGE_HANDLER(PluginProcessMsg_AskBeforeShutdown, OnAskBeforeShutdown) |
125 IPC_MESSAGE_HANDLER(PluginProcessMsg_Shutdown, OnShutdown) | 132 IPC_MESSAGE_HANDLER(PluginProcessMsg_Shutdown, OnShutdown) |
126 #if defined(IPC_MESSAGE_LOG_ENABLED) | 133 #if defined(IPC_MESSAGE_LOG_ENABLED) |
127 IPC_MESSAGE_HANDLER(PluginProcessMsg_SetIPCLoggingEnabled, | 134 IPC_MESSAGE_HANDLER(PluginProcessMsg_SetIPCLoggingEnabled, |
128 OnSetIPCLoggingEnabled) | 135 OnSetIPCLoggingEnabled) |
129 #endif // IPC_MESSAGE_HANDLER | 136 #endif |
130 IPC_MESSAGE_UNHANDLED(handled = false) | 137 IPC_MESSAGE_UNHANDLED(handled = false) |
131 IPC_END_MESSAGE_MAP() | 138 IPC_END_MESSAGE_MAP() |
132 | 139 |
133 if (handled) | 140 if (handled) |
134 return; | 141 return; |
135 | 142 |
136 if (msg.routing_id() == MSG_ROUTING_CONTROL) { | 143 if (msg.routing_id() == MSG_ROUTING_CONTROL) { |
137 OnControlMessageReceived(msg); | 144 OnControlMessageReceived(msg); |
138 } else { | 145 } else { |
139 router_.OnMessageReceived(msg); | 146 router_.OnMessageReceived(msg); |
(...skipping 26 matching lines...) Expand all Loading... |
166 MessageLoop::current()->Quit(); | 173 MessageLoop::current()->Quit(); |
167 return; | 174 return; |
168 } | 175 } |
169 | 176 |
170 // The child process shutdown sequence is a request response based mechanism, | 177 // The child process shutdown sequence is a request response based mechanism, |
171 // where we send out an initial feeler request to the child process host | 178 // where we send out an initial feeler request to the child process host |
172 // instance in the browser to verify if it's ok to shutdown the child process. | 179 // instance in the browser to verify if it's ok to shutdown the child process. |
173 // The browser then sends back a response if it's ok to shutdown. | 180 // The browser then sends back a response if it's ok to shutdown. |
174 Send(new PluginProcessHostMsg_ShutdownRequest); | 181 Send(new PluginProcessHostMsg_ShutdownRequest); |
175 } | 182 } |
OLD | NEW |