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 1855 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1866 max_queued_jobs_ = value; | 1866 max_queued_jobs_ = value; |
1867 } | 1867 } |
1868 | 1868 |
1869 int HostResolverImpl::Resolve(const RequestInfo& info, | 1869 int HostResolverImpl::Resolve(const RequestInfo& info, |
1870 RequestPriority priority, | 1870 RequestPriority priority, |
1871 AddressList* addresses, | 1871 AddressList* addresses, |
1872 const CompletionCallback& callback, | 1872 const CompletionCallback& callback, |
1873 RequestHandle* out_req, | 1873 RequestHandle* out_req, |
1874 const BoundNetLog& source_net_log) { | 1874 const BoundNetLog& source_net_log) { |
1875 // TODO(eroman): Remove ScopedTracker below once crbug.com/455942 is fixed. | 1875 // TODO(eroman): Remove ScopedTracker below once crbug.com/455942 is fixed. |
1876 tracked_objects::ScopedTracker tracking_profile( | 1876 tracked_objects::ScopedTracker tracking_profile_1( |
1877 FROM_HERE_WITH_EXPLICIT_FUNCTION("455942 HostResolverImpl::Resolve")); | 1877 FROM_HERE_WITH_EXPLICIT_FUNCTION("455942 HostResolverImpl::Resolve 1")); |
1878 | 1878 |
1879 DCHECK(addresses); | 1879 DCHECK(addresses); |
1880 DCHECK(CalledOnValidThread()); | 1880 DCHECK(CalledOnValidThread()); |
1881 DCHECK_EQ(false, callback.is_null()); | 1881 DCHECK_EQ(false, callback.is_null()); |
1882 | 1882 |
1883 // Check that the caller supplied a valid hostname to resolve. | 1883 // Check that the caller supplied a valid hostname to resolve. |
1884 std::string labeled_hostname; | 1884 std::string labeled_hostname; |
1885 if (!DNSDomainFromDot(info.hostname(), &labeled_hostname)) | 1885 if (!DNSDomainFromDot(info.hostname(), &labeled_hostname)) |
1886 return ERR_NAME_NOT_RESOLVED; | 1886 return ERR_NAME_NOT_RESOLVED; |
1887 | 1887 |
1888 LogStartRequest(source_net_log, info); | 1888 LogStartRequest(source_net_log, info); |
1889 | 1889 |
1890 IPAddressNumber ip_number; | 1890 IPAddressNumber ip_number; |
1891 IPAddressNumber* ip_number_ptr = nullptr; | 1891 IPAddressNumber* ip_number_ptr = nullptr; |
1892 if (ParseIPLiteralToNumber(info.hostname(), &ip_number)) | 1892 if (ParseIPLiteralToNumber(info.hostname(), &ip_number)) |
1893 ip_number_ptr = &ip_number; | 1893 ip_number_ptr = &ip_number; |
1894 | 1894 |
1895 // Build a key that identifies the request in the cache and in the | 1895 // Build a key that identifies the request in the cache and in the |
1896 // outstanding jobs map. | 1896 // outstanding jobs map. |
1897 Key key = GetEffectiveKeyForRequest(info, ip_number_ptr, source_net_log); | 1897 Key key = GetEffectiveKeyForRequest(info, ip_number_ptr, source_net_log); |
1898 | 1898 |
| 1899 // TODO(eroman): Remove ScopedTracker below once crbug.com/455942 is fixed. |
| 1900 tracked_objects::ScopedTracker tracking_profile_2( |
| 1901 FROM_HERE_WITH_EXPLICIT_FUNCTION("455942 HostResolverImpl::Resolve 2")); |
| 1902 |
1899 int rv = ResolveHelper(key, info, ip_number_ptr, addresses, source_net_log); | 1903 int rv = ResolveHelper(key, info, ip_number_ptr, addresses, source_net_log); |
1900 if (rv != ERR_DNS_CACHE_MISS) { | 1904 if (rv != ERR_DNS_CACHE_MISS) { |
1901 LogFinishRequest(source_net_log, info, rv); | 1905 LogFinishRequest(source_net_log, info, rv); |
1902 RecordTotalTime(HaveDnsConfig(), info.is_speculative(), base::TimeDelta()); | 1906 RecordTotalTime(HaveDnsConfig(), info.is_speculative(), base::TimeDelta()); |
1903 return rv; | 1907 return rv; |
1904 } | 1908 } |
1905 | 1909 |
| 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 |
1906 // Next we need to attach our request to a "job". This job is responsible for | 1914 // Next we need to attach our request to a "job". This job is responsible for |
1907 // calling "getaddrinfo(hostname)" on a worker thread. | 1915 // calling "getaddrinfo(hostname)" on a worker thread. |
1908 | 1916 |
1909 JobMap::iterator jobit = jobs_.find(key); | 1917 JobMap::iterator jobit = jobs_.find(key); |
1910 Job* job; | 1918 Job* job; |
1911 if (jobit == jobs_.end()) { | 1919 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")); |
1912 job = | 1923 job = |
1913 new Job(weak_ptr_factory_.GetWeakPtr(), key, priority, source_net_log); | 1924 new Job(weak_ptr_factory_.GetWeakPtr(), key, priority, source_net_log); |
1914 job->Schedule(false); | 1925 job->Schedule(false); |
1915 | 1926 |
| 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 |
1916 // Check for queue overflow. | 1931 // Check for queue overflow. |
1917 if (dispatcher_->num_queued_jobs() > max_queued_jobs_) { | 1932 if (dispatcher_->num_queued_jobs() > max_queued_jobs_) { |
1918 Job* evicted = static_cast<Job*>(dispatcher_->EvictOldestLowest()); | 1933 Job* evicted = static_cast<Job*>(dispatcher_->EvictOldestLowest()); |
1919 DCHECK(evicted); | 1934 DCHECK(evicted); |
1920 evicted->OnEvicted(); // Deletes |evicted|. | 1935 evicted->OnEvicted(); // Deletes |evicted|. |
1921 if (evicted == job) { | 1936 if (evicted == job) { |
1922 rv = ERR_HOST_RESOLVER_QUEUE_TOO_LARGE; | 1937 rv = ERR_HOST_RESOLVER_QUEUE_TOO_LARGE; |
1923 LogFinishRequest(source_net_log, info, rv); | 1938 LogFinishRequest(source_net_log, info, rv); |
1924 return rv; | 1939 return rv; |
1925 } | 1940 } |
1926 } | 1941 } |
1927 jobs_.insert(jobit, std::make_pair(key, job)); | 1942 jobs_.insert(jobit, std::make_pair(key, job)); |
1928 } else { | 1943 } else { |
1929 job = jobit->second; | 1944 job = jobit->second; |
1930 } | 1945 } |
1931 | 1946 |
| 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 |
1932 // Can't complete synchronously. Create and attach request. | 1951 // Can't complete synchronously. Create and attach request. |
1933 scoped_ptr<Request> req(new Request( | 1952 scoped_ptr<Request> req(new Request( |
1934 source_net_log, info, priority, callback, addresses)); | 1953 source_net_log, info, priority, callback, addresses)); |
1935 if (out_req) | 1954 if (out_req) |
1936 *out_req = reinterpret_cast<RequestHandle>(req.get()); | 1955 *out_req = reinterpret_cast<RequestHandle>(req.get()); |
1937 | 1956 |
1938 job->AddRequest(req.Pass()); | 1957 job->AddRequest(req.Pass()); |
1939 // Completion happens during Job::CompleteRequests(). | 1958 // Completion happens during Job::CompleteRequests(). |
1940 return ERR_IO_PENDING; | 1959 return ERR_IO_PENDING; |
1941 } | 1960 } |
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2392 dns_client_->SetConfig(dns_config); | 2411 dns_client_->SetConfig(dns_config); |
2393 num_dns_failures_ = 0; | 2412 num_dns_failures_ = 0; |
2394 if (dns_client_->GetConfig()) | 2413 if (dns_client_->GetConfig()) |
2395 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", true); | 2414 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", true); |
2396 } | 2415 } |
2397 | 2416 |
2398 AbortDnsTasks(); | 2417 AbortDnsTasks(); |
2399 } | 2418 } |
2400 | 2419 |
2401 } // namespace net | 2420 } // namespace net |
OLD | NEW |