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

Unified Diff: trunk/src/content/browser/renderer_host/p2p/socket_host.cc

Issue 307063003: Revert 273745 "Implements RTP header dumping." due to memory leak (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: trunk/src/content/browser/renderer_host/p2p/socket_host.cc
===================================================================
--- trunk/src/content/browser/renderer_host/p2p/socket_host.cc (revision 273764)
+++ trunk/src/content/browser/renderer_host/p2p/socket_host.cc (working copy)
@@ -8,8 +8,6 @@
#include "content/browser/renderer_host/p2p/socket_host_tcp.h"
#include "content/browser/renderer_host/p2p/socket_host_tcp_server.h"
#include "content/browser/renderer_host/p2p/socket_host_udp.h"
-#include "content/browser/renderer_host/render_process_host_impl.h"
-#include "content/public/browser/browser_thread.h"
#include "crypto/hmac.h"
#include "third_party/libjingle/source/talk/base/asyncpacketsocket.h"
#include "third_party/libjingle/source/talk/base/byteorder.h"
@@ -57,10 +55,7 @@
}
// Verifies rtp header and message length.
-bool ValidateRtpHeader(const char* rtp, int length, size_t* header_length) {
- if (header_length)
- *header_length = 0;
-
+bool ValidateRtpHeader(char* rtp, int length) {
int cc_count = rtp[0] & 0x0F;
int rtp_hdr_len_without_extn = kMinRtpHdrLen + 4 * cc_count;
if (rtp_hdr_len_without_extn > length) {
@@ -70,9 +65,6 @@
// If extension bit is not set, we are done with header processing, as input
// length is verified above.
if (!(rtp[0] & 0x10)) {
- if (header_length)
- *header_length = rtp_hdr_len_without_extn;
-
return true;
}
@@ -86,9 +78,6 @@
if (rtp_hdr_len_without_extn + kRtpExtnHdrLen + extn_length > length) {
return false;
}
-
- if (header_length)
- *header_length = rtp_hdr_len_without_extn + kRtpExtnHdrLen + extn_length;
return true;
}
@@ -217,10 +206,8 @@
return true;
}
-bool GetRtpPacketStartPositionAndLength(const char* packet,
- int length,
- int* rtp_start_pos,
- int* rtp_packet_length) {
+bool GetRtpPacketStartPositionAndLength(
+ char* packet, int length, int* rtp_start_pos, int* rtp_packet_length) {
int rtp_begin, rtp_length;
if (IsTurnChannelData(packet)) {
// Turn Channel Message header format.
@@ -256,7 +243,7 @@
// First skip mandatory stun header which is of 20 bytes.
rtp_begin = P2PSocketHost::kStunHeaderSize;
// Loop through STUN attributes until we find STUN DATA attribute.
- const char* start = packet + rtp_begin;
+ char* start = packet + rtp_begin;
bool data_attr_present = false;
while ((packet + rtp_begin) - start < stun_msg_len) {
// Keep reading STUN attributes until we hit DATA attribute.
@@ -316,7 +303,7 @@
// Making sure we have a valid RTP packet at the end.
if (!(rtp_length < kMinRtpHdrLen) &&
IsRtpPacket(packet + rtp_begin, rtp_length) &&
- ValidateRtpHeader(packet + rtp_begin, rtp_length, NULL)) {
+ ValidateRtpHeader(packet + rtp_begin, rtp_length)) {
*rtp_start_pos = rtp_begin;
*rtp_packet_length = rtp_length;
return true;
@@ -402,13 +389,11 @@
} // packet_processing_helpers
-P2PSocketHost::P2PSocketHost(IPC::Sender* message_sender, int socket_id)
+P2PSocketHost::P2PSocketHost(IPC::Sender* message_sender,
+ int id)
: message_sender_(message_sender),
- id_(socket_id),
- state_(STATE_UNINITIALIZED),
- dump_incoming_rtp_packet_(false),
- dump_outgoing_rtp_packet_(false),
- weak_ptr_factory_(this) {
+ id_(id),
+ state_(STATE_UNINITIALIZED) {
}
P2PSocketHost::~P2PSocketHost() { }
@@ -461,125 +446,34 @@
}
// static
-P2PSocketHost* P2PSocketHost::Create(IPC::Sender* message_sender,
- int socket_id,
- P2PSocketType type,
- net::URLRequestContextGetter* url_context,
- P2PMessageThrottler* throttler) {
+P2PSocketHost* P2PSocketHost::Create(
+ IPC::Sender* message_sender, int id, P2PSocketType type,
+ net::URLRequestContextGetter* url_context,
+ P2PMessageThrottler* throttler) {
switch (type) {
case P2P_SOCKET_UDP:
- return new P2PSocketHostUdp(message_sender, socket_id, throttler);
+ return new P2PSocketHostUdp(message_sender, id, throttler);
case P2P_SOCKET_TCP_SERVER:
return new P2PSocketHostTcpServer(
- message_sender, socket_id, P2P_SOCKET_TCP_CLIENT);
+ message_sender, id, P2P_SOCKET_TCP_CLIENT);
case P2P_SOCKET_STUN_TCP_SERVER:
return new P2PSocketHostTcpServer(
- message_sender, socket_id, P2P_SOCKET_STUN_TCP_CLIENT);
+ message_sender, id, P2P_SOCKET_STUN_TCP_CLIENT);
case P2P_SOCKET_TCP_CLIENT:
case P2P_SOCKET_SSLTCP_CLIENT:
case P2P_SOCKET_TLS_CLIENT:
- return new P2PSocketHostTcp(message_sender, socket_id, type, url_context);
+ return new P2PSocketHostTcp(message_sender, id, type, url_context);
case P2P_SOCKET_STUN_TCP_CLIENT:
case P2P_SOCKET_STUN_SSLTCP_CLIENT:
case P2P_SOCKET_STUN_TLS_CLIENT:
- return new P2PSocketHostStunTcp(
- message_sender, socket_id, type, url_context);
+ return new P2PSocketHostStunTcp(message_sender, id, type, url_context);
}
NOTREACHED();
return NULL;
}
-void P2PSocketHost::StartRtpDump(
- bool incoming,
- bool outgoing,
- const RenderProcessHost::WebRtcRtpPacketCallback& packet_callback) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- DCHECK(!packet_callback.is_null());
- DCHECK(incoming || outgoing);
-
- if (incoming)
- dump_incoming_rtp_packet_ = true;
-
- if (outgoing)
- dump_outgoing_rtp_packet_ = true;
-
- packet_dump_callback_ = packet_callback;
-}
-
-void P2PSocketHost::StopRtpDump(bool incoming, bool outgoing) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- DCHECK(incoming || outgoing);
-
- if (incoming)
- dump_incoming_rtp_packet_ = false;
-
- if (outgoing)
- dump_outgoing_rtp_packet_ = false;
-
- if (!dump_incoming_rtp_packet_ && !dump_outgoing_rtp_packet_)
- packet_dump_callback_.Reset();
-}
-
-void P2PSocketHost::DumpRtpPacket(const char* packet,
- size_t length,
- bool incoming) {
- if (IsDtlsPacket(packet, length) || IsRtcpPacket(packet))
- return;
-
- int rtp_packet_pos = 0;
- int rtp_packet_length = length;
- if (!packet_processing_helpers::GetRtpPacketStartPositionAndLength(
- packet, length, &rtp_packet_pos, &rtp_packet_length))
- return;
-
- packet += rtp_packet_pos;
-
- size_t header_length = 0;
- bool valid = ValidateRtpHeader(packet, rtp_packet_length, &header_length);
- if (!valid) {
- DCHECK(false);
- return;
- }
-
- scoped_ptr<uint8[]> header_buffer(new uint8[header_length]);
- memcpy(header_buffer.get(), packet, header_length);
-
- // Posts to the IO thread as the data members should be accessed on the IO
- // thread only.
- BrowserThread::PostTask(BrowserThread::IO,
- FROM_HERE,
- base::Bind(&P2PSocketHost::DumpRtpPacketOnIOThread,
- weak_ptr_factory_.GetWeakPtr(),
- Passed(&header_buffer),
- header_length,
- rtp_packet_length,
- incoming));
-}
-
-void P2PSocketHost::DumpRtpPacketOnIOThread(scoped_ptr<uint8[]> packet_header,
- size_t header_length,
- size_t packet_length,
- bool incoming) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
-
- if ((incoming && !dump_incoming_rtp_packet_) ||
- (!incoming && !dump_outgoing_rtp_packet_) ||
- packet_dump_callback_.is_null()) {
- return;
- }
-
- // |packet_dump_callback_| must be called on the UI thread.
- BrowserThread::PostTask(BrowserThread::UI,
- FROM_HERE,
- base::Bind(packet_dump_callback_,
- packet_header.get(),
- header_length,
- packet_length,
- incoming));
-}
-
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698