OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "content/browser/renderer_host/p2p/socket_host.h" | 5 #include "content/browser/renderer_host/p2p/socket_host.h" |
6 | 6 |
7 #include "base/metrics/histogram.h" | |
7 #include "base/sys_byteorder.h" | 8 #include "base/sys_byteorder.h" |
8 #include "content/browser/renderer_host/p2p/socket_host_tcp.h" | 9 #include "content/browser/renderer_host/p2p/socket_host_tcp.h" |
9 #include "content/browser/renderer_host/p2p/socket_host_tcp_server.h" | 10 #include "content/browser/renderer_host/p2p/socket_host_tcp_server.h" |
10 #include "content/browser/renderer_host/p2p/socket_host_udp.h" | 11 #include "content/browser/renderer_host/p2p/socket_host_udp.h" |
11 #include "content/browser/renderer_host/render_process_host_impl.h" | 12 #include "content/browser/renderer_host/render_process_host_impl.h" |
12 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
13 #include "crypto/hmac.h" | 14 #include "crypto/hmac.h" |
14 #include "third_party/libjingle/source/talk/p2p/base/stun.h" | 15 #include "third_party/libjingle/source/talk/p2p/base/stun.h" |
15 #include "third_party/webrtc/base/asyncpacketsocket.h" | 16 #include "third_party/webrtc/base/asyncpacketsocket.h" |
16 #include "third_party/webrtc/base/byteorder.h" | 17 #include "third_party/webrtc/base/byteorder.h" |
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
453 } | 454 } |
454 | 455 |
455 } // packet_processing_helpers | 456 } // packet_processing_helpers |
456 | 457 |
457 P2PSocketHost::P2PSocketHost(IPC::Sender* message_sender, int socket_id) | 458 P2PSocketHost::P2PSocketHost(IPC::Sender* message_sender, int socket_id) |
458 : message_sender_(message_sender), | 459 : message_sender_(message_sender), |
459 id_(socket_id), | 460 id_(socket_id), |
460 state_(STATE_UNINITIALIZED), | 461 state_(STATE_UNINITIALIZED), |
461 dump_incoming_rtp_packet_(false), | 462 dump_incoming_rtp_packet_(false), |
462 dump_outgoing_rtp_packet_(false), | 463 dump_outgoing_rtp_packet_(false), |
463 weak_ptr_factory_(this) { | 464 weak_ptr_factory_(this), |
465 protocol_type_(P2PSocketHost::UNKNOWN), | |
466 send_packets_delayed_total_(0), | |
467 send_packets_total_(0), | |
468 send_bytes_delayed_max_(0), | |
469 send_bytes_delayed_cur_(0) { | |
464 } | 470 } |
465 | 471 |
466 P2PSocketHost::~P2PSocketHost() { } | 472 P2PSocketHost::~P2PSocketHost() { |
473 DCHECK(protocol_type_ != P2PSocketHost::UNKNOWN); | |
davidben
2014/10/27 23:20:26
Nit: DCHECK_NE(protocol_type_, P2pSocketHost::UNKN
davidben
2014/10/27 23:20:26
Seems this should be a parameter to P2PSocketHost'
guoweis2
2014/10/27 23:48:49
Done.
| |
474 | |
475 if (protocol_type_ == P2PSocketHost::UDP) { | |
476 UMA_HISTOGRAM_COUNTS_10000("WebRTC.SystemMaxConsecutiveBytesDelayed_UDP", | |
477 send_bytes_delayed_max_); | |
478 } else { | |
479 UMA_HISTOGRAM_COUNTS_10000("WebRTC.SystemMaxConsecutiveBytesDelayed_TCP", | |
480 send_bytes_delayed_max_); | |
481 } | |
482 | |
483 if (send_packets_total_ > 0) { | |
484 int delay_rate = (send_packets_delayed_total_ * 100) / send_packets_total_; | |
485 if (protocol_type_ == P2PSocketHost::UDP) { | |
486 UMA_HISTOGRAM_PERCENTAGE("WebRTC.SystemPercentPacketsDelayed_UDP", | |
487 delay_rate); | |
488 } else { | |
489 UMA_HISTOGRAM_PERCENTAGE("WebRTC.SystemPercentPacketsDelayed_TCP", | |
490 delay_rate); | |
491 } | |
492 } | |
493 } | |
467 | 494 |
468 // Verifies that the packet |data| has a valid STUN header. | 495 // Verifies that the packet |data| has a valid STUN header. |
469 // static | 496 // static |
470 bool P2PSocketHost::GetStunPacketType( | 497 bool P2PSocketHost::GetStunPacketType( |
471 const char* data, int data_size, StunMessageType* type) { | 498 const char* data, int data_size, StunMessageType* type) { |
472 | 499 |
473 if (data_size < kStunHeaderSize) { | 500 if (data_size < kStunHeaderSize) { |
474 return false; | 501 return false; |
475 } | 502 } |
476 | 503 |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
637 // |packet_dump_callback_| must be called on the UI thread. | 664 // |packet_dump_callback_| must be called on the UI thread. |
638 BrowserThread::PostTask(BrowserThread::UI, | 665 BrowserThread::PostTask(BrowserThread::UI, |
639 FROM_HERE, | 666 FROM_HERE, |
640 base::Bind(packet_dump_callback_, | 667 base::Bind(packet_dump_callback_, |
641 Passed(&packet_header), | 668 Passed(&packet_header), |
642 header_length, | 669 header_length, |
643 packet_length, | 670 packet_length, |
644 incoming)); | 671 incoming)); |
645 } | 672 } |
646 | 673 |
674 void P2PSocketHost::IncrementDelayedPackets() { | |
675 send_packets_delayed_total_++; | |
676 } | |
677 | |
678 void P2PSocketHost::IncrementTotalSentPackets() { | |
679 send_packets_total_++; | |
680 } | |
681 | |
682 void P2PSocketHost::IncrementDelayedBytes(uint32 size) { | |
683 send_bytes_delayed_cur_ += size; | |
684 if (send_bytes_delayed_cur_ > send_bytes_delayed_max_) { | |
685 send_bytes_delayed_max_ = send_bytes_delayed_cur_; | |
686 } | |
687 } | |
688 | |
689 void P2PSocketHost::DecrementDelayedBytes(uint32 size) { | |
690 send_bytes_delayed_cur_ -= size; | |
691 DCHECK_GE(send_bytes_delayed_cur_, 0); | |
692 } | |
693 | |
647 } // namespace content | 694 } // namespace content |
OLD | NEW |