| 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/renderer/p2p/socket_dispatcher.h" | 5 #include "content/renderer/p2p/socket_dispatcher.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/message_loop_proxy.h" | 9 #include "base/message_loop_proxy.h" |
| 10 #include "content/common/p2p_messages.h" | 10 #include "content/common/p2p_messages.h" |
| 11 #include "content/renderer/p2p/host_address_request.h" | 11 #include "content/renderer/p2p/host_address_request.h" |
| 12 #include "content/renderer/p2p/socket_client.h" | 12 #include "content/renderer/p2p/socket_client.h" |
| 13 #include "content/renderer/render_view_impl.h" | 13 #include "content/renderer/render_view_impl.h" |
| 14 #include "webkit/glue/network_list_observer.h" | 14 #include "webkit/glue/network_list_observer.h" |
| 15 | 15 |
| 16 namespace content { | 16 namespace content { |
| 17 | 17 |
| 18 class P2PSocketDispatcher::AsyncMessageSender | 18 class P2PSocketDispatcher::AsyncMessageSender |
| 19 : public base::RefCountedThreadSafe<AsyncMessageSender> { | 19 : public base::RefCountedThreadSafe<AsyncMessageSender> { |
| 20 public: | 20 public: |
| 21 explicit AsyncMessageSender(IPC::Message::Sender* message_sender) | 21 explicit AsyncMessageSender(IPC::Sender* message_sender) |
| 22 : message_loop_(base::MessageLoopProxy::current()), | 22 : message_loop_(base::MessageLoopProxy::current()), |
| 23 message_sender_(message_sender) { | 23 message_sender_(message_sender) { |
| 24 } | 24 } |
| 25 | 25 |
| 26 void Detach() { | 26 void Detach() { |
| 27 DCHECK(message_loop_->BelongsToCurrentThread()); | 27 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 28 message_sender_ = NULL; | 28 message_sender_ = NULL; |
| 29 } | 29 } |
| 30 | 30 |
| 31 void Send(IPC::Message* msg) { | 31 void Send(IPC::Message* msg) { |
| 32 message_loop_->PostTask(FROM_HERE, | 32 message_loop_->PostTask(FROM_HERE, |
| 33 base::Bind(&AsyncMessageSender::DoSend, this, msg)); | 33 base::Bind(&AsyncMessageSender::DoSend, this, msg)); |
| 34 } | 34 } |
| 35 | 35 |
| 36 private: | 36 private: |
| 37 friend class base::RefCountedThreadSafe<AsyncMessageSender>; | 37 friend class base::RefCountedThreadSafe<AsyncMessageSender>; |
| 38 ~AsyncMessageSender() {} | 38 ~AsyncMessageSender() {} |
| 39 | 39 |
| 40 void DoSend(IPC::Message* msg) { | 40 void DoSend(IPC::Message* msg) { |
| 41 DCHECK(message_loop_->BelongsToCurrentThread()); | 41 DCHECK(message_loop_->BelongsToCurrentThread()); |
| 42 if (message_sender_) | 42 if (message_sender_) |
| 43 message_sender_->Send(msg); | 43 message_sender_->Send(msg); |
| 44 } | 44 } |
| 45 | 45 |
| 46 scoped_refptr<base::MessageLoopProxy> message_loop_; | 46 scoped_refptr<base::MessageLoopProxy> message_loop_; |
| 47 IPC::Message::Sender* message_sender_; | 47 IPC::Sender* message_sender_; |
| 48 | 48 |
| 49 DISALLOW_COPY_AND_ASSIGN(AsyncMessageSender); | 49 DISALLOW_COPY_AND_ASSIGN(AsyncMessageSender); |
| 50 }; | 50 }; |
| 51 | 51 |
| 52 P2PSocketDispatcher::P2PSocketDispatcher(RenderViewImpl* render_view) | 52 P2PSocketDispatcher::P2PSocketDispatcher(RenderViewImpl* render_view) |
| 53 : content::RenderViewObserver(render_view), | 53 : content::RenderViewObserver(render_view), |
| 54 message_loop_(base::MessageLoopProxy::current()), | 54 message_loop_(base::MessageLoopProxy::current()), |
| 55 network_notifications_started_(false), | 55 network_notifications_started_(false), |
| 56 network_list_observers_( | 56 network_list_observers_( |
| 57 new ObserverListThreadSafe<webkit_glue::NetworkListObserver>()), | 57 new ObserverListThreadSafe<webkit_glue::NetworkListObserver>()), |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 // hasn't processed the close message by the time it sends the | 191 // hasn't processed the close message by the time it sends the |
| 192 // message to the renderer. | 192 // message to the renderer. |
| 193 VLOG(1) << "Received P2P message for socket that doesn't exist."; | 193 VLOG(1) << "Received P2P message for socket that doesn't exist."; |
| 194 return NULL; | 194 return NULL; |
| 195 } | 195 } |
| 196 | 196 |
| 197 return client; | 197 return client; |
| 198 } | 198 } |
| 199 | 199 |
| 200 } // namespace content | 200 } // namespace content |
| OLD | NEW |