Chromium Code Reviews| 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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 71 | 71 |
| 72 class ResponseParameters : public NetLog::EventParameters { | 72 class ResponseParameters : public NetLog::EventParameters { |
| 73 public: | 73 public: |
| 74 ResponseParameters(int rcode, int answer_count, const NetLog::Source& source) | 74 ResponseParameters(int rcode, int answer_count, const NetLog::Source& source) |
| 75 : rcode_(rcode), answer_count_(answer_count), source_(source) {} | 75 : rcode_(rcode), answer_count_(answer_count), source_(source) {} |
| 76 | 76 |
| 77 virtual Value* ToValue() const OVERRIDE { | 77 virtual Value* ToValue() const OVERRIDE { |
| 78 DictionaryValue* dict = new DictionaryValue(); | 78 DictionaryValue* dict = new DictionaryValue(); |
| 79 dict->SetInteger("rcode", rcode_); | 79 dict->SetInteger("rcode", rcode_); |
| 80 dict->SetInteger("answer_count", answer_count_); | 80 dict->SetInteger("answer_count", answer_count_); |
| 81 dict->Set("socket_source", source_.ToValue()); | 81 dict->Set("source_dependency", source_.ToValue()); |
| 82 return dict; | 82 return dict; |
| 83 } | 83 } |
| 84 | 84 |
| 85 private: | 85 private: |
| 86 const int rcode_; | 86 const int rcode_; |
| 87 const int answer_count_; | 87 const int answer_count_; |
| 88 const NetLog::Source source_; | 88 const NetLog::Source source_; |
| 89 }; | 89 }; |
| 90 | 90 |
| 91 // ---------------------------------------------------------------------------- | 91 // ---------------------------------------------------------------------------- |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 204 base::Bind(&DnsUDPAttempt::OnIOComplete, | 204 base::Bind(&DnsUDPAttempt::OnIOComplete, |
| 205 base::Unretained(this))); | 205 base::Unretained(this))); |
| 206 } | 206 } |
| 207 | 207 |
| 208 int DoReadResponseComplete(int rv) { | 208 int DoReadResponseComplete(int rv) { |
| 209 DCHECK_NE(ERR_IO_PENDING, rv); | 209 DCHECK_NE(ERR_IO_PENDING, rv); |
| 210 if (rv < 0) | 210 if (rv < 0) |
| 211 return rv; | 211 return rv; |
| 212 | 212 |
| 213 DCHECK(rv); | 213 DCHECK(rv); |
| 214 // TODO(szym): Consider making this check less aggressive. | |
| 215 // Other implementations simply ignore mismatched responses. | |
| 214 if (!response_->InitParse(rv, *query_)) | 216 if (!response_->InitParse(rv, *query_)) |
| 215 return ERR_DNS_MALFORMED_RESPONSE; | 217 return ERR_DNS_MALFORMED_RESPONSE; |
| 216 if (response_->flags() & dns_protocol::kFlagTC) | 218 if (response_->flags() & dns_protocol::kFlagTC) |
| 217 return ERR_DNS_SERVER_REQUIRES_TCP; | 219 return ERR_DNS_SERVER_REQUIRES_TCP; |
| 218 if (response_->rcode() != dns_protocol::kRcodeNOERROR && | 220 if (response_->rcode() != dns_protocol::kRcodeNOERROR && |
| 219 response_->rcode() != dns_protocol::kRcodeNXDOMAIN) { | 221 response_->rcode() != dns_protocol::kRcodeNXDOMAIN) { |
| 220 return ERR_DNS_SERVER_FAILED; | 222 return ERR_DNS_SERVER_FAILED; |
| 221 } | 223 } |
| 222 if (response_->answer_count() == 0) | 224 if (response_->answer_count() == 0) |
| 223 return ERR_NAME_NOT_RESOLVED; | 225 return ERR_NAME_NOT_RESOLVED; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 296 } | 298 } |
| 297 | 299 |
| 298 virtual int Start() OVERRIDE { | 300 virtual int Start() OVERRIDE { |
| 299 int rv = PrepareSearch(); | 301 int rv = PrepareSearch(); |
| 300 if (rv == OK) | 302 if (rv == OK) |
| 301 rv = StartQuery(); | 303 rv = StartQuery(); |
| 302 DCHECK_NE(OK, rv); | 304 DCHECK_NE(OK, rv); |
| 303 return rv; | 305 return rv; |
| 304 } | 306 } |
| 305 | 307 |
| 308 virtual const BoundNetLog& net_log() const { | |
|
mmenke
2012/02/14 18:46:00
nit: OVERRIDE
| |
| 309 return net_log_; | |
| 310 } | |
| 311 | |
| 306 private: | 312 private: |
| 307 // Prepares |qnames_| according to the DnsConfig. | 313 // Prepares |qnames_| according to the DnsConfig. |
| 308 int PrepareSearch() { | 314 int PrepareSearch() { |
| 309 const DnsConfig& config = session_->config(); | 315 const DnsConfig& config = session_->config(); |
| 310 | 316 |
| 311 std::string labeled_hostname; | 317 std::string labeled_hostname; |
| 312 if (!DNSDomainFromDot(hostname_, &labeled_hostname)) | 318 if (!DNSDomainFromDot(hostname_, &labeled_hostname)) |
| 313 return ERR_INVALID_ARGUMENT; | 319 return ERR_INVALID_ARGUMENT; |
| 314 | 320 |
| 315 if (hostname_[hostname_.size() - 1] == '.') { | 321 if (hostname_[hostname_.size() - 1] == '.') { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 380 | 386 |
| 381 uint16 id = session_->NextQueryId(); | 387 uint16 id = session_->NextQueryId(); |
| 382 scoped_ptr<DnsQuery> query; | 388 scoped_ptr<DnsQuery> query; |
| 383 if (attempts_.empty()) { | 389 if (attempts_.empty()) { |
| 384 query.reset(new DnsQuery(id, qnames_.front(), qtype_)); | 390 query.reset(new DnsQuery(id, qnames_.front(), qtype_)); |
| 385 } else { | 391 } else { |
| 386 query.reset(attempts_[0]->query()->CloneWithNewId(id)); | 392 query.reset(attempts_[0]->query()->CloneWithNewId(id)); |
| 387 } | 393 } |
| 388 | 394 |
| 389 net_log_.AddEvent(NetLog::TYPE_DNS_TRANSACTION_ATTEMPT, make_scoped_refptr( | 395 net_log_.AddEvent(NetLog::TYPE_DNS_TRANSACTION_ATTEMPT, make_scoped_refptr( |
| 390 new NetLogSourceParameter("socket_source", socket->NetLog().source()))); | 396 new NetLogSourceParameter("source_dependency", |
| 397 socket->NetLog().source()))); | |
| 391 | 398 |
| 392 const DnsConfig& config = session_->config(); | 399 const DnsConfig& config = session_->config(); |
| 393 | 400 |
| 394 unsigned server_index = first_server_index_ + | 401 unsigned server_index = first_server_index_ + |
| 395 (attempt_number % config.nameservers.size()); | 402 (attempt_number % config.nameservers.size()); |
| 396 | 403 |
| 397 DnsUDPAttempt* attempt = new DnsUDPAttempt( | 404 DnsUDPAttempt* attempt = new DnsUDPAttempt( |
| 398 socket.Pass(), | 405 socket.Pass(), |
| 399 config.nameservers[server_index], | 406 config.nameservers[server_index], |
| 400 query.Pass(), | 407 query.Pass(), |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 528 | 535 |
| 529 // static | 536 // static |
| 530 scoped_ptr<DnsTransactionFactory> DnsTransactionFactory::CreateFactory( | 537 scoped_ptr<DnsTransactionFactory> DnsTransactionFactory::CreateFactory( |
| 531 DnsSession* session) { | 538 DnsSession* session) { |
| 532 return scoped_ptr<DnsTransactionFactory>( | 539 return scoped_ptr<DnsTransactionFactory>( |
| 533 new DnsTransactionFactoryImpl(session)); | 540 new DnsTransactionFactoryImpl(session)); |
| 534 } | 541 } |
| 535 | 542 |
| 536 } // namespace net | 543 } // namespace net |
| 537 | 544 |
| OLD | NEW |