| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 // P2PSocketDispatcher is a per-renderer object that dispatchers all | |
| 6 // P2P messages received from the browser and relays all P2P messages | |
| 7 // sent to the browser. P2PSocketClient instances register themselves | |
| 8 // with the dispatcher using RegisterClient() and UnregisterClient(). | |
| 9 // | |
| 10 // Relationship of classes. | |
| 11 // | |
| 12 // P2PSocketHost P2PSocketClient | |
| 13 // ^ ^ | |
| 14 // | | | |
| 15 // v IPC v | |
| 16 // P2PSocketsHost <---------> P2PSocketDispatcher | |
| 17 // | |
| 18 | |
| 19 #ifndef CHROME_RENDERER_P2P_SOCKET_DISPATCHER_H_ | |
| 20 #define CHROME_RENDERER_P2P_SOCKET_DISPATCHER_H_ | |
| 21 | |
| 22 #include <vector> | |
| 23 | |
| 24 #include "base/id_map.h" | |
| 25 #include "chrome/renderer/p2p/socket_client.h" | |
| 26 #include "content/common/p2p_sockets.h" | |
| 27 #include "chrome/renderer/render_view_observer.h" | |
| 28 | |
| 29 namespace base { | |
| 30 class MessageLoopProxy; | |
| 31 } // namespace base | |
| 32 | |
| 33 // P2PSocketDispatcher works on the renderer thread. It dispatches all | |
| 34 // messages on that thread, and all its methods must be called on the | |
| 35 // same thread. | |
| 36 class P2PSocketDispatcher : public RenderViewObserver { | |
| 37 public: | |
| 38 explicit P2PSocketDispatcher(RenderView* render_view); | |
| 39 virtual ~P2PSocketDispatcher(); | |
| 40 | |
| 41 P2PSocketClient* CreateSocket(P2PSocketType type, | |
| 42 const net::IPEndPoint& address, | |
| 43 P2PSocketClient::Delegate* delegate); | |
| 44 | |
| 45 // RenderViewObserver overrides. | |
| 46 virtual bool OnMessageReceived(const IPC::Message& message); | |
| 47 | |
| 48 private: | |
| 49 friend class P2PSocketClient; | |
| 50 | |
| 51 // Called by P2PSocketClient. | |
| 52 int RegisterClient(P2PSocketClient* client); | |
| 53 void UnregisterClient(int id); | |
| 54 void SendP2PMessage(IPC::Message* msg); | |
| 55 base::MessageLoopProxy* message_loop(); | |
| 56 | |
| 57 // Incoming message handlers. | |
| 58 void OnSocketCreated(int socket_id, const net::IPEndPoint& address); | |
| 59 void OnError(int socket_id); | |
| 60 void OnDataReceived(int socket_id, const net::IPEndPoint& address, | |
| 61 const std::vector<char>& data); | |
| 62 | |
| 63 P2PSocketClient* GetClient(int socket_id); | |
| 64 | |
| 65 scoped_refptr<base::MessageLoopProxy> message_loop_; | |
| 66 IDMap<P2PSocketClient> clients_; | |
| 67 | |
| 68 DISALLOW_COPY_AND_ASSIGN(P2PSocketDispatcher); | |
| 69 }; | |
| 70 | |
| 71 #endif // CHROME_RENDERER_P2P_SOCKET_DISPATCHER_H_ | |
| OLD | NEW |