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/base/host_resolver_impl.h" | 5 #include "net/base/host_resolver_impl.h" |
| 6 | 6 |
| 7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
| 8 #include <Winsock2.h> | 8 #include <Winsock2.h> |
| 9 #elif defined(OS_POSIX) | 9 #elif defined(OS_POSIX) |
| 10 #include <netdb.h> | 10 #include <netdb.h> |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 427 if (total_count_ == 0) | 427 if (total_count_ == 0) |
| 428 DCHECK_EQ(MINIMUM_PRIORITY, highest_priority_); | 428 DCHECK_EQ(MINIMUM_PRIORITY, highest_priority_); |
| 429 } | 429 } |
| 430 | 430 |
| 431 private: | 431 private: |
| 432 RequestPriority highest_priority_; | 432 RequestPriority highest_priority_; |
| 433 size_t total_count_; | 433 size_t total_count_; |
| 434 size_t counts_[NUM_PRIORITIES]; | 434 size_t counts_[NUM_PRIORITIES]; |
| 435 }; | 435 }; |
| 436 | 436 |
| 437 } // anonymous namespace | |
| 438 | |
| 437 //----------------------------------------------------------------------------- | 439 //----------------------------------------------------------------------------- |
| 438 | 440 |
| 439 HostResolver* CreateHostResolver(size_t max_concurrent_resolves, | 441 HostResolver* CreateHostResolver(size_t max_concurrent_resolves, |
| 440 size_t max_retry_attempts, | 442 size_t max_retry_attempts, |
| 441 HostCache* cache, | 443 HostCache* cache, |
| 442 scoped_ptr<DnsConfigService> config_service, | 444 scoped_ptr<DnsConfigService> config_service, |
| 443 NetLog* net_log) { | 445 NetLog* net_log) { |
| 444 if (max_concurrent_resolves == HostResolver::kDefaultParallelism) | 446 if (max_concurrent_resolves == HostResolver::kDefaultParallelism) |
| 445 max_concurrent_resolves = kDefaultMaxProcTasks; | 447 max_concurrent_resolves = kDefaultMaxProcTasks; |
| 446 | 448 |
| 447 // TODO(szym): Add experiments with reserved slots for higher priority | 449 // TODO(szym): Add experiments with reserved slots for higher priority |
| 448 // requests. | 450 // requests. |
| 449 | 451 |
| 450 PrioritizedDispatcher::Limits limits(NUM_PRIORITIES, max_concurrent_resolves); | 452 PrioritizedDispatcher::Limits limits(NUM_PRIORITIES, max_concurrent_resolves); |
| 451 | 453 |
| 452 HostResolverImpl* resolver = new HostResolverImpl( | 454 HostResolverImpl* resolver = new HostResolverImpl( |
| 453 cache, | 455 cache, |
| 454 limits, | 456 limits, |
| 455 HostResolverImpl::ProcTaskParams(NULL, max_retry_attempts), | 457 HostResolverImpl::ProcTaskParams(NULL, max_retry_attempts), |
| 456 config_service.Pass(), | 458 config_service.Pass(), |
| 457 net_log); | 459 net_log); |
| 458 | 460 |
| 459 return resolver; | 461 return resolver; |
| 460 } | 462 } |
| 461 | 463 |
| 462 } // anonymous namespace | |
| 463 | |
| 464 //----------------------------------------------------------------------------- | |
| 465 | |
| 466 HostResolver* CreateSystemHostResolver(size_t max_concurrent_resolves, | 464 HostResolver* CreateSystemHostResolver(size_t max_concurrent_resolves, |
| 467 size_t max_retry_attempts, | 465 size_t max_retry_attempts, |
| 468 NetLog* net_log) { | 466 NetLog* net_log) { |
| 469 return CreateHostResolver(max_concurrent_resolves, | 467 return CreateHostResolver(max_concurrent_resolves, |
| 470 max_retry_attempts, | 468 max_retry_attempts, |
| 471 HostCache::CreateDefaultCache(), | 469 HostCache::CreateDefaultCache(), |
| 472 scoped_ptr<DnsConfigService>(NULL), | 470 scoped_ptr<DnsConfigService>(NULL), |
| 473 net_log); | 471 net_log); |
| 474 } | 472 } |
| 475 | 473 |
| (...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1063 uint16 qtype = (key.address_family == ADDRESS_FAMILY_IPV6) | 1061 uint16 qtype = (key.address_family == ADDRESS_FAMILY_IPV6) |
| 1064 ? dns_protocol::kTypeAAAA | 1062 ? dns_protocol::kTypeAAAA |
| 1065 : dns_protocol::kTypeA; | 1063 : dns_protocol::kTypeA; |
| 1066 // TODO(szym): Implement "happy eyeballs". | 1064 // TODO(szym): Implement "happy eyeballs". |
| 1067 transaction_ = factory->CreateTransaction( | 1065 transaction_ = factory->CreateTransaction( |
| 1068 key.hostname, | 1066 key.hostname, |
| 1069 qtype, | 1067 qtype, |
| 1070 base::Bind(&DnsTask::OnTransactionComplete, base::Unretained(this), | 1068 base::Bind(&DnsTask::OnTransactionComplete, base::Unretained(this), |
| 1071 base::TimeTicks::Now()), | 1069 base::TimeTicks::Now()), |
| 1072 net_log_); | 1070 net_log_); |
| 1071 | |
|
szym
2012/05/14 18:48:32
No need for this empty line.
Daniele
2012/05/17 23:04:34
Done.
| |
| 1073 DCHECK(transaction_.get()); | 1072 DCHECK(transaction_.get()); |
| 1074 } | 1073 } |
| 1075 | 1074 |
| 1076 int Start() { | 1075 int Start() { |
| 1077 net_log_.BeginEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_DNS_TASK, NULL); | 1076 net_log_.BeginEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_DNS_TASK, NULL); |
| 1078 return transaction_->Start(); | 1077 return transaction_->Start(); |
| 1079 } | 1078 } |
| 1080 | 1079 |
| 1081 void OnTransactionComplete(const base::TimeTicks& start_time, | 1080 void OnTransactionComplete(const base::TimeTicks& start_time, |
| 1082 DnsTransaction* transaction, | 1081 DnsTransaction* transaction, |
| (...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1550 #endif | 1549 #endif |
| 1551 NetworkChangeNotifier::AddIPAddressObserver(this); | 1550 NetworkChangeNotifier::AddIPAddressObserver(this); |
| 1552 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_OPENBSD) | 1551 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_OPENBSD) |
| 1553 #if !defined(OS_ANDROID) | 1552 #if !defined(OS_ANDROID) |
| 1554 EnsureDnsReloaderInit(); | 1553 EnsureDnsReloaderInit(); |
| 1555 #endif | 1554 #endif |
| 1556 NetworkChangeNotifier::AddDNSObserver(this); | 1555 NetworkChangeNotifier::AddDNSObserver(this); |
| 1557 #endif | 1556 #endif |
| 1558 | 1557 |
| 1559 if (dns_config_service_.get()) { | 1558 if (dns_config_service_.get()) { |
| 1560 dns_config_service_->Watch( | |
| 1561 base::Bind(&HostResolverImpl::OnDnsConfigChanged, | |
| 1562 base::Unretained(this))); | |
| 1563 dns_client_ = DnsClient::CreateClient(net_log_); | 1559 dns_client_ = DnsClient::CreateClient(net_log_); |
| 1560 dns_config_service_->Watch(base::Bind(&HostResolverImpl::OnDnsConfigChanged, | |
|
szym
2012/05/14 18:48:32
Why did you change the order? I'm okay with the ne
Daniele
2012/05/17 23:04:34
I changed it because of the way I was calling the
| |
| 1561 base::Unretained(this))); | |
| 1564 } | 1562 } |
| 1565 } | 1563 } |
| 1566 | 1564 |
| 1567 HostResolverImpl::~HostResolverImpl() { | 1565 HostResolverImpl::~HostResolverImpl() { |
| 1568 DiscardIPv6ProbeJob(); | 1566 DiscardIPv6ProbeJob(); |
| 1569 | 1567 |
| 1570 // This will also cancel all outstanding requests. | 1568 // This will also cancel all outstanding requests. |
| 1571 STLDeleteValues(&jobs_); | 1569 STLDeleteValues(&jobs_); |
| 1572 | 1570 |
| 1573 NetworkChangeNotifier::RemoveIPAddressObserver(this); | 1571 NetworkChangeNotifier::RemoveIPAddressObserver(this); |
| (...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1975 | 1973 |
| 1976 if (self && dns_config.IsValid()) | 1974 if (self && dns_config.IsValid()) |
| 1977 TryServingAllJobsFromHosts(); | 1975 TryServingAllJobsFromHosts(); |
| 1978 } | 1976 } |
| 1979 | 1977 |
| 1980 bool HostResolverImpl::HaveDnsConfig() const { | 1978 bool HostResolverImpl::HaveDnsConfig() const { |
| 1981 return (dns_client_.get() != NULL) && (dns_client_->GetConfig() != NULL); | 1979 return (dns_client_.get() != NULL) && (dns_client_->GetConfig() != NULL); |
| 1982 } | 1980 } |
| 1983 | 1981 |
| 1984 } // namespace net | 1982 } // namespace net |
| OLD | NEW |