| 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/message_loop_proxy.h" |    9 #include "base/message_loop/message_loop_proxy.h" | 
|   10 #include "content/child/child_process.h" |   10 #include "content/child/child_process.h" | 
|   11 #include "content/common/p2p_messages.h" |   11 #include "content/common/p2p_messages.h" | 
|   12 #include "content/renderer/p2p/host_address_request.h" |   12 #include "content/renderer/p2p/host_address_request.h" | 
|   13 #include "content/renderer/p2p/network_list_observer.h" |   13 #include "content/renderer/p2p/network_list_observer.h" | 
|   14 #include "content/renderer/p2p/socket_client_impl.h" |   14 #include "content/renderer/p2p/socket_client_impl.h" | 
|   15 #include "content/renderer/render_view_impl.h" |   15 #include "content/renderer/render_view_impl.h" | 
|   16 #include "ipc/ipc_sender.h" |   16 #include "ipc/ipc_channel.h" | 
|   17  |   17  | 
|   18 namespace content { |   18 namespace content { | 
|   19  |   19  | 
|   20 P2PSocketDispatcher::P2PSocketDispatcher( |   20 P2PSocketDispatcher::P2PSocketDispatcher( | 
|   21     base::MessageLoopProxy* ipc_message_loop) |   21     base::MessageLoopProxy* ipc_message_loop) | 
|   22     : message_loop_(ipc_message_loop), |   22     : message_loop_(ipc_message_loop), | 
|   23       network_notifications_started_(false), |   23       network_notifications_started_(false), | 
|   24       network_list_observers_( |   24       network_list_observers_( | 
|   25           new ObserverListThreadSafe<NetworkListObserver>()), |   25           new ObserverListThreadSafe<NetworkListObserver>()), | 
|   26       sender_(NULL) { |   26       channel_(NULL) { | 
|   27 } |   27 } | 
|   28  |   28  | 
|   29 P2PSocketDispatcher::~P2PSocketDispatcher() { |   29 P2PSocketDispatcher::~P2PSocketDispatcher() { | 
|   30   network_list_observers_->AssertEmpty(); |   30   network_list_observers_->AssertEmpty(); | 
|   31   for (IDMap<P2PSocketClientImpl>::iterator i(&clients_); !i.IsAtEnd(); |   31   for (IDMap<P2PSocketClientImpl>::iterator i(&clients_); !i.IsAtEnd(); | 
|   32        i.Advance()) { |   32        i.Advance()) { | 
|   33     i.GetCurrentValue()->Detach(); |   33     i.GetCurrentValue()->Detach(); | 
|   34   } |   34   } | 
|   35 } |   35 } | 
|   36  |   36  | 
|   37 void P2PSocketDispatcher::AddNetworkListObserver( |   37 void P2PSocketDispatcher::AddNetworkListObserver( | 
|   38     NetworkListObserver* network_list_observer) { |   38     NetworkListObserver* network_list_observer) { | 
|   39   network_list_observers_->AddObserver(network_list_observer); |   39   network_list_observers_->AddObserver(network_list_observer); | 
|   40   network_notifications_started_ = true; |   40   network_notifications_started_ = true; | 
|   41   SendP2PMessage(new P2PHostMsg_StartNetworkNotifications()); |   41   SendP2PMessage(new P2PHostMsg_StartNetworkNotifications()); | 
|   42 } |   42 } | 
|   43  |   43  | 
|   44 void P2PSocketDispatcher::RemoveNetworkListObserver( |   44 void P2PSocketDispatcher::RemoveNetworkListObserver( | 
|   45     NetworkListObserver* network_list_observer) { |   45     NetworkListObserver* network_list_observer) { | 
|   46   network_list_observers_->RemoveObserver(network_list_observer); |   46   network_list_observers_->RemoveObserver(network_list_observer); | 
|   47 } |   47 } | 
|   48  |   48  | 
|   49 void P2PSocketDispatcher::Send(IPC::Message* message) { |   49 void P2PSocketDispatcher::Send(IPC::Message* message) { | 
|   50   DCHECK(message_loop_->BelongsToCurrentThread()); |   50   DCHECK(message_loop_->BelongsToCurrentThread()); | 
|   51   if (!sender_) { |   51   if (!channel_) { | 
|   52     DLOG(WARNING) << "P2PSocketDispatcher::Send() - Sender closed."; |   52     DLOG(WARNING) << "P2PSocketDispatcher::Send() - Channel closed."; | 
|   53     delete message; |   53     delete message; | 
|   54     return; |   54     return; | 
|   55   } |   55   } | 
|   56  |   56  | 
|   57   sender_->Send(message); |   57   channel_->Send(message); | 
|   58 } |   58 } | 
|   59  |   59  | 
|   60 bool P2PSocketDispatcher::OnMessageReceived(const IPC::Message& message) { |   60 bool P2PSocketDispatcher::OnMessageReceived(const IPC::Message& message) { | 
|   61   bool handled = true; |   61   bool handled = true; | 
|   62   IPC_BEGIN_MESSAGE_MAP(P2PSocketDispatcher, message) |   62   IPC_BEGIN_MESSAGE_MAP(P2PSocketDispatcher, message) | 
|   63     IPC_MESSAGE_HANDLER(P2PMsg_NetworkListChanged, OnNetworkListChanged) |   63     IPC_MESSAGE_HANDLER(P2PMsg_NetworkListChanged, OnNetworkListChanged) | 
|   64     IPC_MESSAGE_HANDLER(P2PMsg_GetHostAddressResult, OnGetHostAddressResult) |   64     IPC_MESSAGE_HANDLER(P2PMsg_GetHostAddressResult, OnGetHostAddressResult) | 
|   65     IPC_MESSAGE_HANDLER(P2PMsg_OnSocketCreated, OnSocketCreated) |   65     IPC_MESSAGE_HANDLER(P2PMsg_OnSocketCreated, OnSocketCreated) | 
|   66     IPC_MESSAGE_HANDLER(P2PMsg_OnIncomingTcpConnection, OnIncomingTcpConnection) |   66     IPC_MESSAGE_HANDLER(P2PMsg_OnIncomingTcpConnection, OnIncomingTcpConnection) | 
|   67     IPC_MESSAGE_HANDLER(P2PMsg_OnSendComplete, OnSendComplete) |   67     IPC_MESSAGE_HANDLER(P2PMsg_OnSendComplete, OnSendComplete) | 
|   68     IPC_MESSAGE_HANDLER(P2PMsg_OnError, OnError) |   68     IPC_MESSAGE_HANDLER(P2PMsg_OnError, OnError) | 
|   69     IPC_MESSAGE_HANDLER(P2PMsg_OnDataReceived, OnDataReceived) |   69     IPC_MESSAGE_HANDLER(P2PMsg_OnDataReceived, OnDataReceived) | 
|   70     IPC_MESSAGE_UNHANDLED(handled = false) |   70     IPC_MESSAGE_UNHANDLED(handled = false) | 
|   71   IPC_END_MESSAGE_MAP() |   71   IPC_END_MESSAGE_MAP() | 
|   72   return handled; |   72   return handled; | 
|   73 } |   73 } | 
|   74  |   74  | 
|   75 void P2PSocketDispatcher::OnFilterAdded(IPC::Sender* sender) { |   75 void P2PSocketDispatcher::OnFilterAdded(IPC::Channel* channel) { | 
|   76   DVLOG(1) << "P2PSocketDispatcher::OnFilterAdded()"; |   76   DVLOG(1) << "P2PSocketDispatcher::OnFilterAdded()"; | 
|   77   sender_ = sender; |   77   channel_ = channel; | 
|   78 } |   78 } | 
|   79  |   79  | 
|   80 void P2PSocketDispatcher::OnFilterRemoved() { |   80 void P2PSocketDispatcher::OnFilterRemoved() { | 
|   81   sender_ = NULL; |   81   channel_ = NULL; | 
|   82 } |   82 } | 
|   83  |   83  | 
|   84 void P2PSocketDispatcher::OnChannelClosing() { |   84 void P2PSocketDispatcher::OnChannelClosing() { | 
|   85   sender_ = NULL; |   85   channel_ = NULL; | 
|   86 } |   86 } | 
|   87  |   87  | 
|   88 base::MessageLoopProxy* P2PSocketDispatcher::message_loop() { |   88 base::MessageLoopProxy* P2PSocketDispatcher::message_loop() { | 
|   89   return message_loop_.get(); |   89   return message_loop_.get(); | 
|   90 } |   90 } | 
|   91  |   91  | 
|   92 int P2PSocketDispatcher::RegisterClient(P2PSocketClientImpl* client) { |   92 int P2PSocketDispatcher::RegisterClient(P2PSocketClientImpl* client) { | 
|   93   DCHECK(message_loop_->BelongsToCurrentThread()); |   93   DCHECK(message_loop_->BelongsToCurrentThread()); | 
|   94   return clients_.Add(client); |   94   return clients_.Add(client); | 
|   95 } |   95 } | 
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  185     // hasn't processed the close message by the time it sends the |  185     // hasn't processed the close message by the time it sends the | 
|  186     // message to the renderer. |  186     // message to the renderer. | 
|  187     VLOG(1) << "Received P2P message for socket that doesn't exist."; |  187     VLOG(1) << "Received P2P message for socket that doesn't exist."; | 
|  188     return NULL; |  188     return NULL; | 
|  189   } |  189   } | 
|  190  |  190  | 
|  191   return client; |  191   return client; | 
|  192 } |  192 } | 
|  193  |  193  | 
|  194 }  // namespace content |  194 }  // namespace content | 
| OLD | NEW |