Chromium Code Reviews| 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 | |
|
Alpha Left Google
2011/03/02 21:56:10
Hm.. Having P2PSocketsHost and P2PSocketHost is co
Sergey Ulanov
2011/03/02 23:56:43
I agree that the naming sucks. Thanks for your sug
| |
| 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 class MessageLoop; | |
| 30 | |
| 31 // P2PSocketDispatcher works on the same thread it was created on. It | |
|
Alpha Left Google
2011/03/02 21:56:10
I'd just say it works only on render thread or IO
Sergey Ulanov
2011/03/02 23:56:43
Done.
| |
| 32 // dispatches all messages on that thread, and all its methods must be | |
| 33 // called on the same thread. | |
| 34 class P2PSocketDispatcher : public RenderViewObserver { | |
| 35 public: | |
| 36 explicit P2PSocketDispatcher(RenderView* render_view); | |
| 37 virtual ~P2PSocketDispatcher(); | |
| 38 | |
| 39 P2PSocketClient* CreateSocket(P2PSocketType type, P2PSocketAddress address, | |
| 40 P2PSocketClient::Delegate* delegate); | |
| 41 | |
| 42 // RenderViewObserver overrides. | |
| 43 virtual bool OnMessageReceived(const IPC::Message& message); | |
| 44 | |
| 45 private: | |
| 46 friend class P2PSocketClient; | |
| 47 | |
| 48 // Called by P2PSocketClient. | |
| 49 int RegisterClient(P2PSocketClient* client); | |
| 50 void UnregisterClient(int id); | |
| 51 void SendP2PMessage(IPC::Message* msg); | |
| 52 MessageLoop* message_loop(); | |
| 53 | |
| 54 // Incoming message handlers. | |
| 55 void OnSocketCreated(int socket_id, P2PSocketAddress address); | |
| 56 void OnError(int socket_id); | |
| 57 void OnDataReceived(int socket_id, P2PSocketAddress address, | |
| 58 const std::vector<char>& data); | |
| 59 | |
| 60 P2PSocketClient* GetClient(int socket_id); | |
| 61 | |
| 62 MessageLoop* message_loop_; | |
| 63 IDMap<P2PSocketClient> clients_; | |
| 64 | |
| 65 DISALLOW_COPY_AND_ASSIGN(P2PSocketDispatcher); | |
| 66 }; | |
| 67 | |
| 68 #endif // CHROME_RENDERER_P2P_SOCKET_DISPATCHER_H_ | |
| OLD | NEW |