Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(240)

Side by Side Diff: net/dns/host_resolver_impl.cc

Issue 2389613002: Remove stl_util's deletion functions from net/dns/. (Closed)
Patch Set: rev Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/dns/host_resolver_impl.h ('k') | net/dns/mdns_client_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 12 matching lines...) Expand all
23 #include "base/debug/debugger.h" 23 #include "base/debug/debugger.h"
24 #include "base/debug/leak_annotations.h" 24 #include "base/debug/leak_annotations.h"
25 #include "base/debug/stack_trace.h" 25 #include "base/debug/stack_trace.h"
26 #include "base/macros.h" 26 #include "base/macros.h"
27 #include "base/memory/ptr_util.h" 27 #include "base/memory/ptr_util.h"
28 #include "base/metrics/field_trial.h" 28 #include "base/metrics/field_trial.h"
29 #include "base/metrics/histogram_macros.h" 29 #include "base/metrics/histogram_macros.h"
30 #include "base/metrics/sparse_histogram.h" 30 #include "base/metrics/sparse_histogram.h"
31 #include "base/profiler/scoped_tracker.h" 31 #include "base/profiler/scoped_tracker.h"
32 #include "base/single_thread_task_runner.h" 32 #include "base/single_thread_task_runner.h"
33 #include "base/stl_util.h"
34 #include "base/strings/string_util.h" 33 #include "base/strings/string_util.h"
35 #include "base/strings/utf_string_conversions.h" 34 #include "base/strings/utf_string_conversions.h"
36 #include "base/threading/thread_task_runner_handle.h" 35 #include "base/threading/thread_task_runner_handle.h"
37 #include "base/threading/worker_pool.h" 36 #include "base/threading/worker_pool.h"
38 #include "base/time/time.h" 37 #include "base/time/time.h"
39 #include "base/trace_event/trace_event.h" 38 #include "base/trace_event/trace_event.h"
40 #include "base/values.h" 39 #include "base/values.h"
41 #include "net/base/address_family.h" 40 #include "net/base/address_family.h"
42 #include "net/base/address_list.h" 41 #include "net/base/address_list.h"
43 #include "net/base/host_port_pair.h" 42 #include "net/base/host_port_pair.h"
(...skipping 1684 matching lines...) Expand 10 before | Expand all | Expand 10 after
1728 1727
1729 // Performs Job's last rites. Completes all Requests. Deletes this. 1728 // Performs Job's last rites. Completes all Requests. Deletes this.
1730 void CompleteRequests(const HostCache::Entry& entry, 1729 void CompleteRequests(const HostCache::Entry& entry,
1731 base::TimeDelta ttl) { 1730 base::TimeDelta ttl) {
1732 CHECK(resolver_.get()); 1731 CHECK(resolver_.get());
1733 1732
1734 // This job must be removed from resolver's |jobs_| now to make room for a 1733 // This job must be removed from resolver's |jobs_| now to make room for a
1735 // new job with the same key in case one of the OnComplete callbacks decides 1734 // new job with the same key in case one of the OnComplete callbacks decides
1736 // to spawn one. Consequently, the job deletes itself when CompleteRequests 1735 // to spawn one. Consequently, the job deletes itself when CompleteRequests
1737 // is done. 1736 // is done.
1738 std::unique_ptr<Job> self_deleter(this); 1737 std::unique_ptr<Job> self_deleter = resolver_->RemoveJob(this);
1739
1740 resolver_->RemoveJob(this);
1741 1738
1742 if (is_running()) { 1739 if (is_running()) {
1743 if (is_proc_running()) { 1740 if (is_proc_running()) {
1744 DCHECK(!is_queued()); 1741 DCHECK(!is_queued());
1745 proc_task_->Cancel(); 1742 proc_task_->Cancel();
1746 proc_task_ = nullptr; 1743 proc_task_ = nullptr;
1747 } 1744 }
1748 KillDnsTask(); 1745 KillDnsTask();
1749 1746
1750 // Signal dispatcher that a slot has opened. 1747 // Signal dispatcher that a slot has opened.
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
1888 1885
1889 HostResolverImpl::HostResolverImpl(const Options& options, NetLog* net_log) 1886 HostResolverImpl::HostResolverImpl(const Options& options, NetLog* net_log)
1890 : HostResolverImpl( 1887 : HostResolverImpl(
1891 options, 1888 options,
1892 net_log, 1889 net_log,
1893 base::WorkerPool::GetTaskRunner(true /* task_is_slow */)) {} 1890 base::WorkerPool::GetTaskRunner(true /* task_is_slow */)) {}
1894 1891
1895 HostResolverImpl::~HostResolverImpl() { 1892 HostResolverImpl::~HostResolverImpl() {
1896 // Prevent the dispatcher from starting new jobs. 1893 // Prevent the dispatcher from starting new jobs.
1897 dispatcher_->SetLimitsToZero(); 1894 dispatcher_->SetLimitsToZero();
1898 // It's now safe for Jobs to call KillDsnTask on destruction, because 1895 // It's now safe for Jobs to call KillDnsTask on destruction, because
1899 // OnJobComplete will not start any new jobs. 1896 // OnJobComplete will not start any new jobs.
1900 base::STLDeleteValues(&jobs_); 1897 jobs_.clear();
1901 1898
1902 NetworkChangeNotifier::RemoveIPAddressObserver(this); 1899 NetworkChangeNotifier::RemoveIPAddressObserver(this);
1903 NetworkChangeNotifier::RemoveConnectionTypeObserver(this); 1900 NetworkChangeNotifier::RemoveConnectionTypeObserver(this);
1904 NetworkChangeNotifier::RemoveDNSObserver(this); 1901 NetworkChangeNotifier::RemoveDNSObserver(this);
1905 } 1902 }
1906 1903
1907 void HostResolverImpl::SetMaxQueuedJobs(size_t value) { 1904 void HostResolverImpl::SetMaxQueuedJobs(size_t value) {
1908 DCHECK_EQ(0u, dispatcher_->num_queued_jobs()); 1905 DCHECK_EQ(0u, dispatcher_->num_queued_jobs());
1909 DCHECK_GT(value, 0u); 1906 DCHECK_GT(value, 0u);
1910 max_queued_jobs_ = value; 1907 max_queued_jobs_ = value;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1959 if (dispatcher_->num_queued_jobs() > max_queued_jobs_) { 1956 if (dispatcher_->num_queued_jobs() > max_queued_jobs_) {
1960 Job* evicted = static_cast<Job*>(dispatcher_->EvictOldestLowest()); 1957 Job* evicted = static_cast<Job*>(dispatcher_->EvictOldestLowest());
1961 DCHECK(evicted); 1958 DCHECK(evicted);
1962 evicted->OnEvicted(); // Deletes |evicted|. 1959 evicted->OnEvicted(); // Deletes |evicted|.
1963 if (evicted == job) { 1960 if (evicted == job) {
1964 rv = ERR_HOST_RESOLVER_QUEUE_TOO_LARGE; 1961 rv = ERR_HOST_RESOLVER_QUEUE_TOO_LARGE;
1965 LogFinishRequest(source_net_log, info, rv); 1962 LogFinishRequest(source_net_log, info, rv);
1966 return rv; 1963 return rv;
1967 } 1964 }
1968 } 1965 }
1969 jobs_.insert(jobit, std::make_pair(key, job)); 1966 jobs_.insert(jobit, std::make_pair(key, base::WrapUnique(job)));
1970 } else { 1967 } else {
1971 job = jobit->second; 1968 job = jobit->second.get();
1972 } 1969 }
1973 1970
1974 // Can't complete synchronously. Create and attach request. 1971 // Can't complete synchronously. Create and attach request.
1975 std::unique_ptr<RequestImpl> req(new RequestImpl( 1972 std::unique_ptr<RequestImpl> req(new RequestImpl(
1976 source_net_log, info, priority, callback, addresses, job)); 1973 source_net_log, info, priority, callback, addresses, job));
1977 job->AddRequest(req.get()); 1974 job->AddRequest(req.get());
1978 *out_req = std::move(req); 1975 *out_req = std::move(req);
1979 1976
1980 // Completion happens during Job::CompleteRequests(). 1977 // Completion happens during Job::CompleteRequests().
1981 return ERR_IO_PENDING; 1978 return ERR_IO_PENDING;
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
2293 return true; 2290 return true;
2294 } 2291 }
2295 2292
2296 void HostResolverImpl::CacheResult(const Key& key, 2293 void HostResolverImpl::CacheResult(const Key& key,
2297 const HostCache::Entry& entry, 2294 const HostCache::Entry& entry,
2298 base::TimeDelta ttl) { 2295 base::TimeDelta ttl) {
2299 if (cache_.get()) 2296 if (cache_.get())
2300 cache_->Set(key, entry, base::TimeTicks::Now(), ttl); 2297 cache_->Set(key, entry, base::TimeTicks::Now(), ttl);
2301 } 2298 }
2302 2299
2303 void HostResolverImpl::RemoveJob(Job* job) { 2300 std::unique_ptr<Job> HostResolverImpl::RemoveJob(Job* job) {
2304 DCHECK(job); 2301 DCHECK(job);
2305 JobMap::iterator it = jobs_.find(job->key()); 2302 JobMap::iterator it = jobs_.find(job->key());
2306 if (it != jobs_.end() && it->second == job) 2303 if (it != jobs_.end() && it->second.get() == job) {
2304 std::unique_ptr<Job> job = std::move(it->second);
2307 jobs_.erase(it); 2305 jobs_.erase(it);
2306 return job;
2307 }
davidben 2016/11/09 23:17:54 return nullptr?
2308 } 2308 }
2309 2309
2310 HostResolverImpl::Key HostResolverImpl::GetEffectiveKeyForRequest( 2310 HostResolverImpl::Key HostResolverImpl::GetEffectiveKeyForRequest(
2311 const RequestInfo& info, 2311 const RequestInfo& info,
2312 const IPAddress* ip_address, 2312 const IPAddress* ip_address,
2313 const NetLogWithSource& net_log) { 2313 const NetLogWithSource& net_log) {
2314 HostResolverFlags effective_flags = 2314 HostResolverFlags effective_flags =
2315 info.host_resolver_flags() | additional_resolver_flags_; 2315 info.host_resolver_flags() | additional_resolver_flags_;
2316 AddressFamily effective_address_family = info.address_family(); 2316 AddressFamily effective_address_family = info.address_family();
2317 2317
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
2352 void HostResolverImpl::RunLoopbackProbeJob() { 2352 void HostResolverImpl::RunLoopbackProbeJob() {
2353 new LoopbackProbeJob(weak_ptr_factory_.GetWeakPtr(), 2353 new LoopbackProbeJob(weak_ptr_factory_.GetWeakPtr(),
2354 worker_task_runner_.get()); 2354 worker_task_runner_.get());
2355 } 2355 }
2356 2356
2357 void HostResolverImpl::AbortAllInProgressJobs() { 2357 void HostResolverImpl::AbortAllInProgressJobs() {
2358 // In Abort, a Request callback could spawn new Jobs with matching keys, so 2358 // In Abort, a Request callback could spawn new Jobs with matching keys, so
2359 // first collect and remove all running jobs from |jobs_|. 2359 // first collect and remove all running jobs from |jobs_|.
2360 std::vector<std::unique_ptr<Job>> jobs_to_abort; 2360 std::vector<std::unique_ptr<Job>> jobs_to_abort;
2361 for (JobMap::iterator it = jobs_.begin(); it != jobs_.end(); ) { 2361 for (JobMap::iterator it = jobs_.begin(); it != jobs_.end(); ) {
2362 Job* job = it->second; 2362 Job* job = it->second.get();
2363 if (job->is_running()) { 2363 if (job->is_running()) {
2364 jobs_to_abort.push_back(base::WrapUnique(job)); 2364 jobs_to_abort.push_back(std::move(it->second));
2365 jobs_.erase(it++); 2365 jobs_.erase(it++);
2366 } else { 2366 } else {
2367 DCHECK(job->is_queued()); 2367 DCHECK(job->is_queued());
2368 ++it; 2368 ++it;
2369 } 2369 }
2370 } 2370 }
2371 2371
2372 // Pause the dispatcher so it won't start any new dispatcher jobs while 2372 // Pause the dispatcher so it won't start any new dispatcher jobs while
2373 // aborting the old ones. This is needed so that it won't start the second 2373 // aborting the old ones. This is needed so that it won't start the second
2374 // DnsTransaction for a job in |jobs_to_abort| if the DnsConfig just became 2374 // DnsTransaction for a job in |jobs_to_abort| if the DnsConfig just became
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
2407 if (!HaveDnsConfig()) 2407 if (!HaveDnsConfig())
2408 return; 2408 return;
2409 2409
2410 // TODO(szym): Do not do this if nsswitch.conf instructs not to. 2410 // TODO(szym): Do not do this if nsswitch.conf instructs not to.
2411 // http://crbug.com/117655 2411 // http://crbug.com/117655
2412 2412
2413 // Life check to bail once |this| is deleted. 2413 // Life check to bail once |this| is deleted.
2414 base::WeakPtr<HostResolverImpl> self = weak_ptr_factory_.GetWeakPtr(); 2414 base::WeakPtr<HostResolverImpl> self = weak_ptr_factory_.GetWeakPtr();
2415 2415
2416 for (JobMap::iterator it = jobs_.begin(); self.get() && it != jobs_.end();) { 2416 for (JobMap::iterator it = jobs_.begin(); self.get() && it != jobs_.end();) {
2417 Job* job = it->second; 2417 Job* job = it->second.get();
2418 ++it; 2418 ++it;
2419 // This could remove |job| from |jobs_|, but iterator will remain valid. 2419 // This could remove |job| from |jobs_|, but iterator will remain valid.
2420 job->ServeFromHosts(); 2420 job->ServeFromHosts();
2421 } 2421 }
2422 } 2422 }
2423 2423
2424 void HostResolverImpl::OnIPAddressChanged() { 2424 void HostResolverImpl::OnIPAddressChanged() {
2425 resolved_known_ipv6_hostname_ = false; 2425 resolved_known_ipv6_hostname_ = false;
2426 last_ipv6_probe_time_ = base::TimeTicks(); 2426 last_ipv6_probe_time_ = base::TimeTicks();
2427 // Abandon all ProbeJobs. 2427 // Abandon all ProbeJobs.
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
2609 if (job_) 2609 if (job_)
2610 job_->CancelRequest(this); 2610 job_->CancelRequest(this);
2611 } 2611 }
2612 2612
2613 void HostResolverImpl::RequestImpl::ChangeRequestPriority( 2613 void HostResolverImpl::RequestImpl::ChangeRequestPriority(
2614 RequestPriority priority) { 2614 RequestPriority priority) {
2615 job_->ChangeRequestPriority(this, priority); 2615 job_->ChangeRequestPriority(this, priority);
2616 } 2616 }
2617 2617
2618 } // namespace net 2618 } // namespace net
OLDNEW
« no previous file with comments | « net/dns/host_resolver_impl.h ('k') | net/dns/mdns_client_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698