| 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 <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/big_endian.h" | 13 #include "base/big_endian.h" |
| 14 #include "base/bind.h" | 14 #include "base/bind.h" |
| 15 #include "base/location.h" | 15 #include "base/location.h" |
| 16 #include "base/macros.h" | 16 #include "base/macros.h" |
| 17 #include "base/memory/ptr_util.h" | 17 #include "base/memory/ptr_util.h" |
| 18 #include "base/memory/ref_counted.h" | 18 #include "base/memory/ref_counted.h" |
| 19 #include "base/memory/weak_ptr.h" | 19 #include "base/memory/weak_ptr.h" |
| 20 #include "base/metrics/histogram_macros.h" | 20 #include "base/metrics/histogram_macros.h" |
| 21 #include "base/profiler/scoped_tracker.h" | 21 #include "base/profiler/scoped_tracker.h" |
| 22 #include "base/rand_util.h" | 22 #include "base/rand_util.h" |
| 23 #include "base/single_thread_task_runner.h" | 23 #include "base/single_thread_task_runner.h" |
| 24 #include "base/stl_util.h" | 24 #include "base/stl_util.h" |
| 25 #include "base/strings/string_piece.h" | 25 #include "base/strings/string_piece.h" |
| 26 #include "base/threading/non_thread_safe.h" | 26 #include "base/threading/non_thread_safe.h" |
| 27 #include "base/threading/thread_task_runner_handle.h" | 27 #include "base/threading/thread_task_runner_handle.h" |
| 28 #include "base/timer/timer.h" | 28 #include "base/timer/timer.h" |
| 29 #include "base/trace_event/trace_event.h" |
| 29 #include "base/values.h" | 30 #include "base/values.h" |
| 30 #include "net/base/completion_callback.h" | 31 #include "net/base/completion_callback.h" |
| 31 #include "net/base/io_buffer.h" | 32 #include "net/base/io_buffer.h" |
| 32 #include "net/base/ip_address.h" | 33 #include "net/base/ip_address.h" |
| 33 #include "net/base/ip_endpoint.h" | 34 #include "net/base/ip_endpoint.h" |
| 34 #include "net/base/net_errors.h" | 35 #include "net/base/net_errors.h" |
| 35 #include "net/dns/dns_protocol.h" | 36 #include "net/dns/dns_protocol.h" |
| 36 #include "net/dns/dns_query.h" | 37 #include "net/dns/dns_query.h" |
| 37 #include "net/dns/dns_response.h" | 38 #include "net/dns/dns_response.h" |
| 38 #include "net/dns/dns_session.h" | 39 #include "net/dns/dns_session.h" |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 // TODO(szym): Extract TTL for NXDOMAIN results. http://crbug.com/115051 | 278 // TODO(szym): Extract TTL for NXDOMAIN results. http://crbug.com/115051 |
| 278 if (response_->rcode() == dns_protocol::kRcodeNXDOMAIN) | 279 if (response_->rcode() == dns_protocol::kRcodeNXDOMAIN) |
| 279 return ERR_NAME_NOT_RESOLVED; | 280 return ERR_NAME_NOT_RESOLVED; |
| 280 if (response_->rcode() != dns_protocol::kRcodeNOERROR) | 281 if (response_->rcode() != dns_protocol::kRcodeNOERROR) |
| 281 return ERR_DNS_SERVER_FAILED; | 282 return ERR_DNS_SERVER_FAILED; |
| 282 | 283 |
| 283 return OK; | 284 return OK; |
| 284 } | 285 } |
| 285 | 286 |
| 286 void OnIOComplete(int rv) { | 287 void OnIOComplete(int rv) { |
| 288 TRACE_EVENT1("net", "DnsUDPAttempt::OnIOComplete", "qname", |
| 289 query_->qname().as_string()); |
| 287 rv = DoLoop(rv); | 290 rv = DoLoop(rv); |
| 288 if (rv != ERR_IO_PENDING) | 291 if (rv != ERR_IO_PENDING) |
| 289 callback_.Run(rv); | 292 callback_.Run(rv); |
| 290 } | 293 } |
| 291 | 294 |
| 292 State next_state_; | 295 State next_state_; |
| 293 bool received_malformed_response_; | 296 bool received_malformed_response_; |
| 294 base::TimeTicks start_time_; | 297 base::TimeTicks start_time_; |
| 295 | 298 |
| 296 std::unique_ptr<DnsSession::SocketLease> socket_lease_; | 299 std::unique_ptr<DnsSession::SocketLease> socket_lease_; |
| (...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 794 // Custom timeout for TCP attempt. | 797 // Custom timeout for TCP attempt. |
| 795 base::TimeDelta timeout = timer_.GetCurrentDelay() * 2; | 798 base::TimeDelta timeout = timer_.GetCurrentDelay() * 2; |
| 796 timer_.Start(FROM_HERE, timeout, this, &DnsTransactionImpl::OnTimeout); | 799 timer_.Start(FROM_HERE, timeout, this, &DnsTransactionImpl::OnTimeout); |
| 797 } | 800 } |
| 798 return AttemptResult(rv, attempt); | 801 return AttemptResult(rv, attempt); |
| 799 } | 802 } |
| 800 | 803 |
| 801 // Begins query for the current name. Makes the first attempt. | 804 // Begins query for the current name. Makes the first attempt. |
| 802 AttemptResult StartQuery() { | 805 AttemptResult StartQuery() { |
| 803 std::string dotted_qname = DNSDomainToString(qnames_.front()); | 806 std::string dotted_qname = DNSDomainToString(qnames_.front()); |
| 807 TRACE_EVENT1("net", "DnsTransactionImpl::StartQuery", "dotted_qname", |
| 808 dotted_qname); |
| 804 net_log_.BeginEvent(NetLogEventType::DNS_TRANSACTION_QUERY, | 809 net_log_.BeginEvent(NetLogEventType::DNS_TRANSACTION_QUERY, |
| 805 NetLog::StringCallback("qname", &dotted_qname)); | 810 NetLog::StringCallback("qname", &dotted_qname)); |
| 806 | 811 |
| 807 first_server_index_ = session_->NextFirstServerIndex(); | 812 first_server_index_ = session_->NextFirstServerIndex(); |
| 808 RecordLostPacketsIfAny(); | 813 RecordLostPacketsIfAny(); |
| 809 attempts_.clear(); | 814 attempts_.clear(); |
| 810 had_tcp_attempt_ = false; | 815 had_tcp_attempt_ = false; |
| 811 return MakeAttempt(); | 816 return MakeAttempt(); |
| 812 } | 817 } |
| 813 | 818 |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 999 } // namespace | 1004 } // namespace |
| 1000 | 1005 |
| 1001 // static | 1006 // static |
| 1002 std::unique_ptr<DnsTransactionFactory> DnsTransactionFactory::CreateFactory( | 1007 std::unique_ptr<DnsTransactionFactory> DnsTransactionFactory::CreateFactory( |
| 1003 DnsSession* session) { | 1008 DnsSession* session) { |
| 1004 return std::unique_ptr<DnsTransactionFactory>( | 1009 return std::unique_ptr<DnsTransactionFactory>( |
| 1005 new DnsTransactionFactoryImpl(session)); | 1010 new DnsTransactionFactoryImpl(session)); |
| 1006 } | 1011 } |
| 1007 | 1012 |
| 1008 } // namespace net | 1013 } // namespace net |
| OLD | NEW |