OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "base/message_loop.h" | 5 #include "base/message_loop.h" |
6 #include "base/thread.h" | 6 #include "base/thread.h" |
7 #include "chrome/common/ipc_channel_proxy.h" | 7 #include "chrome/common/ipc_channel_proxy.h" |
8 #include "chrome/common/ipc_logging.h" | 8 #include "chrome/common/ipc_logging.h" |
9 #include "chrome/common/ipc_message_utils.h" | 9 #include "chrome/common/ipc_message_utils.h" |
10 | 10 |
11 namespace IPC { | 11 namespace IPC { |
12 | 12 |
13 //----------------------------------------------------------------------------- | 13 //----------------------------------------------------------------------------- |
14 | 14 |
15 ChannelProxy::Context::Context(Channel::Listener* listener, | 15 ChannelProxy::Context::Context(Channel::Listener* listener, |
16 MessageFilter* filter, | 16 MessageFilter* filter, |
17 MessageLoop* ipc_message_loop) | 17 MessageLoop* ipc_message_loop) |
18 : listener_message_loop_(MessageLoop::current()), | 18 : listener_message_loop_(MessageLoop::current()), |
19 listener_(listener), | 19 listener_(listener), |
20 ipc_message_loop_(ipc_message_loop), | 20 ipc_message_loop_(ipc_message_loop), |
21 channel_(NULL) { | 21 channel_(NULL), |
| 22 peer_pid_(0), |
| 23 channel_connected_called_(false) { |
22 if (filter) | 24 if (filter) |
23 filters_.push_back(filter); | 25 filters_.push_back(filter); |
24 } | 26 } |
25 | 27 |
26 void ChannelProxy::Context::CreateChannel(const std::wstring& id, | 28 void ChannelProxy::Context::CreateChannel(const std::wstring& id, |
27 const Channel::Mode& mode) { | 29 const Channel::Mode& mode) { |
28 DCHECK(channel_ == NULL); | 30 DCHECK(channel_ == NULL); |
29 channel_id_ = id; | 31 channel_id_ = id; |
30 channel_ = new Channel(id, mode, this); | 32 channel_ = new Channel(id, mode, this); |
31 } | 33 } |
(...skipping 29 matching lines...) Expand all Loading... |
61 // NOTE: This code relies on the listener's message loop not going away while | 63 // NOTE: This code relies on the listener's message loop not going away while |
62 // this thread is active. That should be a reasonable assumption, but it | 64 // this thread is active. That should be a reasonable assumption, but it |
63 // feels risky. We may want to invent some more indirect way of referring to | 65 // feels risky. We may want to invent some more indirect way of referring to |
64 // a MessageLoop if this becomes a problem. | 66 // a MessageLoop if this becomes a problem. |
65 listener_message_loop_->PostTask(FROM_HERE, NewRunnableMethod( | 67 listener_message_loop_->PostTask(FROM_HERE, NewRunnableMethod( |
66 this, &Context::OnDispatchMessage, message)); | 68 this, &Context::OnDispatchMessage, message)); |
67 } | 69 } |
68 | 70 |
69 // Called on the IPC::Channel thread | 71 // Called on the IPC::Channel thread |
70 void ChannelProxy::Context::OnChannelConnected(int32 peer_pid) { | 72 void ChannelProxy::Context::OnChannelConnected(int32 peer_pid) { |
| 73 peer_pid_ = peer_pid; |
71 for (size_t i = 0; i < filters_.size(); ++i) | 74 for (size_t i = 0; i < filters_.size(); ++i) |
72 filters_[i]->OnChannelConnected(peer_pid); | 75 filters_[i]->OnChannelConnected(peer_pid); |
73 | 76 |
74 // See above comment about using listener_message_loop_ here. | 77 // See above comment about using listener_message_loop_ here. |
75 listener_message_loop_->PostTask(FROM_HERE, NewRunnableMethod( | 78 listener_message_loop_->PostTask(FROM_HERE, NewRunnableMethod( |
76 this, &Context::OnDispatchConnected, peer_pid)); | 79 this, &Context::OnDispatchConnected)); |
77 } | 80 } |
78 | 81 |
79 // Called on the IPC::Channel thread | 82 // Called on the IPC::Channel thread |
80 void ChannelProxy::Context::OnChannelError() { | 83 void ChannelProxy::Context::OnChannelError() { |
81 // See above comment about using listener_message_loop_ here. | 84 // See above comment about using listener_message_loop_ here. |
82 listener_message_loop_->PostTask(FROM_HERE, NewRunnableMethod( | 85 listener_message_loop_->PostTask(FROM_HERE, NewRunnableMethod( |
83 this, &Context::OnDispatchError)); | 86 this, &Context::OnDispatchError)); |
84 } | 87 } |
85 | 88 |
86 // Called on the IPC::Channel thread | 89 // Called on the IPC::Channel thread |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 } | 156 } |
154 | 157 |
155 NOTREACHED() << "filter to be removed not found"; | 158 NOTREACHED() << "filter to be removed not found"; |
156 } | 159 } |
157 | 160 |
158 // Called on the listener's thread | 161 // Called on the listener's thread |
159 void ChannelProxy::Context::OnDispatchMessage(const Message& message) { | 162 void ChannelProxy::Context::OnDispatchMessage(const Message& message) { |
160 if (!listener_) | 163 if (!listener_) |
161 return; | 164 return; |
162 | 165 |
| 166 OnDispatchConnected(); |
| 167 |
163 #ifdef IPC_MESSAGE_LOG_ENABLED | 168 #ifdef IPC_MESSAGE_LOG_ENABLED |
164 Logging* logger = Logging::current(); | 169 Logging* logger = Logging::current(); |
165 if (message.type() == IPC_LOGGING_ID) { | 170 if (message.type() == IPC_LOGGING_ID) { |
166 logger->OnReceivedLoggingMessage(message); | 171 logger->OnReceivedLoggingMessage(message); |
167 return; | 172 return; |
168 } | 173 } |
169 | 174 |
170 if (logger->Enabled()) | 175 if (logger->Enabled()) |
171 logger->OnPreDispatchMessage(message); | 176 logger->OnPreDispatchMessage(message); |
172 #endif | 177 #endif |
173 | 178 |
174 listener_->OnMessageReceived(message); | 179 listener_->OnMessageReceived(message); |
175 | 180 |
176 #ifdef IPC_MESSAGE_LOG_ENABLED | 181 #ifdef IPC_MESSAGE_LOG_ENABLED |
177 if (logger->Enabled()) | 182 if (logger->Enabled()) |
178 logger->OnPostDispatchMessage(message, channel_id_); | 183 logger->OnPostDispatchMessage(message, channel_id_); |
179 #endif | 184 #endif |
180 } | 185 } |
181 | 186 |
182 // Called on the listener's thread | 187 // Called on the listener's thread |
183 void ChannelProxy::Context::OnDispatchConnected(int32 peer_pid) { | 188 void ChannelProxy::Context::OnDispatchConnected() { |
| 189 if (channel_connected_called_) |
| 190 return; |
| 191 |
| 192 channel_connected_called_ = true; |
184 if (listener_) | 193 if (listener_) |
185 listener_->OnChannelConnected(peer_pid); | 194 listener_->OnChannelConnected(peer_pid_); |
186 } | 195 } |
187 | 196 |
188 // Called on the listener's thread | 197 // Called on the listener's thread |
189 void ChannelProxy::Context::OnDispatchError() { | 198 void ChannelProxy::Context::OnDispatchError() { |
190 if (listener_) | 199 if (listener_) |
191 listener_->OnChannelError(); | 200 listener_->OnChannelError(); |
192 } | 201 } |
193 | 202 |
194 //----------------------------------------------------------------------------- | 203 //----------------------------------------------------------------------------- |
195 | 204 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 void ChannelProxy::OnClientConnected() { | 296 void ChannelProxy::OnClientConnected() { |
288 Channel *channel = context_.get()->channel_; | 297 Channel *channel = context_.get()->channel_; |
289 DCHECK(channel); // Channel must have been created first. | 298 DCHECK(channel); // Channel must have been created first. |
290 channel->OnClientConnected(); | 299 channel->OnClientConnected(); |
291 } | 300 } |
292 #endif | 301 #endif |
293 | 302 |
294 //----------------------------------------------------------------------------- | 303 //----------------------------------------------------------------------------- |
295 | 304 |
296 } // namespace IPC | 305 } // namespace IPC |
OLD | NEW |