| 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 "ipc/ipc_channel_proxy.h" | 7 #include "ipc/ipc_channel_proxy.h" |
| 8 #include "ipc/ipc_logging.h" | 8 #include "ipc/ipc_logging.h" |
| 9 #include "ipc/ipc_message_utils.h" | 9 #include "ipc/ipc_message_utils.h" |
| 10 | 10 |
| 11 namespace IPC { | 11 namespace IPC { |
| 12 | 12 |
| 13 //----------------------------------------------------------------------------- | 13 //------------------------------------------------------------------------------ |
| 14 |
| 15 // This task ensures the message is deleted if the task is deleted without |
| 16 // having been run. |
| 17 class SendTask : public Task { |
| 18 public: |
| 19 SendTask(ChannelProxy::Context* context, Message* message) |
| 20 : context_(context), |
| 21 message_(message) { |
| 22 } |
| 23 |
| 24 virtual void Run() { |
| 25 context_->OnSendMessage(message_.release()); |
| 26 } |
| 27 |
| 28 private: |
| 29 scoped_refptr<ChannelProxy::Context> context_; |
| 30 scoped_ptr<Message> message_; |
| 31 |
| 32 DISALLOW_COPY_AND_ASSIGN(SendTask); |
| 33 }; |
| 34 |
| 35 //------------------------------------------------------------------------------ |
| 14 | 36 |
| 15 ChannelProxy::Context::Context(Channel::Listener* listener, | 37 ChannelProxy::Context::Context(Channel::Listener* listener, |
| 16 MessageFilter* filter, | 38 MessageFilter* filter, |
| 17 MessageLoop* ipc_message_loop) | 39 MessageLoop* ipc_message_loop) |
| 18 : listener_message_loop_(MessageLoop::current()), | 40 : listener_message_loop_(MessageLoop::current()), |
| 19 listener_(listener), | 41 listener_(listener), |
| 20 ipc_message_loop_(ipc_message_loop), | 42 ipc_message_loop_(ipc_message_loop), |
| 21 channel_(NULL), | 43 channel_(NULL), |
| 22 peer_pid_(0), | 44 peer_pid_(0), |
| 23 channel_connected_called_(false) { | 45 channel_connected_called_(false) { |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 context_->ipc_message_loop()->PostTask(FROM_HERE, NewRunnableMethod( | 269 context_->ipc_message_loop()->PostTask(FROM_HERE, NewRunnableMethod( |
| 248 context_.get(), &Context::OnChannelClosed)); | 270 context_.get(), &Context::OnChannelClosed)); |
| 249 } | 271 } |
| 250 } | 272 } |
| 251 | 273 |
| 252 bool ChannelProxy::Send(Message* message) { | 274 bool ChannelProxy::Send(Message* message) { |
| 253 #ifdef IPC_MESSAGE_LOG_ENABLED | 275 #ifdef IPC_MESSAGE_LOG_ENABLED |
| 254 Logging::current()->OnSendMessage(message, context_->channel_id()); | 276 Logging::current()->OnSendMessage(message, context_->channel_id()); |
| 255 #endif | 277 #endif |
| 256 | 278 |
| 257 context_->ipc_message_loop()->PostTask(FROM_HERE, NewRunnableMethod( | 279 context_->ipc_message_loop()->PostTask(FROM_HERE, |
| 258 context_.get(), &Context::OnSendMessage, message)); | 280 new SendTask(context_.get(), message)); |
| 259 return true; | 281 return true; |
| 260 } | 282 } |
| 261 | 283 |
| 262 void ChannelProxy::AddFilter(MessageFilter* filter) { | 284 void ChannelProxy::AddFilter(MessageFilter* filter) { |
| 263 // We want to addref the filter to prevent it from | 285 // We want to addref the filter to prevent it from |
| 264 // being destroyed before the OnAddFilter call is invoked. | 286 // being destroyed before the OnAddFilter call is invoked. |
| 265 filter->AddRef(); | 287 filter->AddRef(); |
| 266 context_->ipc_message_loop()->PostTask(FROM_HERE, NewRunnableMethod( | 288 context_->ipc_message_loop()->PostTask(FROM_HERE, NewRunnableMethod( |
| 267 context_.get(), &Context::OnAddFilter, filter)); | 289 context_.get(), &Context::OnAddFilter, filter)); |
| 268 } | 290 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 283 int ChannelProxy::GetClientFileDescriptor() const { | 305 int ChannelProxy::GetClientFileDescriptor() const { |
| 284 Channel *channel = context_.get()->channel_; | 306 Channel *channel = context_.get()->channel_; |
| 285 DCHECK(channel); // Channel must have been created first. | 307 DCHECK(channel); // Channel must have been created first. |
| 286 return channel->GetClientFileDescriptor(); | 308 return channel->GetClientFileDescriptor(); |
| 287 } | 309 } |
| 288 #endif | 310 #endif |
| 289 | 311 |
| 290 //----------------------------------------------------------------------------- | 312 //----------------------------------------------------------------------------- |
| 291 | 313 |
| 292 } // namespace IPC | 314 } // namespace IPC |
| OLD | NEW |