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