OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "net/socket/tcp_socket.h" | 5 #include "net/socket/tcp_socket.h" |
6 #include "net/socket/tcp_socket_win.h" | 6 #include "net/socket/tcp_socket_win.h" |
7 | 7 |
8 #include <mstcpip.h> | 8 #include <mstcpip.h> |
9 | 9 |
10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/metrics/stats_counters.h" | 12 #include "base/metrics/stats_counters.h" |
13 #include "base/profiler/scoped_tracker.h" | 13 #include "base/profiler/scoped_tracker.h" |
14 #include "base/win/windows_version.h" | 14 #include "base/win/windows_version.h" |
15 #include "net/base/address_list.h" | 15 #include "net/base/address_list.h" |
16 #include "net/base/connection_type_histograms.h" | 16 #include "net/base/connection_type_histograms.h" |
17 #include "net/base/io_buffer.h" | 17 #include "net/base/io_buffer.h" |
18 #include "net/base/ip_endpoint.h" | 18 #include "net/base/ip_endpoint.h" |
19 #include "net/base/net_errors.h" | 19 #include "net/base/net_errors.h" |
20 #include "net/base/net_util.h" | 20 #include "net/base/net_util.h" |
| 21 #include "net/base/network_activity_monitor.h" |
21 #include "net/base/network_change_notifier.h" | 22 #include "net/base/network_change_notifier.h" |
22 #include "net/base/winsock_init.h" | 23 #include "net/base/winsock_init.h" |
23 #include "net/base/winsock_util.h" | 24 #include "net/base/winsock_util.h" |
24 #include "net/socket/socket_descriptor.h" | 25 #include "net/socket/socket_descriptor.h" |
25 #include "net/socket/socket_net_log_params.h" | 26 #include "net/socket/socket_net_log_params.h" |
26 | 27 |
27 namespace net { | 28 namespace net { |
28 | 29 |
29 namespace { | 30 namespace { |
30 | 31 |
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
538 // It seems that some winsock interceptors report that more was written | 539 // It seems that some winsock interceptors report that more was written |
539 // than was available. Treat this as an error. http://crbug.com/27870 | 540 // than was available. Treat this as an error. http://crbug.com/27870 |
540 LOG(ERROR) << "Detected broken LSP: Asked to write " << buf_len | 541 LOG(ERROR) << "Detected broken LSP: Asked to write " << buf_len |
541 << " bytes, but " << rv << " bytes reported."; | 542 << " bytes, but " << rv << " bytes reported."; |
542 return ERR_WINSOCK_UNEXPECTED_WRITTEN_BYTES; | 543 return ERR_WINSOCK_UNEXPECTED_WRITTEN_BYTES; |
543 } | 544 } |
544 base::StatsCounter write_bytes("tcp.write_bytes"); | 545 base::StatsCounter write_bytes("tcp.write_bytes"); |
545 write_bytes.Add(rv); | 546 write_bytes.Add(rv); |
546 net_log_.AddByteTransferEvent(NetLog::TYPE_SOCKET_BYTES_SENT, rv, | 547 net_log_.AddByteTransferEvent(NetLog::TYPE_SOCKET_BYTES_SENT, rv, |
547 buf->data()); | 548 buf->data()); |
| 549 NetworkActivityMonitor::GetInstance()->IncrementBytesSent(rv); |
548 return rv; | 550 return rv; |
549 } | 551 } |
550 } else { | 552 } else { |
551 int os_error = WSAGetLastError(); | 553 int os_error = WSAGetLastError(); |
552 if (os_error != WSA_IO_PENDING) { | 554 if (os_error != WSA_IO_PENDING) { |
553 int net_error = MapSystemError(os_error); | 555 int net_error = MapSystemError(os_error); |
554 net_log_.AddEvent(NetLog::TYPE_SOCKET_WRITE_ERROR, | 556 net_log_.AddEvent(NetLog::TYPE_SOCKET_WRITE_ERROR, |
555 CreateNetLogSocketErrorCallback(net_error, os_error)); | 557 CreateNetLogSocketErrorCallback(net_error, os_error)); |
556 return net_error; | 558 return net_error; |
557 } | 559 } |
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
906 NetLog::TYPE_SOCKET_READ_ERROR, | 908 NetLog::TYPE_SOCKET_READ_ERROR, |
907 CreateNetLogSocketErrorCallback(net_error, os_error)); | 909 CreateNetLogSocketErrorCallback(net_error, os_error)); |
908 return net_error; | 910 return net_error; |
909 } | 911 } |
910 } else { | 912 } else { |
911 base::StatsCounter read_bytes("tcp.read_bytes"); | 913 base::StatsCounter read_bytes("tcp.read_bytes"); |
912 if (rv > 0) | 914 if (rv > 0) |
913 read_bytes.Add(rv); | 915 read_bytes.Add(rv); |
914 net_log_.AddByteTransferEvent(NetLog::TYPE_SOCKET_BYTES_RECEIVED, rv, | 916 net_log_.AddByteTransferEvent(NetLog::TYPE_SOCKET_BYTES_RECEIVED, rv, |
915 buf->data()); | 917 buf->data()); |
| 918 NetworkActivityMonitor::GetInstance()->IncrementBytesReceived(rv); |
916 return rv; | 919 return rv; |
917 } | 920 } |
918 | 921 |
919 waiting_read_ = true; | 922 waiting_read_ = true; |
920 read_callback_ = callback; | 923 read_callback_ = callback; |
921 core_->read_iobuffer_ = buf; | 924 core_->read_iobuffer_ = buf; |
922 core_->read_buffer_length_ = buf_len; | 925 core_->read_buffer_length_ = buf_len; |
923 core_->WatchForRead(); | 926 core_->WatchForRead(); |
924 return ERR_IO_PENDING; | 927 return ERR_IO_PENDING; |
925 } | 928 } |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
975 // than was available. Treat this as an error. http://crbug.com/27870 | 978 // than was available. Treat this as an error. http://crbug.com/27870 |
976 LOG(ERROR) << "Detected broken LSP: Asked to write " | 979 LOG(ERROR) << "Detected broken LSP: Asked to write " |
977 << core_->write_buffer_length_ << " bytes, but " << rv | 980 << core_->write_buffer_length_ << " bytes, but " << rv |
978 << " bytes reported."; | 981 << " bytes reported."; |
979 rv = ERR_WINSOCK_UNEXPECTED_WRITTEN_BYTES; | 982 rv = ERR_WINSOCK_UNEXPECTED_WRITTEN_BYTES; |
980 } else { | 983 } else { |
981 base::StatsCounter write_bytes("tcp.write_bytes"); | 984 base::StatsCounter write_bytes("tcp.write_bytes"); |
982 write_bytes.Add(num_bytes); | 985 write_bytes.Add(num_bytes); |
983 net_log_.AddByteTransferEvent(NetLog::TYPE_SOCKET_BYTES_SENT, num_bytes, | 986 net_log_.AddByteTransferEvent(NetLog::TYPE_SOCKET_BYTES_SENT, num_bytes, |
984 core_->write_iobuffer_->data()); | 987 core_->write_iobuffer_->data()); |
| 988 NetworkActivityMonitor::GetInstance()->IncrementBytesSent(num_bytes); |
985 } | 989 } |
986 } | 990 } |
987 | 991 |
988 core_->write_iobuffer_ = NULL; | 992 core_->write_iobuffer_ = NULL; |
989 | 993 |
990 DCHECK_NE(rv, ERR_IO_PENDING); | 994 DCHECK_NE(rv, ERR_IO_PENDING); |
991 base::ResetAndReturn(&write_callback_).Run(rv); | 995 base::ResetAndReturn(&write_callback_).Run(rv); |
992 } | 996 } |
993 | 997 |
994 void TCPSocketWin::DidSignalRead() { | 998 void TCPSocketWin::DidSignalRead() { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1034 core_->read_buffer_length_ = 0; | 1038 core_->read_buffer_length_ = 0; |
1035 | 1039 |
1036 DCHECK_NE(rv, ERR_IO_PENDING); | 1040 DCHECK_NE(rv, ERR_IO_PENDING); |
1037 // TODO(vadimt): Remove ScopedTracker below once crbug.com/418183 is fixed. | 1041 // TODO(vadimt): Remove ScopedTracker below once crbug.com/418183 is fixed. |
1038 tracked_objects::ScopedTracker tracking_profile( | 1042 tracked_objects::ScopedTracker tracking_profile( |
1039 FROM_HERE_WITH_EXPLICIT_FUNCTION("TCPSocketWin::DidSignalRead")); | 1043 FROM_HERE_WITH_EXPLICIT_FUNCTION("TCPSocketWin::DidSignalRead")); |
1040 base::ResetAndReturn(&read_callback_).Run(rv); | 1044 base::ResetAndReturn(&read_callback_).Run(rv); |
1041 } | 1045 } |
1042 | 1046 |
1043 } // namespace net | 1047 } // namespace net |
OLD | NEW |