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/async_host_resolver.h" | 5 #include "net/dns/async_host_resolver.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
340 transaction) != dns_transactions_.end()); | 340 transaction) != dns_transactions_.end()); |
341 | 341 |
342 // If by the time requests that caused |transaction| are cancelled, we do | 342 // If by the time requests that caused |transaction| are cancelled, we do |
343 // not have a port number to associate with the result, therefore, we | 343 // not have a port number to associate with the result, therefore, we |
344 // assume the most common port, otherwise we use the port number of the | 344 // assume the most common port, otherwise we use the port number of the |
345 // first request. | 345 // first request. |
346 KeyRequestListMap::iterator rit = requestlist_map_.find( | 346 KeyRequestListMap::iterator rit = requestlist_map_.find( |
347 std::make_pair(transaction->GetHostname(), transaction->GetType())); | 347 std::make_pair(transaction->GetHostname(), transaction->GetType())); |
348 DCHECK(rit != requestlist_map_.end()); | 348 DCHECK(rit != requestlist_map_.end()); |
349 RequestList& requests = rit->second; | 349 RequestList& requests = rit->second; |
350 int port = requests.empty() ? 80 : requests.front()->info().port(); | |
351 | 350 |
352 // Extract AddressList and TTL out of DnsResponse. | 351 // Extract AddressList and TTL out of DnsResponse. |
353 AddressList addr_list; | 352 AddressList addr_list; |
354 uint32 ttl = kuint32max; | 353 uint32 ttl = kuint32max; |
355 if (result == OK) { | 354 if (result == OK) { |
356 IPAddressList ip_addresses; | 355 IPAddressList ip_addresses; |
357 DnsRecordParser parser = response->Parser(); | 356 DnsRecordParser parser = response->Parser(); |
358 DnsResourceRecord record; | 357 DnsResourceRecord record; |
359 // TODO(szym): Add stricter checking of names, aliases and address lengths. | 358 // TODO(szym): Add stricter checking of names, aliases and address lengths. |
360 while (parser.ParseRecord(&record)) { | 359 while (parser.ParseRecord(&record)) { |
361 if (record.type == transaction->GetType() && | 360 if (record.type == transaction->GetType() && |
362 (record.rdata.size() == kIPv4AddressSize || | 361 (record.rdata.size() == kIPv4AddressSize || |
363 record.rdata.size() == kIPv6AddressSize)) { | 362 record.rdata.size() == kIPv6AddressSize)) { |
364 ip_addresses.push_back(IPAddressNumber(record.rdata.begin(), | 363 ip_addresses.push_back(IPAddressNumber(record.rdata.begin(), |
365 record.rdata.end())); | 364 record.rdata.end())); |
366 ttl = std::min(ttl, record.ttl); | 365 ttl = std::min(ttl, record.ttl); |
367 } | 366 } |
368 } | 367 } |
369 if (!ip_addresses.empty()) | 368 if (!ip_addresses.empty()) |
370 addr_list = AddressList::CreateFromIPAddressList(ip_addresses, port); | 369 addr_list = AddressList::CreateFromIPAddressList(ip_addresses, ""); |
371 else | 370 else |
372 result = ERR_NAME_NOT_RESOLVED; | 371 result = ERR_NAME_NOT_RESOLVED; |
373 } | 372 } |
374 | 373 |
374 // NOTE: This is here only to compile, but async_host_resolver* is going | |
cbentzel
2012/02/10 19:51:08
Is this note still correct?
szym
2012/02/10 21:49:36
I haven't removed async_host_resolver* yet, but th
| |
375 // away in this CL. | |
376 int port = requests.empty() ? 80 : requests.front()->info().port(); | |
377 addr_list.SetPort(port); | |
378 | |
375 // Run callback of every request that was depending on this DNS request, | 379 // Run callback of every request that was depending on this DNS request, |
376 // also notify observers. | 380 // also notify observers. |
377 for (RequestList::iterator it = requests.begin(); it != requests.end(); ++it) | 381 for (RequestList::iterator it = requests.begin(); it != requests.end(); ++it) |
378 (*it)->OnAsyncComplete(result, addr_list); | 382 (*it)->OnAsyncComplete(result, addr_list); |
379 | 383 |
380 // It is possible that the requests that caused |transaction| to be | 384 // It is possible that the requests that caused |transaction| to be |
381 // created are cancelled by the time |transaction| completes. In that | 385 // created are cancelled by the time |transaction| completes. In that |
382 // case |requests| would be empty. We are knowingly throwing away the | 386 // case |requests| would be empty. We are knowingly throwing away the |
383 // result of a DNS resolution in that case, because (a) if there are no | 387 // result of a DNS resolution in that case, because (a) if there are no |
384 // requests, we do not have info to obtain a key from, (b) DnsTransaction | 388 // requests, we do not have info to obtain a key from, (b) DnsTransaction |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
515 it = requests.erase(it); | 519 it = requests.erase(it); |
516 } else { | 520 } else { |
517 ++it; | 521 ++it; |
518 } | 522 } |
519 } | 523 } |
520 } | 524 } |
521 StartNewDnsRequestFor(request); | 525 StartNewDnsRequestFor(request); |
522 } | 526 } |
523 | 527 |
524 } // namespace net | 528 } // namespace net |
OLD | NEW |