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); |
| 474 |
| 475 if (protocol_type_ == P2PSocketHost::UDP) { |
| 476 UMA_HISTOGRAM_COUNTS_10000("WebRTC.MaxSystemConsecutiveDelayedBytes_UDP", |
| 477 send_bytes_delayed_max_); |
| 478 } else { |
| 479 UMA_HISTOGRAM_COUNTS_10000("WebRTC.MaxSystemConsecutiveDelayedBytes_TCP", |
| 480 send_bytes_delayed_max_); |
| 481 } |
| 482 |
| 483 if (send_packets_total_ > 0) { |
| 484 int loss_rate = (send_packets_delayed_total_ * 100) / send_packets_total_; |
| 485 if (protocol_type_ == P2PSocketHost::UDP) { |
| 486 UMA_HISTOGRAM_PERCENTAGE("WebRTC.SystemDelayedPackets_UDP", loss_rate); |
| 487 } else { |
| 488 UMA_HISTOGRAM_PERCENTAGE("WebRTC.SystemDelayedPackets_TCP", loss_rate); |
| 489 } |
| 490 } |
| 491 } |
467 | 492 |
468 // Verifies that the packet |data| has a valid STUN header. | 493 // Verifies that the packet |data| has a valid STUN header. |
469 // static | 494 // static |
470 bool P2PSocketHost::GetStunPacketType( | 495 bool P2PSocketHost::GetStunPacketType( |
471 const char* data, int data_size, StunMessageType* type) { | 496 const char* data, int data_size, StunMessageType* type) { |
472 | 497 |
473 if (data_size < kStunHeaderSize) { | 498 if (data_size < kStunHeaderSize) { |
474 return false; | 499 return false; |
475 } | 500 } |
476 | 501 |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
637 // |packet_dump_callback_| must be called on the UI thread. | 662 // |packet_dump_callback_| must be called on the UI thread. |
638 BrowserThread::PostTask(BrowserThread::UI, | 663 BrowserThread::PostTask(BrowserThread::UI, |
639 FROM_HERE, | 664 FROM_HERE, |
640 base::Bind(packet_dump_callback_, | 665 base::Bind(packet_dump_callback_, |
641 Passed(&packet_header), | 666 Passed(&packet_header), |
642 header_length, | 667 header_length, |
643 packet_length, | 668 packet_length, |
644 incoming)); | 669 incoming)); |
645 } | 670 } |
646 | 671 |
| 672 void P2PSocketHost::IncrementDelayedPackets() { |
| 673 send_packets_delayed_total_++; |
| 674 } |
| 675 |
| 676 void P2PSocketHost::IncrementTotalSentPackets() { |
| 677 send_packets_total_++; |
| 678 } |
| 679 |
| 680 void P2PSocketHost::IncrementDelayedBytes(uint32 size) { |
| 681 send_bytes_delayed_cur_ += size; |
| 682 if (send_bytes_delayed_cur_ > send_bytes_delayed_max_) { |
| 683 send_bytes_delayed_max_ = send_bytes_delayed_cur_; |
| 684 } |
| 685 } |
| 686 |
| 687 void P2PSocketHost::DecrementDelayedBytes(uint32 size) { |
| 688 send_bytes_delayed_cur_ -= size; |
| 689 DCHECK_GE(send_bytes_delayed_cur_, 0); |
| 690 } |
| 691 |
647 } // namespace content | 692 } // namespace content |
OLD | NEW |