OLD | NEW |
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_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_H_ | 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_H_ |
6 #define CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_H_ | 6 #define CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_H_ |
7 | 7 |
8 #include "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
9 #include "content/common/content_export.h" | 9 #include "content/common/content_export.h" |
10 #include "content/common/p2p_socket_type.h" | 10 #include "content/common/p2p_socket_type.h" |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 | 84 |
85 void StartRtpDump( | 85 void StartRtpDump( |
86 bool incoming, | 86 bool incoming, |
87 bool outgoing, | 87 bool outgoing, |
88 const RenderProcessHost::WebRtcRtpPacketCallback& packet_callback); | 88 const RenderProcessHost::WebRtcRtpPacketCallback& packet_callback); |
89 void StopRtpDump(bool incoming, bool outgoing); | 89 void StopRtpDump(bool incoming, bool outgoing); |
90 | 90 |
91 protected: | 91 protected: |
92 friend class P2PSocketHostTcpTestBase; | 92 friend class P2PSocketHostTcpTestBase; |
93 | 93 |
| 94 // This should match suffix IPProtocolType defined in histograms.xml. |
| 95 enum ProtocolType { UDP = 0x1, TCP = 0x2 }; |
| 96 |
94 // TODO(mallinath) - Remove this below enum and use one defined in | 97 // TODO(mallinath) - Remove this below enum and use one defined in |
95 // libjingle/souce/talk/p2p/base/stun.h | 98 // libjingle/souce/talk/p2p/base/stun.h |
96 enum StunMessageType { | 99 enum StunMessageType { |
97 STUN_BINDING_REQUEST = 0x0001, | 100 STUN_BINDING_REQUEST = 0x0001, |
98 STUN_BINDING_RESPONSE = 0x0101, | 101 STUN_BINDING_RESPONSE = 0x0101, |
99 STUN_BINDING_ERROR_RESPONSE = 0x0111, | 102 STUN_BINDING_ERROR_RESPONSE = 0x0111, |
100 STUN_SHARED_SECRET_REQUEST = 0x0002, | 103 STUN_SHARED_SECRET_REQUEST = 0x0002, |
101 STUN_SHARED_SECRET_RESPONSE = 0x0102, | 104 STUN_SHARED_SECRET_RESPONSE = 0x0102, |
102 STUN_SHARED_SECRET_ERROR_RESPONSE = 0x0112, | 105 STUN_SHARED_SECRET_ERROR_RESPONSE = 0x0112, |
103 STUN_ALLOCATE_REQUEST = 0x0003, | 106 STUN_ALLOCATE_REQUEST = 0x0003, |
(...skipping 14 matching lines...) Expand all Loading... |
118 }; | 121 }; |
119 | 122 |
120 enum State { | 123 enum State { |
121 STATE_UNINITIALIZED, | 124 STATE_UNINITIALIZED, |
122 STATE_CONNECTING, | 125 STATE_CONNECTING, |
123 STATE_TLS_CONNECTING, | 126 STATE_TLS_CONNECTING, |
124 STATE_OPEN, | 127 STATE_OPEN, |
125 STATE_ERROR, | 128 STATE_ERROR, |
126 }; | 129 }; |
127 | 130 |
128 P2PSocketHost(IPC::Sender* message_sender, int socket_id); | 131 P2PSocketHost(IPC::Sender* message_sender, |
| 132 int socket_id, |
| 133 ProtocolType protocol_type); |
129 | 134 |
130 // Verifies that the packet |data| has a valid STUN header. In case | 135 // Verifies that the packet |data| has a valid STUN header. In case |
131 // of success stores type of the message in |type|. | 136 // of success stores type of the message in |type|. |
132 static bool GetStunPacketType(const char* data, int data_size, | 137 static bool GetStunPacketType(const char* data, int data_size, |
133 StunMessageType* type); | 138 StunMessageType* type); |
134 static bool IsRequestOrResponse(StunMessageType type); | 139 static bool IsRequestOrResponse(StunMessageType type); |
135 | 140 |
136 // Calls |packet_dump_callback_| to record the RTP header. | 141 // Calls |packet_dump_callback_| to record the RTP header. |
137 void DumpRtpPacket(const char* packet, size_t length, bool incoming); | 142 void DumpRtpPacket(const char* packet, size_t length, bool incoming); |
138 | 143 |
139 // A helper to dump the packet on the IO thread. | 144 // A helper to dump the packet on the IO thread. |
140 void DumpRtpPacketOnIOThread(scoped_ptr<uint8[]> packet_header, | 145 void DumpRtpPacketOnIOThread(scoped_ptr<uint8[]> packet_header, |
141 size_t header_length, | 146 size_t header_length, |
142 size_t packet_length, | 147 size_t packet_length, |
143 bool incoming); | 148 bool incoming); |
144 | 149 |
| 150 // Used by subclasses to track the metrics of delayed bytes and packets. |
| 151 void IncrementDelayedPackets(); |
| 152 void IncrementTotalSentPackets(); |
| 153 void IncrementDelayedBytes(uint32 size); |
| 154 void DecrementDelayedBytes(uint32 size); |
| 155 |
145 IPC::Sender* message_sender_; | 156 IPC::Sender* message_sender_; |
146 int id_; | 157 int id_; |
147 State state_; | 158 State state_; |
148 bool dump_incoming_rtp_packet_; | 159 bool dump_incoming_rtp_packet_; |
149 bool dump_outgoing_rtp_packet_; | 160 bool dump_outgoing_rtp_packet_; |
150 RenderProcessHost::WebRtcRtpPacketCallback packet_dump_callback_; | 161 RenderProcessHost::WebRtcRtpPacketCallback packet_dump_callback_; |
151 | 162 |
152 base::WeakPtrFactory<P2PSocketHost> weak_ptr_factory_; | 163 base::WeakPtrFactory<P2PSocketHost> weak_ptr_factory_; |
153 | 164 |
| 165 ProtocolType protocol_type_; |
| 166 |
| 167 private: |
| 168 // Track total delayed packets for calculating how many packets are |
| 169 // delayed by system at the end of call. |
| 170 uint32 send_packets_delayed_total_; |
| 171 uint32 send_packets_total_; |
| 172 |
| 173 // Track the maximum of consecutive delayed bytes caused by system's |
| 174 // EWOULDBLOCK. |
| 175 int32 send_bytes_delayed_max_; |
| 176 int32 send_bytes_delayed_cur_; |
| 177 |
154 DISALLOW_COPY_AND_ASSIGN(P2PSocketHost); | 178 DISALLOW_COPY_AND_ASSIGN(P2PSocketHost); |
155 }; | 179 }; |
156 | 180 |
157 } // namespace content | 181 } // namespace content |
158 | 182 |
159 #endif // CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_H_ | 183 #endif // CONTENT_BROWSER_RENDERER_HOST_P2P_SOCKET_HOST_H_ |
OLD | NEW |