| 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 |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 DnsUDPAttempt(unsigned server_index, | 134 DnsUDPAttempt(unsigned server_index, |
| 135 scoped_ptr<DnsSession::SocketLease> socket_lease, | 135 scoped_ptr<DnsSession::SocketLease> socket_lease, |
| 136 scoped_ptr<DnsQuery> query) | 136 scoped_ptr<DnsQuery> query) |
| 137 : DnsAttempt(server_index), | 137 : DnsAttempt(server_index), |
| 138 next_state_(STATE_NONE), | 138 next_state_(STATE_NONE), |
| 139 received_malformed_response_(false), | 139 received_malformed_response_(false), |
| 140 socket_lease_(socket_lease.Pass()), | 140 socket_lease_(socket_lease.Pass()), |
| 141 query_(query.Pass()) {} | 141 query_(query.Pass()) {} |
| 142 | 142 |
| 143 // DnsAttempt: | 143 // DnsAttempt: |
| 144 virtual int Start(const CompletionCallback& callback) override { | 144 int Start(const CompletionCallback& callback) override { |
| 145 DCHECK_EQ(STATE_NONE, next_state_); | 145 DCHECK_EQ(STATE_NONE, next_state_); |
| 146 callback_ = callback; | 146 callback_ = callback; |
| 147 start_time_ = base::TimeTicks::Now(); | 147 start_time_ = base::TimeTicks::Now(); |
| 148 next_state_ = STATE_SEND_QUERY; | 148 next_state_ = STATE_SEND_QUERY; |
| 149 return DoLoop(OK); | 149 return DoLoop(OK); |
| 150 } | 150 } |
| 151 | 151 |
| 152 virtual const DnsQuery* GetQuery() const override { | 152 const DnsQuery* GetQuery() const override { return query_.get(); } |
| 153 return query_.get(); | |
| 154 } | |
| 155 | 153 |
| 156 virtual const DnsResponse* GetResponse() const override { | 154 const DnsResponse* GetResponse() const override { |
| 157 const DnsResponse* resp = response_.get(); | 155 const DnsResponse* resp = response_.get(); |
| 158 return (resp != NULL && resp->IsValid()) ? resp : NULL; | 156 return (resp != NULL && resp->IsValid()) ? resp : NULL; |
| 159 } | 157 } |
| 160 | 158 |
| 161 virtual const BoundNetLog& GetSocketNetLog() const override { | 159 const BoundNetLog& GetSocketNetLog() const override { |
| 162 return socket_lease_->socket()->NetLog(); | 160 return socket_lease_->socket()->NetLog(); |
| 163 } | 161 } |
| 164 | 162 |
| 165 private: | 163 private: |
| 166 enum State { | 164 enum State { |
| 167 STATE_SEND_QUERY, | 165 STATE_SEND_QUERY, |
| 168 STATE_SEND_QUERY_COMPLETE, | 166 STATE_SEND_QUERY_COMPLETE, |
| 169 STATE_READ_RESPONSE, | 167 STATE_READ_RESPONSE, |
| 170 STATE_READ_RESPONSE_COMPLETE, | 168 STATE_READ_RESPONSE_COMPLETE, |
| 171 STATE_NONE, | 169 STATE_NONE, |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 scoped_ptr<StreamSocket> socket, | 297 scoped_ptr<StreamSocket> socket, |
| 300 scoped_ptr<DnsQuery> query) | 298 scoped_ptr<DnsQuery> query) |
| 301 : DnsAttempt(server_index), | 299 : DnsAttempt(server_index), |
| 302 next_state_(STATE_NONE), | 300 next_state_(STATE_NONE), |
| 303 socket_(socket.Pass()), | 301 socket_(socket.Pass()), |
| 304 query_(query.Pass()), | 302 query_(query.Pass()), |
| 305 length_buffer_(new IOBufferWithSize(sizeof(uint16))), | 303 length_buffer_(new IOBufferWithSize(sizeof(uint16))), |
| 306 response_length_(0) {} | 304 response_length_(0) {} |
| 307 | 305 |
| 308 // DnsAttempt: | 306 // DnsAttempt: |
| 309 virtual int Start(const CompletionCallback& callback) override { | 307 int Start(const CompletionCallback& callback) override { |
| 310 DCHECK_EQ(STATE_NONE, next_state_); | 308 DCHECK_EQ(STATE_NONE, next_state_); |
| 311 callback_ = callback; | 309 callback_ = callback; |
| 312 start_time_ = base::TimeTicks::Now(); | 310 start_time_ = base::TimeTicks::Now(); |
| 313 next_state_ = STATE_CONNECT_COMPLETE; | 311 next_state_ = STATE_CONNECT_COMPLETE; |
| 314 int rv = socket_->Connect(base::Bind(&DnsTCPAttempt::OnIOComplete, | 312 int rv = socket_->Connect(base::Bind(&DnsTCPAttempt::OnIOComplete, |
| 315 base::Unretained(this))); | 313 base::Unretained(this))); |
| 316 if (rv == ERR_IO_PENDING) { | 314 if (rv == ERR_IO_PENDING) { |
| 317 set_result(rv); | 315 set_result(rv); |
| 318 return rv; | 316 return rv; |
| 319 } | 317 } |
| 320 return DoLoop(rv); | 318 return DoLoop(rv); |
| 321 } | 319 } |
| 322 | 320 |
| 323 virtual const DnsQuery* GetQuery() const override { | 321 const DnsQuery* GetQuery() const override { return query_.get(); } |
| 324 return query_.get(); | |
| 325 } | |
| 326 | 322 |
| 327 virtual const DnsResponse* GetResponse() const override { | 323 const DnsResponse* GetResponse() const override { |
| 328 const DnsResponse* resp = response_.get(); | 324 const DnsResponse* resp = response_.get(); |
| 329 return (resp != NULL && resp->IsValid()) ? resp : NULL; | 325 return (resp != NULL && resp->IsValid()) ? resp : NULL; |
| 330 } | 326 } |
| 331 | 327 |
| 332 virtual const BoundNetLog& GetSocketNetLog() const override { | 328 const BoundNetLog& GetSocketNetLog() const override { |
| 333 return socket_->NetLog(); | 329 return socket_->NetLog(); |
| 334 } | 330 } |
| 335 | 331 |
| 336 private: | 332 private: |
| 337 enum State { | 333 enum State { |
| 338 STATE_CONNECT_COMPLETE, | 334 STATE_CONNECT_COMPLETE, |
| 339 STATE_SEND_LENGTH, | 335 STATE_SEND_LENGTH, |
| 340 STATE_SEND_QUERY, | 336 STATE_SEND_QUERY, |
| 341 STATE_READ_LENGTH, | 337 STATE_READ_LENGTH, |
| 342 STATE_READ_LENGTH_COMPLETE, | 338 STATE_READ_LENGTH_COMPLETE, |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 qnames_initial_size_(0), | 556 qnames_initial_size_(0), |
| 561 attempts_count_(0), | 557 attempts_count_(0), |
| 562 had_tcp_attempt_(false), | 558 had_tcp_attempt_(false), |
| 563 first_server_index_(0) { | 559 first_server_index_(0) { |
| 564 DCHECK(session_.get()); | 560 DCHECK(session_.get()); |
| 565 DCHECK(!hostname_.empty()); | 561 DCHECK(!hostname_.empty()); |
| 566 DCHECK(!callback_.is_null()); | 562 DCHECK(!callback_.is_null()); |
| 567 DCHECK(!IsIPLiteral(hostname_)); | 563 DCHECK(!IsIPLiteral(hostname_)); |
| 568 } | 564 } |
| 569 | 565 |
| 570 virtual ~DnsTransactionImpl() { | 566 ~DnsTransactionImpl() override { |
| 571 if (!callback_.is_null()) { | 567 if (!callback_.is_null()) { |
| 572 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_DNS_TRANSACTION, | 568 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_DNS_TRANSACTION, |
| 573 ERR_ABORTED); | 569 ERR_ABORTED); |
| 574 } // otherwise logged in DoCallback or Start | 570 } // otherwise logged in DoCallback or Start |
| 575 } | 571 } |
| 576 | 572 |
| 577 virtual const std::string& GetHostname() const override { | 573 const std::string& GetHostname() const override { |
| 578 DCHECK(CalledOnValidThread()); | 574 DCHECK(CalledOnValidThread()); |
| 579 return hostname_; | 575 return hostname_; |
| 580 } | 576 } |
| 581 | 577 |
| 582 virtual uint16 GetType() const override { | 578 uint16 GetType() const override { |
| 583 DCHECK(CalledOnValidThread()); | 579 DCHECK(CalledOnValidThread()); |
| 584 return qtype_; | 580 return qtype_; |
| 585 } | 581 } |
| 586 | 582 |
| 587 virtual void Start() override { | 583 void Start() override { |
| 588 DCHECK(!callback_.is_null()); | 584 DCHECK(!callback_.is_null()); |
| 589 DCHECK(attempts_.empty()); | 585 DCHECK(attempts_.empty()); |
| 590 net_log_.BeginEvent(NetLog::TYPE_DNS_TRANSACTION, | 586 net_log_.BeginEvent(NetLog::TYPE_DNS_TRANSACTION, |
| 591 base::Bind(&NetLogStartCallback, &hostname_, qtype_)); | 587 base::Bind(&NetLogStartCallback, &hostname_, qtype_)); |
| 592 AttemptResult result(PrepareSearch(), NULL); | 588 AttemptResult result(PrepareSearch(), NULL); |
| 593 if (result.rv == OK) { | 589 if (result.rv == OK) { |
| 594 qnames_initial_size_ = qnames_.size(); | 590 qnames_initial_size_ = qnames_.size(); |
| 595 if (qtype_ == dns_protocol::kTypeA) | 591 if (qtype_ == dns_protocol::kTypeA) |
| 596 UMA_HISTOGRAM_COUNTS("AsyncDNS.SuffixSearchStart", qnames_.size()); | 592 UMA_HISTOGRAM_COUNTS("AsyncDNS.SuffixSearchStart", qnames_.size()); |
| 597 result = ProcessAttemptResult(StartQuery()); | 593 result = ProcessAttemptResult(StartQuery()); |
| (...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 961 // ---------------------------------------------------------------------------- | 957 // ---------------------------------------------------------------------------- |
| 962 | 958 |
| 963 // Implementation of DnsTransactionFactory that returns instances of | 959 // Implementation of DnsTransactionFactory that returns instances of |
| 964 // DnsTransactionImpl. | 960 // DnsTransactionImpl. |
| 965 class DnsTransactionFactoryImpl : public DnsTransactionFactory { | 961 class DnsTransactionFactoryImpl : public DnsTransactionFactory { |
| 966 public: | 962 public: |
| 967 explicit DnsTransactionFactoryImpl(DnsSession* session) { | 963 explicit DnsTransactionFactoryImpl(DnsSession* session) { |
| 968 session_ = session; | 964 session_ = session; |
| 969 } | 965 } |
| 970 | 966 |
| 971 virtual scoped_ptr<DnsTransaction> CreateTransaction( | 967 scoped_ptr<DnsTransaction> CreateTransaction( |
| 972 const std::string& hostname, | 968 const std::string& hostname, |
| 973 uint16 qtype, | 969 uint16 qtype, |
| 974 const CallbackType& callback, | 970 const CallbackType& callback, |
| 975 const BoundNetLog& net_log) override { | 971 const BoundNetLog& net_log) override { |
| 976 return scoped_ptr<DnsTransaction>(new DnsTransactionImpl( | 972 return scoped_ptr<DnsTransaction>(new DnsTransactionImpl( |
| 977 session_.get(), hostname, qtype, callback, net_log)); | 973 session_.get(), hostname, qtype, callback, net_log)); |
| 978 } | 974 } |
| 979 | 975 |
| 980 private: | 976 private: |
| 981 scoped_refptr<DnsSession> session_; | 977 scoped_refptr<DnsSession> session_; |
| 982 }; | 978 }; |
| 983 | 979 |
| 984 } // namespace | 980 } // namespace |
| 985 | 981 |
| 986 // static | 982 // static |
| 987 scoped_ptr<DnsTransactionFactory> DnsTransactionFactory::CreateFactory( | 983 scoped_ptr<DnsTransactionFactory> DnsTransactionFactory::CreateFactory( |
| 988 DnsSession* session) { | 984 DnsSession* session) { |
| 989 return scoped_ptr<DnsTransactionFactory>( | 985 return scoped_ptr<DnsTransactionFactory>( |
| 990 new DnsTransactionFactoryImpl(session)); | 986 new DnsTransactionFactoryImpl(session)); |
| 991 } | 987 } |
| 992 | 988 |
| 993 } // namespace net | 989 } // namespace net |
| OLD | NEW |