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 167 matching lines...) Loading... |
178 !hostname.compare(hostname.size() - kSuffixLen, kSuffixLen, kSuffix); | 178 !hostname.compare(hostname.size() - kSuffixLen, kSuffixLen, kSuffix); |
179 } | 179 } |
180 return hostname.size() > kSuffixLenTrimmed && | 180 return hostname.size() > kSuffixLenTrimmed && |
181 !hostname.compare(hostname.size() - kSuffixLenTrimmed, kSuffixLenTrimmed, | 181 !hostname.compare(hostname.size() - kSuffixLenTrimmed, kSuffixLenTrimmed, |
182 kSuffix, kSuffixLenTrimmed); | 182 kSuffix, kSuffixLenTrimmed); |
183 } | 183 } |
184 | 184 |
185 // Attempts to connect a UDP socket to |dest|:53. | 185 // Attempts to connect a UDP socket to |dest|:53. |
186 bool IsGloballyReachable(const IPAddressNumber& dest, | 186 bool IsGloballyReachable(const IPAddressNumber& dest, |
187 const BoundNetLog& net_log) { | 187 const BoundNetLog& net_log) { |
| 188 // TODO(eroman): Remove ScopedTracker below once crbug.com/455942 is fixed. |
| 189 tracked_objects::ScopedTracker tracking_profile_1( |
| 190 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 191 "455942 IsGloballyReachable (create udp socket)")); |
| 192 |
188 scoped_ptr<DatagramClientSocket> socket( | 193 scoped_ptr<DatagramClientSocket> socket( |
189 ClientSocketFactory::GetDefaultFactory()->CreateDatagramClientSocket( | 194 ClientSocketFactory::GetDefaultFactory()->CreateDatagramClientSocket( |
190 DatagramSocket::DEFAULT_BIND, | 195 DatagramSocket::DEFAULT_BIND, |
191 RandIntCallback(), | 196 RandIntCallback(), |
192 net_log.net_log(), | 197 net_log.net_log(), |
193 net_log.source())); | 198 net_log.source())); |
| 199 // TODO(eroman): Remove ScopedTracker below once crbug.com/455942 is fixed. |
| 200 tracked_objects::ScopedTracker tracking_profile_2( |
| 201 FROM_HERE_WITH_EXPLICIT_FUNCTION("455942 IsGloballyReachable (connect)")); |
194 int rv = socket->Connect(IPEndPoint(dest, 53)); | 202 int rv = socket->Connect(IPEndPoint(dest, 53)); |
195 if (rv != OK) | 203 if (rv != OK) |
196 return false; | 204 return false; |
| 205 tracked_objects::ScopedTracker tracking_profile_3( |
| 206 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 207 "455942 IsGloballyReachable (get local addr)")); |
197 IPEndPoint endpoint; | 208 IPEndPoint endpoint; |
198 rv = socket->GetLocalAddress(&endpoint); | 209 rv = socket->GetLocalAddress(&endpoint); |
199 if (rv != OK) | 210 if (rv != OK) |
200 return false; | 211 return false; |
| 212 tracked_objects::ScopedTracker tracking_profile_4( |
| 213 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 214 "455942 IsGloballyReachable (remainder)")); |
201 DCHECK_EQ(ADDRESS_FAMILY_IPV6, endpoint.GetFamily()); | 215 DCHECK_EQ(ADDRESS_FAMILY_IPV6, endpoint.GetFamily()); |
202 const IPAddressNumber& address = endpoint.address(); | 216 const IPAddressNumber& address = endpoint.address(); |
203 bool is_link_local = (address[0] == 0xFE) && ((address[1] & 0xC0) == 0x80); | 217 bool is_link_local = (address[0] == 0xFE) && ((address[1] & 0xC0) == 0x80); |
204 if (is_link_local) | 218 if (is_link_local) |
205 return false; | 219 return false; |
206 const uint8 kTeredoPrefix[] = { 0x20, 0x01, 0, 0 }; | 220 const uint8 kTeredoPrefix[] = { 0x20, 0x01, 0, 0 }; |
207 bool is_teredo = std::equal(kTeredoPrefix, | 221 bool is_teredo = std::equal(kTeredoPrefix, |
208 kTeredoPrefix + arraysize(kTeredoPrefix), | 222 kTeredoPrefix + arraysize(kTeredoPrefix), |
209 address.begin()); | 223 address.begin()); |
210 if (is_teredo) | 224 if (is_teredo) |
(...skipping 1669 matching lines...) Loading... |
1880 DCHECK(CalledOnValidThread()); | 1894 DCHECK(CalledOnValidThread()); |
1881 DCHECK_EQ(false, callback.is_null()); | 1895 DCHECK_EQ(false, callback.is_null()); |
1882 | 1896 |
1883 // Check that the caller supplied a valid hostname to resolve. | 1897 // Check that the caller supplied a valid hostname to resolve. |
1884 std::string labeled_hostname; | 1898 std::string labeled_hostname; |
1885 if (!DNSDomainFromDot(info.hostname(), &labeled_hostname)) | 1899 if (!DNSDomainFromDot(info.hostname(), &labeled_hostname)) |
1886 return ERR_NAME_NOT_RESOLVED; | 1900 return ERR_NAME_NOT_RESOLVED; |
1887 | 1901 |
1888 LogStartRequest(source_net_log, info); | 1902 LogStartRequest(source_net_log, info); |
1889 | 1903 |
| 1904 tracked_objects::ScopedTracker tracking_profile_1a( |
| 1905 FROM_HERE_WITH_EXPLICIT_FUNCTION("455942 HostResolverImpl::Resolve 1a")); |
| 1906 |
1890 IPAddressNumber ip_number; | 1907 IPAddressNumber ip_number; |
1891 IPAddressNumber* ip_number_ptr = nullptr; | 1908 IPAddressNumber* ip_number_ptr = nullptr; |
1892 if (ParseIPLiteralToNumber(info.hostname(), &ip_number)) | 1909 if (ParseIPLiteralToNumber(info.hostname(), &ip_number)) |
1893 ip_number_ptr = &ip_number; | 1910 ip_number_ptr = &ip_number; |
1894 | 1911 |
| 1912 tracked_objects::ScopedTracker tracking_profile_1b( |
| 1913 FROM_HERE_WITH_EXPLICIT_FUNCTION("455942 HostResolverImpl::Resolve 1b")); |
| 1914 |
1895 // Build a key that identifies the request in the cache and in the | 1915 // Build a key that identifies the request in the cache and in the |
1896 // outstanding jobs map. | 1916 // outstanding jobs map. |
1897 Key key = GetEffectiveKeyForRequest(info, ip_number_ptr, source_net_log); | 1917 Key key = GetEffectiveKeyForRequest(info, ip_number_ptr, source_net_log); |
1898 | 1918 |
1899 // TODO(eroman): Remove ScopedTracker below once crbug.com/455942 is fixed. | 1919 // TODO(eroman): Remove ScopedTracker below once crbug.com/455942 is fixed. |
1900 tracked_objects::ScopedTracker tracking_profile_2( | 1920 tracked_objects::ScopedTracker tracking_profile_2( |
1901 FROM_HERE_WITH_EXPLICIT_FUNCTION("455942 HostResolverImpl::Resolve 2")); | 1921 FROM_HERE_WITH_EXPLICIT_FUNCTION("455942 HostResolverImpl::Resolve 2")); |
1902 | 1922 |
1903 int rv = ResolveHelper(key, info, ip_number_ptr, addresses, source_net_log); | 1923 int rv = ResolveHelper(key, info, ip_number_ptr, addresses, source_net_log); |
1904 if (rv != ERR_DNS_CACHE_MISS) { | 1924 if (rv != ERR_DNS_CACHE_MISS) { |
1905 LogFinishRequest(source_net_log, info, rv); | 1925 LogFinishRequest(source_net_log, info, rv); |
1906 RecordTotalTime(HaveDnsConfig(), info.is_speculative(), base::TimeDelta()); | 1926 RecordTotalTime(HaveDnsConfig(), info.is_speculative(), base::TimeDelta()); |
1907 return rv; | 1927 return rv; |
1908 } | 1928 } |
1909 | 1929 |
1910 // TODO(eroman): Remove ScopedTracker below once crbug.com/455942 is fixed. | |
1911 tracked_objects::ScopedTracker tracking_profile_3( | |
1912 FROM_HERE_WITH_EXPLICIT_FUNCTION("455942 HostResolverImpl::Resolve 3")); | |
1913 | |
1914 // Next we need to attach our request to a "job". This job is responsible for | 1930 // Next we need to attach our request to a "job". This job is responsible for |
1915 // calling "getaddrinfo(hostname)" on a worker thread. | 1931 // calling "getaddrinfo(hostname)" on a worker thread. |
1916 | 1932 |
1917 JobMap::iterator jobit = jobs_.find(key); | 1933 JobMap::iterator jobit = jobs_.find(key); |
1918 Job* job; | 1934 Job* job; |
1919 if (jobit == jobs_.end()) { | 1935 if (jobit == jobs_.end()) { |
1920 // TODO(eroman): Remove ScopedTracker below once crbug.com/455942 is fixed. | |
1921 tracked_objects::ScopedTracker tracking_profile_4( | |
1922 FROM_HERE_WITH_EXPLICIT_FUNCTION("455942 HostResolverImpl::Resolve 4")); | |
1923 job = | 1936 job = |
1924 new Job(weak_ptr_factory_.GetWeakPtr(), key, priority, source_net_log); | 1937 new Job(weak_ptr_factory_.GetWeakPtr(), key, priority, source_net_log); |
1925 job->Schedule(false); | 1938 job->Schedule(false); |
1926 | 1939 |
1927 // TODO(eroman): Remove ScopedTracker below once crbug.com/455942 is fixed. | |
1928 tracked_objects::ScopedTracker tracking_profile_5( | |
1929 FROM_HERE_WITH_EXPLICIT_FUNCTION("455942 HostResolverImpl::Resolve 5")); | |
1930 | |
1931 // Check for queue overflow. | 1940 // Check for queue overflow. |
1932 if (dispatcher_->num_queued_jobs() > max_queued_jobs_) { | 1941 if (dispatcher_->num_queued_jobs() > max_queued_jobs_) { |
1933 Job* evicted = static_cast<Job*>(dispatcher_->EvictOldestLowest()); | 1942 Job* evicted = static_cast<Job*>(dispatcher_->EvictOldestLowest()); |
1934 DCHECK(evicted); | 1943 DCHECK(evicted); |
1935 evicted->OnEvicted(); // Deletes |evicted|. | 1944 evicted->OnEvicted(); // Deletes |evicted|. |
1936 if (evicted == job) { | 1945 if (evicted == job) { |
1937 rv = ERR_HOST_RESOLVER_QUEUE_TOO_LARGE; | 1946 rv = ERR_HOST_RESOLVER_QUEUE_TOO_LARGE; |
1938 LogFinishRequest(source_net_log, info, rv); | 1947 LogFinishRequest(source_net_log, info, rv); |
1939 return rv; | 1948 return rv; |
1940 } | 1949 } |
1941 } | 1950 } |
1942 jobs_.insert(jobit, std::make_pair(key, job)); | 1951 jobs_.insert(jobit, std::make_pair(key, job)); |
1943 } else { | 1952 } else { |
1944 job = jobit->second; | 1953 job = jobit->second; |
1945 } | 1954 } |
1946 | 1955 |
1947 // TODO(eroman): Remove ScopedTracker below once crbug.com/455942 is fixed. | |
1948 tracked_objects::ScopedTracker tracking_profile_6( | |
1949 FROM_HERE_WITH_EXPLICIT_FUNCTION("455942 HostResolverImpl::Resolve 6")); | |
1950 | |
1951 // Can't complete synchronously. Create and attach request. | 1956 // Can't complete synchronously. Create and attach request. |
1952 scoped_ptr<Request> req(new Request( | 1957 scoped_ptr<Request> req(new Request( |
1953 source_net_log, info, priority, callback, addresses)); | 1958 source_net_log, info, priority, callback, addresses)); |
1954 if (out_req) | 1959 if (out_req) |
1955 *out_req = reinterpret_cast<RequestHandle>(req.get()); | 1960 *out_req = reinterpret_cast<RequestHandle>(req.get()); |
1956 | 1961 |
1957 job->AddRequest(req.Pass()); | 1962 job->AddRequest(req.Pass()); |
1958 // Completion happens during Job::CompleteRequests(). | 1963 // Completion happens during Job::CompleteRequests(). |
1959 return ERR_IO_PENDING; | 1964 return ERR_IO_PENDING; |
1960 } | 1965 } |
(...skipping 450 matching lines...) Loading... |
2411 dns_client_->SetConfig(dns_config); | 2416 dns_client_->SetConfig(dns_config); |
2412 num_dns_failures_ = 0; | 2417 num_dns_failures_ = 0; |
2413 if (dns_client_->GetConfig()) | 2418 if (dns_client_->GetConfig()) |
2414 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", true); | 2419 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", true); |
2415 } | 2420 } |
2416 | 2421 |
2417 AbortDnsTasks(); | 2422 AbortDnsTasks(); |
2418 } | 2423 } |
2419 | 2424 |
2420 } // namespace net | 2425 } // namespace net |
OLD | NEW |