| 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 "chrome/browser/net/network_stats.h" | 5 #include "chrome/browser/net/network_stats.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/metrics/field_trial.h" | 10 #include "base/metrics/field_trial.h" |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 if (rv != net::ERR_IO_PENDING) | 263 if (rv != net::ERR_IO_PENDING) |
| 264 Finish(WRITE_FAILED, rv); | 264 Finish(WRITE_FAILED, rv); |
| 265 break; | 265 break; |
| 266 } | 266 } |
| 267 DCHECK_EQ(bytes_to_send_, 0u); | 267 DCHECK_EQ(bytes_to_send_, 0u); |
| 268 }; | 268 }; |
| 269 } | 269 } |
| 270 | 270 |
| 271 void NetworkStats::SendNextPacketAfterDelay() { | 271 void NetworkStats::SendNextPacketAfterDelay() { |
| 272 if (current_test_ == PACED_PACKET_TEST) { | 272 if (current_test_ == PACED_PACKET_TEST) { |
| 273 MessageLoop::current()->PostDelayedTask( | 273 base::MessageLoop::current()->PostDelayedTask( |
| 274 FROM_HERE, | 274 FROM_HERE, |
| 275 base::Bind(&NetworkStats::SendPacket, weak_factory_.GetWeakPtr()), | 275 base::Bind(&NetworkStats::SendPacket, weak_factory_.GetWeakPtr()), |
| 276 average_time_); | 276 average_time_); |
| 277 return; | 277 return; |
| 278 } | 278 } |
| 279 | 279 |
| 280 MessageLoop::current()->PostTask( | 280 base::MessageLoop::current()->PostTask( |
| 281 FROM_HERE, | 281 FROM_HERE, |
| 282 base::Bind(&NetworkStats::SendPacket, weak_factory_.GetWeakPtr())); | 282 base::Bind(&NetworkStats::SendPacket, weak_factory_.GetWeakPtr())); |
| 283 } | 283 } |
| 284 | 284 |
| 285 bool NetworkStats::ReadComplete(int result) { | 285 bool NetworkStats::ReadComplete(int result) { |
| 286 DCHECK(socket_.get()); | 286 DCHECK(socket_.get()); |
| 287 DCHECK_NE(net::ERR_IO_PENDING, result); | 287 DCHECK_NE(net::ERR_IO_PENDING, result); |
| 288 if (result < 0) { | 288 if (result < 0) { |
| 289 Finish(READ_FAILED, result); | 289 Finish(READ_FAILED, result); |
| 290 return true; | 290 return true; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 } | 322 } |
| 323 return false; | 323 return false; |
| 324 } | 324 } |
| 325 | 325 |
| 326 void NetworkStats::OnReadComplete(int result) { | 326 void NetworkStats::OnReadComplete(int result) { |
| 327 if (!ReadComplete(result)) { | 327 if (!ReadComplete(result)) { |
| 328 // Called ReadData() via PostDelayedTask() to avoid recursion. Added a delay | 328 // Called ReadData() via PostDelayedTask() to avoid recursion. Added a delay |
| 329 // of 1ms so that the time-out will fire before we have time to really hog | 329 // of 1ms so that the time-out will fire before we have time to really hog |
| 330 // the CPU too extensively (waiting for the time-out) in case of an infinite | 330 // the CPU too extensively (waiting for the time-out) in case of an infinite |
| 331 // loop. | 331 // loop. |
| 332 MessageLoop::current()->PostDelayedTask( | 332 base::MessageLoop::current()->PostDelayedTask( |
| 333 FROM_HERE, | 333 FROM_HERE, |
| 334 base::Bind(&NetworkStats::ReadData, weak_factory_.GetWeakPtr()), | 334 base::Bind(&NetworkStats::ReadData, weak_factory_.GetWeakPtr()), |
| 335 base::TimeDelta::FromMilliseconds(1)); | 335 base::TimeDelta::FromMilliseconds(1)); |
| 336 } | 336 } |
| 337 } | 337 } |
| 338 | 338 |
| 339 void NetworkStats::OnWriteComplete(int result) { | 339 void NetworkStats::OnWriteComplete(int result) { |
| 340 DCHECK(socket_.get()); | 340 DCHECK(socket_.get()); |
| 341 DCHECK_NE(net::ERR_IO_PENDING, result); | 341 DCHECK_NE(net::ERR_IO_PENDING, result); |
| 342 if (result < 0) { | 342 if (result < 0) { |
| 343 Finish(WRITE_FAILED, result); | 343 Finish(WRITE_FAILED, result); |
| 344 return; | 344 return; |
| 345 } | 345 } |
| 346 | 346 |
| 347 DidSendData(result); | 347 DidSendData(result); |
| 348 if (bytes_to_send_) { | 348 if (bytes_to_send_) { |
| 349 int rv = SendData(); | 349 int rv = SendData(); |
| 350 if (rv < 0) { | 350 if (rv < 0) { |
| 351 if (rv != net::ERR_IO_PENDING) | 351 if (rv != net::ERR_IO_PENDING) |
| 352 Finish(WRITE_FAILED, rv); | 352 Finish(WRITE_FAILED, rv); |
| 353 return; | 353 return; |
| 354 } | 354 } |
| 355 DCHECK_EQ(rv, net::OK); | 355 DCHECK_EQ(rv, net::OK); |
| 356 DCHECK_EQ(bytes_to_send_, 0u); | 356 DCHECK_EQ(bytes_to_send_, 0u); |
| 357 } | 357 } |
| 358 | 358 |
| 359 MessageLoop::current()->PostTask( | 359 base::MessageLoop::current()->PostTask( |
| 360 FROM_HERE, | 360 FROM_HERE, |
| 361 base::Bind(&NetworkStats::SendPacket, weak_factory_.GetWeakPtr())); | 361 base::Bind(&NetworkStats::SendPacket, weak_factory_.GetWeakPtr())); |
| 362 } | 362 } |
| 363 | 363 |
| 364 void NetworkStats::ReadData() { | 364 void NetworkStats::ReadData() { |
| 365 int rv; | 365 int rv; |
| 366 do { | 366 do { |
| 367 if (!socket_.get()) | 367 if (!socket_.get()) |
| 368 break; | 368 break; |
| 369 | 369 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 } | 430 } |
| 431 | 431 |
| 432 void NetworkStats::DidSendData(int bytes_sent) { | 432 void NetworkStats::DidSendData(int bytes_sent) { |
| 433 write_buffer_->DidConsume(bytes_sent); | 433 write_buffer_->DidConsume(bytes_sent); |
| 434 if (!write_buffer_->BytesRemaining()) | 434 if (!write_buffer_->BytesRemaining()) |
| 435 write_buffer_ = NULL; | 435 write_buffer_ = NULL; |
| 436 bytes_to_send_ -= bytes_sent; | 436 bytes_to_send_ -= bytes_sent; |
| 437 } | 437 } |
| 438 | 438 |
| 439 void NetworkStats::StartReadDataTimer(int milliseconds) { | 439 void NetworkStats::StartReadDataTimer(int milliseconds) { |
| 440 MessageLoop::current()->PostDelayedTask( | 440 base::MessageLoop::current()->PostDelayedTask( |
| 441 FROM_HERE, | 441 FROM_HERE, |
| 442 base::Bind(&NetworkStats::OnReadDataTimeout, | 442 base::Bind(&NetworkStats::OnReadDataTimeout, |
| 443 weak_factory_.GetWeakPtr(), | 443 weak_factory_.GetWeakPtr(), |
| 444 base_packet_number_), | 444 base_packet_number_), |
| 445 base::TimeDelta::FromMilliseconds(milliseconds)); | 445 base::TimeDelta::FromMilliseconds(milliseconds)); |
| 446 } | 446 } |
| 447 | 447 |
| 448 void NetworkStats::OnReadDataTimeout(uint32 test_base_packet_number) { | 448 void NetworkStats::OnReadDataTimeout(uint32 test_base_packet_number) { |
| 449 if (test_base_packet_number != base_packet_number_) | 449 if (test_base_packet_number != base_packet_number_) |
| 450 return; | 450 return; |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 647 void NetworkStats::Finish(Status status, int result) { | 647 void NetworkStats::Finish(Status status, int result) { |
| 648 // Set the base_packet_number_ for the start of next test. Changing the | 648 // Set the base_packet_number_ for the start of next test. Changing the |
| 649 // |base_packet_number_| indicates to OnReadDataTimeout that the Finish has | 649 // |base_packet_number_| indicates to OnReadDataTimeout that the Finish has |
| 650 // already been called for the test and that it doesn't need to call Finish | 650 // already been called for the test and that it doesn't need to call Finish |
| 651 // again. | 651 // again. |
| 652 base_packet_number_ = packet_number_ + 1; | 652 base_packet_number_ = packet_number_ + 1; |
| 653 RecordHistograms(PROTOCOL_UDP, status, result); | 653 RecordHistograms(PROTOCOL_UDP, status, result); |
| 654 | 654 |
| 655 if (next_test() == NON_PACED_PACKET_TEST || | 655 if (next_test() == NON_PACED_PACKET_TEST || |
| 656 next_test() == PACED_PACKET_TEST) { | 656 next_test() == PACED_PACKET_TEST) { |
| 657 MessageLoop::current()->PostTask( | 657 base::MessageLoop::current()->PostTask( |
| 658 FROM_HERE, | 658 FROM_HERE, |
| 659 base::Bind(&NetworkStats::RestartPacketTest, | 659 base::Bind(&NetworkStats::RestartPacketTest, |
| 660 weak_factory_.GetWeakPtr())); | 660 weak_factory_.GetWeakPtr())); |
| 661 return; | 661 return; |
| 662 } | 662 } |
| 663 | 663 |
| 664 DoFinishCallback(result); | 664 DoFinishCallback(result); |
| 665 | 665 |
| 666 // Close the socket so that there are no more IO operations. | 666 // Close the socket so that there are no more IO operations. |
| 667 net::UDPClientSocket* udp_socket = | 667 net::UDPClientSocket* udp_socket = |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1017 udp_stats_client->Start( | 1017 udp_stats_client->Start( |
| 1018 host_resolver, server_address, histogram_port, has_proxy_server, | 1018 host_resolver, server_address, histogram_port, has_proxy_server, |
| 1019 kLargeTestBytesToSend, kMaximumSequentialPackets, | 1019 kLargeTestBytesToSend, kMaximumSequentialPackets, |
| 1020 net::CompletionCallback()); | 1020 net::CompletionCallback()); |
| 1021 } | 1021 } |
| 1022 break; | 1022 break; |
| 1023 } | 1023 } |
| 1024 } | 1024 } |
| 1025 | 1025 |
| 1026 } // namespace chrome_browser_net | 1026 } // namespace chrome_browser_net |
| OLD | NEW |