Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(580)

Side by Side Diff: content/renderer/p2p/socket_client.h

Issue 13584008: Send notification about outgoing p2p packets from browser to renderer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 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 #ifndef CONTENT_RENDERER_P2P_SOCKET_CLIENT_H_ 5 #ifndef CONTENT_RENDERER_P2P_SOCKET_CLIENT_H_
6 #define CONTENT_RENDERER_P2P_SOCKET_CLIENT_H_ 6 #define CONTENT_RENDERER_P2P_SOCKET_CLIENT_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
11 #include "content/common/p2p_sockets.h" 11 #include "content/common/p2p_sockets.h"
12 #include "net/base/ip_endpoint.h" 12 #include "net/base/ip_endpoint.h"
13 13
14 namespace base { 14 namespace base {
15 class MessageLoopProxy; 15 class MessageLoopProxy;
16 } // namespace base 16 } // namespace base
17 17
18 namespace content { 18 namespace content {
19 19
20 class P2PSocketDispatcher; 20 class P2PSocketDispatcher;
21 21
22 // P2P socket that rountes all calls over IPC. 22 // P2P socket that rountes all calls over IPC.
23 // 23 //
24 // The object runs on two threads: IPC thread and delegate thread. The 24 // The object runs on two threads: IPC thread and delegate thread. The
25 // IPC thread is used to interact with P2PSocketDispatcher. All 25 // IPC thread is used to interact with P2PSocketDispatcher. All
26 // callbacks to the user of this class are called on the delegate 26 // callbacks to the user of this class are called on the delegate
27 // thread which is specified in Init(). 27 // thread which is specified in Init().
28 class P2PSocketClient : public base::RefCountedThreadSafe<P2PSocketClient> { 28 class P2PSocketClient : public base::RefCountedThreadSafe<P2PSocketClient> {
29 public: 29 public:
30 // Delegate is called on the the same thread on the delegate thread. 30 // Delegate is called on the the same thread on which P2PSocketCLient is
31 // created.
31 class Delegate { 32 class Delegate {
32 public: 33 public:
33 virtual ~Delegate() { } 34 virtual ~Delegate() { }
34 35
35 virtual void OnOpen(const net::IPEndPoint& address) = 0; 36 virtual void OnOpen(const net::IPEndPoint& address) = 0;
36 virtual void OnIncomingTcpConnection(const net::IPEndPoint& address, 37 virtual void OnIncomingTcpConnection(const net::IPEndPoint& address,
37 P2PSocketClient* client) = 0; 38 P2PSocketClient* client) = 0;
39 virtual void OnSendComplete() = 0;
38 virtual void OnError() = 0; 40 virtual void OnError() = 0;
39 virtual void OnDataReceived(const net::IPEndPoint& address, 41 virtual void OnDataReceived(const net::IPEndPoint& address,
40 const std::vector<char>& data) = 0; 42 const std::vector<char>& data) = 0;
41 }; 43 };
42 44
43 explicit P2PSocketClient(P2PSocketDispatcher* dispatcher); 45 explicit P2PSocketClient(P2PSocketDispatcher* dispatcher);
44 46
45 // Initialize socket of the specified |type| and connected to the 47 // Initialize socket of the specified |type| and connected to the
46 // specified |address|. |address| matters only when |type| is set to 48 // specified |address|. |address| matters only when |type| is set to
47 // P2P_SOCKET_TCP_CLIENT. 49 // P2P_SOCKET_TCP_CLIENT.
(...skipping 25 matching lines...) Expand all
73 friend class P2PSocketDispatcher; 75 friend class P2PSocketDispatcher;
74 76
75 // Calls destructor. 77 // Calls destructor.
76 friend class base::RefCountedThreadSafe<P2PSocketClient>; 78 friend class base::RefCountedThreadSafe<P2PSocketClient>;
77 79
78 virtual ~P2PSocketClient(); 80 virtual ~P2PSocketClient();
79 81
80 // Message handlers that run on IPC thread. 82 // Message handlers that run on IPC thread.
81 void OnSocketCreated(const net::IPEndPoint& address); 83 void OnSocketCreated(const net::IPEndPoint& address);
82 void OnIncomingTcpConnection(const net::IPEndPoint& address); 84 void OnIncomingTcpConnection(const net::IPEndPoint& address);
85 void OnSendComplete(int packet_id);
86 void OnSendComplete();
83 void OnError(); 87 void OnError();
84 void OnDataReceived(const net::IPEndPoint& address, 88 void OnDataReceived(const net::IPEndPoint& address,
85 const std::vector<char>& data); 89 const std::vector<char>& data);
86 90
87 // Proxy methods that deliver messages to the delegate thread. 91 // Proxy methods that deliver messages to the delegate thread.
88 void DeliverOnSocketCreated(const net::IPEndPoint& address); 92 void DeliverOnSocketCreated(const net::IPEndPoint& address);
89 void DeliverOnIncomingTcpConnection( 93 void DeliverOnIncomingTcpConnection(
90 const net::IPEndPoint& address, 94 const net::IPEndPoint& address,
91 scoped_refptr<P2PSocketClient> new_client); 95 scoped_refptr<P2PSocketClient> new_client);
96 void DeliverOnSendComplete();
92 void DeliverOnError(); 97 void DeliverOnError();
93 void DeliverOnDataReceived(const net::IPEndPoint& address, 98 void DeliverOnDataReceived(const net::IPEndPoint& address,
94 const std::vector<char>& data); 99 const std::vector<char>& data);
95 100
96 // Scheduled on the IPC thread to finish initialization. 101 // Scheduled on the IPC thread to finish initialization.
97 void DoInit(P2PSocketType type, 102 void DoInit(P2PSocketType type,
98 const net::IPEndPoint& local_address, 103 const net::IPEndPoint& local_address,
99 const net::IPEndPoint& remote_address); 104 const net::IPEndPoint& remote_address);
100 105
101 // Scheduled on the IPC thread to finish closing the connection. 106 // Scheduled on the IPC thread to finish closing the connection.
102 void DoClose(); 107 void DoClose();
103 108
104 // Called by the dispatcher when it is destroyed. 109 // Called by the dispatcher when it is destroyed.
105 void Detach(); 110 void Detach();
106 111
107 P2PSocketDispatcher* dispatcher_; 112 P2PSocketDispatcher* dispatcher_;
108 scoped_refptr<base::MessageLoopProxy> ipc_message_loop_; 113 scoped_refptr<base::MessageLoopProxy> ipc_message_loop_;
109 scoped_refptr<base::MessageLoopProxy> delegate_message_loop_; 114 scoped_refptr<base::MessageLoopProxy> delegate_message_loop_;
110 int socket_id_; 115 int socket_id_;
111 Delegate* delegate_; 116 Delegate* delegate_;
112 State state_; 117 State state_;
113 118
114 DISALLOW_COPY_AND_ASSIGN(P2PSocketClient); 119 DISALLOW_COPY_AND_ASSIGN(P2PSocketClient);
115 }; 120 };
116 121
117 } // namespace content 122 } // namespace content
118 123
119 #endif // CONTENT_RENDERER_P2P_SOCKET_CLIENT_H_ 124 #endif // CONTENT_RENDERER_P2P_SOCKET_CLIENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698