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/metrics/histogram.h" |
8 #include "base/sys_byteorder.h" | 8 #include "base/sys_byteorder.h" |
9 #include "content/browser/renderer_host/p2p/socket_host_tcp.h" | 9 #include "content/browser/renderer_host/p2p/socket_host_tcp.h" |
10 #include "content/browser/renderer_host/p2p/socket_host_tcp_server.h" | 10 #include "content/browser/renderer_host/p2p/socket_host_tcp_server.h" |
(...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
631 if (!valid) { | 631 if (!valid) { |
632 DCHECK(false); | 632 DCHECK(false); |
633 return; | 633 return; |
634 } | 634 } |
635 | 635 |
636 scoped_ptr<uint8[]> header_buffer(new uint8[header_length]); | 636 scoped_ptr<uint8[]> header_buffer(new uint8[header_length]); |
637 memcpy(header_buffer.get(), packet, header_length); | 637 memcpy(header_buffer.get(), packet, header_length); |
638 | 638 |
639 // Posts to the IO thread as the data members should be accessed on the IO | 639 // Posts to the IO thread as the data members should be accessed on the IO |
640 // thread only. | 640 // thread only. |
641 BrowserThread::PostTask(BrowserThread::IO, | 641 BrowserThread::PostTask( |
642 FROM_HERE, | 642 BrowserThread::IO, FROM_HERE, |
643 base::Bind(&P2PSocketHost::DumpRtpPacketOnIOThread, | 643 base::Bind(&P2PSocketHost::DumpRtpPacketOnIOThread, |
644 weak_ptr_factory_.GetWeakPtr(), | 644 weak_ptr_factory_.GetWeakPtr(), base::Passed(&header_buffer), |
645 Passed(&header_buffer), | 645 header_length, rtp_packet_length, incoming)); |
646 header_length, | |
647 rtp_packet_length, | |
648 incoming)); | |
649 } | 646 } |
650 | 647 |
651 void P2PSocketHost::DumpRtpPacketOnIOThread(scoped_ptr<uint8[]> packet_header, | 648 void P2PSocketHost::DumpRtpPacketOnIOThread(scoped_ptr<uint8[]> packet_header, |
652 size_t header_length, | 649 size_t header_length, |
653 size_t packet_length, | 650 size_t packet_length, |
654 bool incoming) { | 651 bool incoming) { |
655 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 652 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
656 | 653 |
657 if ((incoming && !dump_incoming_rtp_packet_) || | 654 if ((incoming && !dump_incoming_rtp_packet_) || |
658 (!incoming && !dump_outgoing_rtp_packet_) || | 655 (!incoming && !dump_outgoing_rtp_packet_) || |
659 packet_dump_callback_.is_null()) { | 656 packet_dump_callback_.is_null()) { |
660 return; | 657 return; |
661 } | 658 } |
662 | 659 |
663 // |packet_dump_callback_| must be called on the UI thread. | 660 // |packet_dump_callback_| must be called on the UI thread. |
664 BrowserThread::PostTask(BrowserThread::UI, | 661 BrowserThread::PostTask( |
665 FROM_HERE, | 662 BrowserThread::UI, FROM_HERE, |
666 base::Bind(packet_dump_callback_, | 663 base::Bind(packet_dump_callback_, base::Passed(&packet_header), |
667 Passed(&packet_header), | 664 header_length, packet_length, incoming)); |
668 header_length, | |
669 packet_length, | |
670 incoming)); | |
671 } | 665 } |
672 | 666 |
673 void P2PSocketHost::IncrementDelayedPackets() { | 667 void P2PSocketHost::IncrementDelayedPackets() { |
674 send_packets_delayed_total_++; | 668 send_packets_delayed_total_++; |
675 } | 669 } |
676 | 670 |
677 void P2PSocketHost::IncrementTotalSentPackets() { | 671 void P2PSocketHost::IncrementTotalSentPackets() { |
678 send_packets_total_++; | 672 send_packets_total_++; |
679 } | 673 } |
680 | 674 |
681 void P2PSocketHost::IncrementDelayedBytes(uint32 size) { | 675 void P2PSocketHost::IncrementDelayedBytes(uint32 size) { |
682 send_bytes_delayed_cur_ += size; | 676 send_bytes_delayed_cur_ += size; |
683 if (send_bytes_delayed_cur_ > send_bytes_delayed_max_) { | 677 if (send_bytes_delayed_cur_ > send_bytes_delayed_max_) { |
684 send_bytes_delayed_max_ = send_bytes_delayed_cur_; | 678 send_bytes_delayed_max_ = send_bytes_delayed_cur_; |
685 } | 679 } |
686 } | 680 } |
687 | 681 |
688 void P2PSocketHost::DecrementDelayedBytes(uint32 size) { | 682 void P2PSocketHost::DecrementDelayedBytes(uint32 size) { |
689 send_bytes_delayed_cur_ -= size; | 683 send_bytes_delayed_cur_ -= size; |
690 DCHECK_GE(send_bytes_delayed_cur_, 0); | 684 DCHECK_GE(send_bytes_delayed_cur_, 0); |
691 } | 685 } |
692 | 686 |
693 } // namespace content | 687 } // namespace content |
OLD | NEW |