| 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 // P2PSocketDispatcher is a per-renderer object that dispatchers all | 5 // P2PSocketDispatcher is a per-renderer object that dispatchers all |
| 6 // P2P messages received from the browser and relays all P2P messages | 6 // P2P messages received from the browser and relays all P2P messages |
| 7 // sent to the browser. P2PSocketClient instances register themselves | 7 // sent to the browser. P2PSocketClient instances register themselves |
| 8 // with the dispatcher using RegisterClient() and UnregisterClient(). | 8 // with the dispatcher using RegisterClient() and UnregisterClient(). |
| 9 // | 9 // |
| 10 // Relationship of classes. | 10 // Relationship of classes. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 | 23 |
| 24 #include <vector> | 24 #include <vector> |
| 25 | 25 |
| 26 #include "base/callback_forward.h" | 26 #include "base/callback_forward.h" |
| 27 #include "base/compiler_specific.h" | 27 #include "base/compiler_specific.h" |
| 28 #include "base/id_map.h" | 28 #include "base/id_map.h" |
| 29 #include "base/observer_list_threadsafe.h" | 29 #include "base/observer_list_threadsafe.h" |
| 30 #include "base/synchronization/lock.h" | 30 #include "base/synchronization/lock.h" |
| 31 #include "content/common/content_export.h" | 31 #include "content/common/content_export.h" |
| 32 #include "content/common/p2p_sockets.h" | 32 #include "content/common/p2p_sockets.h" |
| 33 #include "content/public/renderer/render_view_observer.h" | 33 #include "ipc/ipc_channel_proxy.h" |
| 34 #include "net/base/net_util.h" | 34 #include "net/base/net_util.h" |
| 35 | 35 |
| 36 class RenderViewImpl; | 36 class RenderViewImpl; |
| 37 | 37 |
| 38 namespace base { | 38 namespace base { |
| 39 class MessageLoopProxy; | 39 class MessageLoopProxy; |
| 40 } // namespace base | 40 } // namespace base |
| 41 | 41 |
| 42 namespace net { | 42 namespace net { |
| 43 class IPEndPoint; | 43 class IPEndPoint; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 57 // P2PSocketDispatcher requires that all NetworkListObservers are | 57 // P2PSocketDispatcher requires that all NetworkListObservers are |
| 58 // unregistered when SocketDispatcherGone is called. | 58 // unregistered when SocketDispatcherGone is called. |
| 59 class P2PSocketDispatcherDestructionObserver { | 59 class P2PSocketDispatcherDestructionObserver { |
| 60 public: | 60 public: |
| 61 virtual void OnSocketDispatcherDestroyed() = 0; | 61 virtual void OnSocketDispatcherDestroyed() = 0; |
| 62 | 62 |
| 63 protected: | 63 protected: |
| 64 virtual ~P2PSocketDispatcherDestructionObserver() {} | 64 virtual ~P2PSocketDispatcherDestructionObserver() {} |
| 65 }; | 65 }; |
| 66 | 66 |
| 67 class CONTENT_EXPORT P2PSocketDispatcher : public content::RenderViewObserver { | 67 class CONTENT_EXPORT P2PSocketDispatcher |
| 68 : public IPC::ChannelProxy::MessageFilter{ |
| 68 public: | 69 public: |
| 69 explicit P2PSocketDispatcher(RenderViewImpl* render_view); | 70 P2PSocketDispatcher(base::MessageLoopProxy* ipc_message_loop); |
| 70 virtual ~P2PSocketDispatcher(); | |
| 71 | 71 |
| 72 // Add a new network list observer. Each observer is called | 72 // Add a new network list observer. Each observer is called |
| 73 // immidiately after it is registered and then later whenever | 73 // immidiately after it is registered and then later whenever |
| 74 // network configuration changes. Can be called on any thread. The | 74 // network configuration changes. Can be called on any thread. The |
| 75 // observer is always called on the thread it was added. | 75 // observer is always called on the thread it was added. |
| 76 void AddNetworkListObserver( | 76 void AddNetworkListObserver( |
| 77 webkit_glue::NetworkListObserver* network_list_observer); | 77 webkit_glue::NetworkListObserver* network_list_observer); |
| 78 | 78 |
| 79 // Removes network list observer. Must be called on the thread on | 79 // Removes network list observer. Must be called on the thread on |
| 80 // which the observer was added. | 80 // which the observer was added. |
| 81 void RemoveNetworkListObserver( | 81 void RemoveNetworkListObserver( |
| 82 webkit_glue::NetworkListObserver* network_list_observer); | 82 webkit_glue::NetworkListObserver* network_list_observer); |
| 83 | 83 |
| 84 void AddDestructionObserver(P2PSocketDispatcherDestructionObserver* observer); | 84 void AddDestructionObserver(P2PSocketDispatcherDestructionObserver* observer); |
| 85 void RemoveDestructionObserver( | 85 void RemoveDestructionObserver( |
| 86 P2PSocketDispatcherDestructionObserver* observer); | 86 P2PSocketDispatcherDestructionObserver* observer); |
| 87 | 87 |
| 88 // RenderViewObserver overrides. | 88 protected: |
| 89 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 89 virtual ~P2PSocketDispatcher(); |
| 90 | 90 |
| 91 private: | 91 private: |
| 92 friend class P2PHostAddressRequest; | 92 friend class P2PHostAddressRequest; |
| 93 friend class P2PSocketClient; | 93 friend class P2PSocketClient; |
| 94 class AsyncMessageSender; | 94 class AsyncMessageSender; |
| 95 | 95 |
| 96 // Send a message asynchronously. Must be called on the IO thread. |
| 97 virtual void Send(IPC::Message* message); |
| 98 |
| 99 // IPC::ChannelProxy::MessageFilter override. Called on IO thread. |
| 100 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| 101 virtual void OnFilterAdded(IPC::Channel* channel) OVERRIDE; |
| 102 virtual void OnFilterRemoved() OVERRIDE; |
| 103 virtual void OnChannelClosing() OVERRIDE; |
| 104 |
| 105 // Returns the IO message loop. |
| 96 base::MessageLoopProxy* message_loop(); | 106 base::MessageLoopProxy* message_loop(); |
| 97 | 107 |
| 98 // Called by P2PSocketClient. | 108 // Called by P2PSocketClient. |
| 99 int RegisterClient(P2PSocketClient* client); | 109 int RegisterClient(P2PSocketClient* client); |
| 100 void UnregisterClient(int id); | 110 void UnregisterClient(int id); |
| 101 void SendP2PMessage(IPC::Message* msg); | 111 void SendP2PMessage(IPC::Message* msg); |
| 102 | 112 |
| 103 // Called by DnsRequest. | 113 // Called by DnsRequest. |
| 104 int RegisterHostAddressRequest(P2PHostAddressRequest* request); | 114 int RegisterHostAddressRequest(P2PHostAddressRequest* request); |
| 105 void UnregisterHostAddressRequest(int id); | 115 void UnregisterHostAddressRequest(int id); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 122 IDMap<P2PHostAddressRequest> host_address_requests_; | 132 IDMap<P2PHostAddressRequest> host_address_requests_; |
| 123 | 133 |
| 124 bool network_notifications_started_; | 134 bool network_notifications_started_; |
| 125 scoped_refptr<ObserverListThreadSafe<webkit_glue::NetworkListObserver> > | 135 scoped_refptr<ObserverListThreadSafe<webkit_glue::NetworkListObserver> > |
| 126 network_list_observers_; | 136 network_list_observers_; |
| 127 | 137 |
| 128 scoped_refptr<AsyncMessageSender> async_message_sender_; | 138 scoped_refptr<AsyncMessageSender> async_message_sender_; |
| 129 | 139 |
| 130 ObserverList<P2PSocketDispatcherDestructionObserver> destruction_observer_; | 140 ObserverList<P2PSocketDispatcherDestructionObserver> destruction_observer_; |
| 131 | 141 |
| 142 IPC::Channel* channel_; |
| 143 |
| 132 DISALLOW_COPY_AND_ASSIGN(P2PSocketDispatcher); | 144 DISALLOW_COPY_AND_ASSIGN(P2PSocketDispatcher); |
| 133 }; | 145 }; |
| 134 | 146 |
| 135 } // namespace content | 147 } // namespace content |
| 136 | 148 |
| 137 #endif // CONTENT_RENDERER_P2P_SOCKET_DISPATCHER_H_ | 149 #endif // CONTENT_RENDERER_P2P_SOCKET_DISPATCHER_H_ |
| OLD | NEW |