| 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 "net/dns/dns_transaction.h" | 5 #include "net/dns/dns_transaction.h" |
| 6 | 6 |
| 7 #include <deque> | 7 #include <deque> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/big_endian.h" |
| 11 #include "base/bind.h" | 12 #include "base/bind.h" |
| 12 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/memory/scoped_vector.h" | 15 #include "base/memory/scoped_vector.h" |
| 15 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
| 16 #include "base/message_loop/message_loop.h" | 17 #include "base/message_loop/message_loop.h" |
| 17 #include "base/metrics/histogram.h" | 18 #include "base/metrics/histogram.h" |
| 18 #include "base/rand_util.h" | 19 #include "base/rand_util.h" |
| 19 #include "base/stl_util.h" | 20 #include "base/stl_util.h" |
| 20 #include "base/strings/string_piece.h" | 21 #include "base/strings/string_piece.h" |
| 21 #include "base/threading/non_thread_safe.h" | 22 #include "base/threading/non_thread_safe.h" |
| 22 #include "base/timer/timer.h" | 23 #include "base/timer/timer.h" |
| 23 #include "base/values.h" | 24 #include "base/values.h" |
| 24 #include "net/base/big_endian.h" | |
| 25 #include "net/base/completion_callback.h" | 25 #include "net/base/completion_callback.h" |
| 26 #include "net/base/dns_util.h" | 26 #include "net/base/dns_util.h" |
| 27 #include "net/base/io_buffer.h" | 27 #include "net/base/io_buffer.h" |
| 28 #include "net/base/ip_endpoint.h" | 28 #include "net/base/ip_endpoint.h" |
| 29 #include "net/base/net_errors.h" | 29 #include "net/base/net_errors.h" |
| 30 #include "net/base/net_log.h" | 30 #include "net/base/net_log.h" |
| 31 #include "net/dns/dns_protocol.h" | 31 #include "net/dns/dns_protocol.h" |
| 32 #include "net/dns/dns_query.h" | 32 #include "net/dns/dns_query.h" |
| 33 #include "net/dns/dns_response.h" | 33 #include "net/dns/dns_response.h" |
| 34 #include "net/dns/dns_session.h" | 34 #include "net/dns/dns_session.h" |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 base::TimeTicks::Now() - start_time_); | 381 base::TimeTicks::Now() - start_time_); |
| 382 } | 382 } |
| 383 return rv; | 383 return rv; |
| 384 } | 384 } |
| 385 | 385 |
| 386 int DoConnectComplete(int rv) { | 386 int DoConnectComplete(int rv) { |
| 387 DCHECK_NE(ERR_IO_PENDING, rv); | 387 DCHECK_NE(ERR_IO_PENDING, rv); |
| 388 if (rv < 0) | 388 if (rv < 0) |
| 389 return rv; | 389 return rv; |
| 390 | 390 |
| 391 WriteBigEndian<uint16>(length_buffer_->data(), query_->io_buffer()->size()); | 391 base::WriteBigEndian<uint16>(length_buffer_->data(), |
| 392 query_->io_buffer()->size()); |
| 392 buffer_ = | 393 buffer_ = |
| 393 new DrainableIOBuffer(length_buffer_.get(), length_buffer_->size()); | 394 new DrainableIOBuffer(length_buffer_.get(), length_buffer_->size()); |
| 394 next_state_ = STATE_SEND_LENGTH; | 395 next_state_ = STATE_SEND_LENGTH; |
| 395 return OK; | 396 return OK; |
| 396 } | 397 } |
| 397 | 398 |
| 398 int DoSendLength(int rv) { | 399 int DoSendLength(int rv) { |
| 399 DCHECK_NE(ERR_IO_PENDING, rv); | 400 DCHECK_NE(ERR_IO_PENDING, rv); |
| 400 if (rv < 0) | 401 if (rv < 0) |
| 401 return rv; | 402 return rv; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 return rv; | 440 return rv; |
| 440 | 441 |
| 441 buffer_->DidConsume(rv); | 442 buffer_->DidConsume(rv); |
| 442 if (buffer_->BytesRemaining() > 0) { | 443 if (buffer_->BytesRemaining() > 0) { |
| 443 next_state_ = STATE_READ_LENGTH; | 444 next_state_ = STATE_READ_LENGTH; |
| 444 return socket_->Read( | 445 return socket_->Read( |
| 445 buffer_.get(), | 446 buffer_.get(), |
| 446 buffer_->BytesRemaining(), | 447 buffer_->BytesRemaining(), |
| 447 base::Bind(&DnsTCPAttempt::OnIOComplete, base::Unretained(this))); | 448 base::Bind(&DnsTCPAttempt::OnIOComplete, base::Unretained(this))); |
| 448 } | 449 } |
| 449 ReadBigEndian<uint16>(length_buffer_->data(), &response_length_); | 450 base::ReadBigEndian<uint16>(length_buffer_->data(), &response_length_); |
| 450 // Check if advertised response is too short. (Optimization only.) | 451 // Check if advertised response is too short. (Optimization only.) |
| 451 if (response_length_ < query_->io_buffer()->size()) | 452 if (response_length_ < query_->io_buffer()->size()) |
| 452 return ERR_DNS_MALFORMED_RESPONSE; | 453 return ERR_DNS_MALFORMED_RESPONSE; |
| 453 // Allocate more space so that DnsResponse::InitParse sanity check passes. | 454 // Allocate more space so that DnsResponse::InitParse sanity check passes. |
| 454 response_.reset(new DnsResponse(response_length_ + 1)); | 455 response_.reset(new DnsResponse(response_length_ + 1)); |
| 455 buffer_ = new DrainableIOBuffer(response_->io_buffer(), response_length_); | 456 buffer_ = new DrainableIOBuffer(response_->io_buffer(), response_length_); |
| 456 next_state_ = STATE_READ_RESPONSE; | 457 next_state_ = STATE_READ_RESPONSE; |
| 457 return OK; | 458 return OK; |
| 458 } | 459 } |
| 459 | 460 |
| (...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 954 } // namespace | 955 } // namespace |
| 955 | 956 |
| 956 // static | 957 // static |
| 957 scoped_ptr<DnsTransactionFactory> DnsTransactionFactory::CreateFactory( | 958 scoped_ptr<DnsTransactionFactory> DnsTransactionFactory::CreateFactory( |
| 958 DnsSession* session) { | 959 DnsSession* session) { |
| 959 return scoped_ptr<DnsTransactionFactory>( | 960 return scoped_ptr<DnsTransactionFactory>( |
| 960 new DnsTransactionFactoryImpl(session)); | 961 new DnsTransactionFactoryImpl(session)); |
| 961 } | 962 } |
| 962 | 963 |
| 963 } // namespace net | 964 } // namespace net |
| OLD | NEW |