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/host_resolver_impl.h" | 5 #include "net/dns/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 1915 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1926 | 1926 |
1927 HostResolverImpl::ProcTaskParams::~ProcTaskParams() {} | 1927 HostResolverImpl::ProcTaskParams::~ProcTaskParams() {} |
1928 | 1928 |
1929 HostResolverImpl::HostResolverImpl(const Options& options, NetLog* net_log) | 1929 HostResolverImpl::HostResolverImpl(const Options& options, NetLog* net_log) |
1930 : HostResolverImpl( | 1930 : HostResolverImpl( |
1931 options, | 1931 options, |
1932 net_log, | 1932 net_log, |
1933 base::WorkerPool::GetTaskRunner(true /* task_is_slow */)) {} | 1933 base::WorkerPool::GetTaskRunner(true /* task_is_slow */)) {} |
1934 | 1934 |
1935 HostResolverImpl::~HostResolverImpl() { | 1935 HostResolverImpl::~HostResolverImpl() { |
| 1936 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); |
1936 // Prevent the dispatcher from starting new jobs. | 1937 // Prevent the dispatcher from starting new jobs. |
1937 dispatcher_->SetLimitsToZero(); | 1938 dispatcher_->SetLimitsToZero(); |
1938 // It's now safe for Jobs to call KillDnsTask on destruction, because | 1939 // It's now safe for Jobs to call KillDnsTask on destruction, because |
1939 // OnJobComplete will not start any new jobs. | 1940 // OnJobComplete will not start any new jobs. |
1940 jobs_.clear(); | 1941 jobs_.clear(); |
1941 | 1942 |
1942 NetworkChangeNotifier::RemoveIPAddressObserver(this); | 1943 NetworkChangeNotifier::RemoveIPAddressObserver(this); |
1943 NetworkChangeNotifier::RemoveConnectionTypeObserver(this); | 1944 NetworkChangeNotifier::RemoveConnectionTypeObserver(this); |
1944 NetworkChangeNotifier::RemoveDNSObserver(this); | 1945 NetworkChangeNotifier::RemoveDNSObserver(this); |
1945 } | 1946 } |
1946 | 1947 |
1947 void HostResolverImpl::SetMaxQueuedJobs(size_t value) { | 1948 void HostResolverImpl::SetMaxQueuedJobs(size_t value) { |
1948 DCHECK_EQ(0u, dispatcher_->num_queued_jobs()); | 1949 DCHECK_EQ(0u, dispatcher_->num_queued_jobs()); |
1949 DCHECK_GT(value, 0u); | 1950 DCHECK_GT(value, 0u); |
1950 max_queued_jobs_ = value; | 1951 max_queued_jobs_ = value; |
1951 } | 1952 } |
1952 | 1953 |
1953 int HostResolverImpl::Resolve(const RequestInfo& info, | 1954 int HostResolverImpl::Resolve(const RequestInfo& info, |
1954 RequestPriority priority, | 1955 RequestPriority priority, |
1955 AddressList* addresses, | 1956 AddressList* addresses, |
1956 const CompletionCallback& callback, | 1957 const CompletionCallback& callback, |
1957 std::unique_ptr<Request>* out_req, | 1958 std::unique_ptr<Request>* out_req, |
1958 const NetLogWithSource& source_net_log) { | 1959 const NetLogWithSource& source_net_log) { |
1959 DCHECK(addresses); | 1960 DCHECK(addresses); |
1960 DCHECK(CalledOnValidThread()); | 1961 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); |
1961 DCHECK_EQ(false, callback.is_null()); | 1962 DCHECK_EQ(false, callback.is_null()); |
1962 DCHECK(out_req); | 1963 DCHECK(out_req); |
1963 | 1964 |
1964 // Check that the caller supplied a valid hostname to resolve. | 1965 // Check that the caller supplied a valid hostname to resolve. |
1965 if (!IsValidDNSDomain(info.hostname())) | 1966 if (!IsValidDNSDomain(info.hostname())) |
1966 return ERR_NAME_NOT_RESOLVED; | 1967 return ERR_NAME_NOT_RESOLVED; |
1967 | 1968 |
1968 LogStartRequest(source_net_log, info); | 1969 LogStartRequest(source_net_log, info); |
1969 | 1970 |
1970 IPAddress ip_address; | 1971 IPAddress ip_address; |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2125 MakeNotStale(stale_info); | 2126 MakeNotStale(stale_info); |
2126 return OK; | 2127 return OK; |
2127 } | 2128 } |
2128 | 2129 |
2129 return ERR_DNS_CACHE_MISS; | 2130 return ERR_DNS_CACHE_MISS; |
2130 } | 2131 } |
2131 | 2132 |
2132 int HostResolverImpl::ResolveFromCache(const RequestInfo& info, | 2133 int HostResolverImpl::ResolveFromCache(const RequestInfo& info, |
2133 AddressList* addresses, | 2134 AddressList* addresses, |
2134 const NetLogWithSource& source_net_log) { | 2135 const NetLogWithSource& source_net_log) { |
2135 DCHECK(CalledOnValidThread()); | 2136 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); |
2136 DCHECK(addresses); | 2137 DCHECK(addresses); |
2137 | 2138 |
2138 // Update the net log and notify registered observers. | 2139 // Update the net log and notify registered observers. |
2139 LogStartRequest(source_net_log, info); | 2140 LogStartRequest(source_net_log, info); |
2140 | 2141 |
2141 IPAddress ip_address; | 2142 IPAddress ip_address; |
2142 IPAddress* ip_address_ptr = nullptr; | 2143 IPAddress* ip_address_ptr = nullptr; |
2143 if (ip_address.AssignFromIPLiteral(info.hostname())) | 2144 if (ip_address.AssignFromIPLiteral(info.hostname())) |
2144 ip_address_ptr = &ip_address; | 2145 ip_address_ptr = &ip_address; |
2145 | 2146 |
2146 Key key = GetEffectiveKeyForRequest(info, ip_address_ptr, source_net_log); | 2147 Key key = GetEffectiveKeyForRequest(info, ip_address_ptr, source_net_log); |
2147 | 2148 |
2148 int rv = ResolveHelper(key, info, ip_address_ptr, addresses, false, nullptr, | 2149 int rv = ResolveHelper(key, info, ip_address_ptr, addresses, false, nullptr, |
2149 source_net_log); | 2150 source_net_log); |
2150 LogFinishRequest(source_net_log, info, rv); | 2151 LogFinishRequest(source_net_log, info, rv); |
2151 return rv; | 2152 return rv; |
2152 } | 2153 } |
2153 | 2154 |
2154 void HostResolverImpl::SetDnsClientEnabled(bool enabled) { | 2155 void HostResolverImpl::SetDnsClientEnabled(bool enabled) { |
2155 DCHECK(CalledOnValidThread()); | 2156 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); |
2156 #if defined(ENABLE_BUILT_IN_DNS) | 2157 #if defined(ENABLE_BUILT_IN_DNS) |
2157 if (enabled && !dns_client_) { | 2158 if (enabled && !dns_client_) { |
2158 SetDnsClient(DnsClient::CreateClient(net_log_)); | 2159 SetDnsClient(DnsClient::CreateClient(net_log_)); |
2159 } else if (!enabled && dns_client_) { | 2160 } else if (!enabled && dns_client_) { |
2160 SetDnsClient(std::unique_ptr<DnsClient>()); | 2161 SetDnsClient(std::unique_ptr<DnsClient>()); |
2161 } | 2162 } |
2162 #endif | 2163 #endif |
2163 } | 2164 } |
2164 | 2165 |
2165 HostCache* HostResolverImpl::GetHostCache() { | 2166 HostCache* HostResolverImpl::GetHostCache() { |
(...skipping 12 matching lines...) Expand all Loading... |
2178 return base::MakeUnique<base::DictionaryValue>(); | 2179 return base::MakeUnique<base::DictionaryValue>(); |
2179 | 2180 |
2180 return dns_config->ToValue(); | 2181 return dns_config->ToValue(); |
2181 } | 2182 } |
2182 | 2183 |
2183 int HostResolverImpl::ResolveStaleFromCache( | 2184 int HostResolverImpl::ResolveStaleFromCache( |
2184 const RequestInfo& info, | 2185 const RequestInfo& info, |
2185 AddressList* addresses, | 2186 AddressList* addresses, |
2186 HostCache::EntryStaleness* stale_info, | 2187 HostCache::EntryStaleness* stale_info, |
2187 const NetLogWithSource& source_net_log) { | 2188 const NetLogWithSource& source_net_log) { |
2188 DCHECK(CalledOnValidThread()); | 2189 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); |
2189 DCHECK(addresses); | 2190 DCHECK(addresses); |
2190 DCHECK(stale_info); | 2191 DCHECK(stale_info); |
2191 | 2192 |
2192 // Update the net log and notify registered observers. | 2193 // Update the net log and notify registered observers. |
2193 LogStartRequest(source_net_log, info); | 2194 LogStartRequest(source_net_log, info); |
2194 | 2195 |
2195 IPAddress ip_address; | 2196 IPAddress ip_address; |
2196 IPAddress* ip_address_ptr = nullptr; | 2197 IPAddress* ip_address_ptr = nullptr; |
2197 if (ip_address.AssignFromIPLiteral(info.hostname())) | 2198 if (ip_address.AssignFromIPLiteral(info.hostname())) |
2198 ip_address_ptr = &ip_address; | 2199 ip_address_ptr = &ip_address; |
2199 | 2200 |
2200 Key key = GetEffectiveKeyForRequest(info, ip_address_ptr, source_net_log); | 2201 Key key = GetEffectiveKeyForRequest(info, ip_address_ptr, source_net_log); |
2201 | 2202 |
2202 int rv = ResolveHelper(key, info, ip_address_ptr, addresses, true, stale_info, | 2203 int rv = ResolveHelper(key, info, ip_address_ptr, addresses, true, stale_info, |
2203 source_net_log); | 2204 source_net_log); |
2204 LogFinishRequest(source_net_log, info, rv); | 2205 LogFinishRequest(source_net_log, info, rv); |
2205 return rv; | 2206 return rv; |
2206 } | 2207 } |
2207 | 2208 |
2208 void HostResolverImpl::SetNoIPv6OnWifi(bool no_ipv6_on_wifi) { | 2209 void HostResolverImpl::SetNoIPv6OnWifi(bool no_ipv6_on_wifi) { |
2209 DCHECK(CalledOnValidThread()); | 2210 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); |
2210 assume_ipv6_failure_on_wifi_ = no_ipv6_on_wifi; | 2211 assume_ipv6_failure_on_wifi_ = no_ipv6_on_wifi; |
2211 } | 2212 } |
2212 | 2213 |
2213 bool HostResolverImpl::GetNoIPv6OnWifi() { | 2214 bool HostResolverImpl::GetNoIPv6OnWifi() { |
2214 return assume_ipv6_failure_on_wifi_; | 2215 return assume_ipv6_failure_on_wifi_; |
2215 } | 2216 } |
2216 | 2217 |
2217 bool HostResolverImpl::ResolveAsIP(const Key& key, | 2218 bool HostResolverImpl::ResolveAsIP(const Key& key, |
2218 const RequestInfo& info, | 2219 const RequestInfo& info, |
2219 const IPAddress* ip_address, | 2220 const IPAddress* ip_address, |
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2699 if (job_) | 2700 if (job_) |
2700 job_->CancelRequest(this); | 2701 job_->CancelRequest(this); |
2701 } | 2702 } |
2702 | 2703 |
2703 void HostResolverImpl::RequestImpl::ChangeRequestPriority( | 2704 void HostResolverImpl::RequestImpl::ChangeRequestPriority( |
2704 RequestPriority priority) { | 2705 RequestPriority priority) { |
2705 job_->ChangeRequestPriority(this, priority); | 2706 job_->ChangeRequestPriority(this, priority); |
2706 } | 2707 } |
2707 | 2708 |
2708 } // namespace net | 2709 } // namespace net |
OLD | NEW |