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

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

Issue 2116983002: Change HostResolver::Resolve() to take an std::unique_ptr<Request>* rather than a RequestHandle* (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 months 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
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 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 } 521 }
522 522
523 return true; 523 return true;
524 } 524 }
525 525
526 const unsigned HostResolverImpl::kMaximumDnsFailures = 16; 526 const unsigned HostResolverImpl::kMaximumDnsFailures = 16;
527 527
528 // Holds the data for a request that could not be completed synchronously. 528 // Holds the data for a request that could not be completed synchronously.
529 // It is owned by a Job. Canceled Requests are only marked as canceled rather 529 // It is owned by a Job. Canceled Requests are only marked as canceled rather
530 // than removed from the Job's |requests_| list. 530 // than removed from the Job's |requests_| list.
531 class HostResolverImpl::Request { 531 class HostResolverImpl::RequestImpl : public HostResolver::Request {
532 public: 532 public:
533 Request(const BoundNetLog& source_net_log, 533 RequestImpl(const BoundNetLog& source_net_log,
534 const RequestInfo& info, 534 const RequestInfo& info,
535 RequestPriority priority, 535 RequestPriority priority,
536 const CompletionCallback& callback, 536 const CompletionCallback& callback,
537 AddressList* addresses) 537 AddressList* addresses)
538 : source_net_log_(source_net_log), 538 : source_net_log_(source_net_log),
539 info_(info), 539 info_(info),
540 priority_(priority), 540 priority_(priority),
541 job_(nullptr), 541 job_(nullptr),
542 callback_(callback), 542 callback_(callback),
543 addresses_(addresses), 543 addresses_(addresses),
544 request_time_(base::TimeTicks::Now()) {} 544 request_time_(base::TimeTicks::Now()) {}
545 545
546 // Mark the request as canceled. 546 ~RequestImpl() override;
547 void MarkAsCanceled() {
548 job_ = nullptr;
549 addresses_ = nullptr;
550 callback_.Reset();
551 }
552 547
553 bool was_canceled() const { 548 void ChangeRequestPriority(RequestPriority priority) override;
554 return callback_.is_null();
555 }
556 549
557 void set_job(Job* job) { 550 void set_job(Job* job) {
558 DCHECK(job); 551 DCHECK(job);
559 // Identify which job the request is waiting on. 552 // Identify which job the request is waiting on.
560 job_ = job; 553 job_ = job;
561 } 554 }
562 555
563 // Prepare final AddressList and call completion callback. 556 // Prepare final AddressList and call completion callback.
564 void OnComplete(int error, const AddressList& addr_list) { 557 void OnComplete(int error, const AddressList& addr_list) {
565 DCHECK(!was_canceled());
566 if (error == OK) 558 if (error == OK)
567 *addresses_ = EnsurePortOnAddressList(addr_list, info_.port()); 559 *addresses_ = EnsurePortOnAddressList(addr_list, info_.port());
568 CompletionCallback callback = callback_; 560 CompletionCallback callback = callback_;
569 MarkAsCanceled(); 561 MarkAsCompleted();
570 callback.Run(error); 562 callback.Run(error);
571 } 563 }
572 564
565 void MarkAsCompleted() {
566 RemoveJob();
567 addresses_ = nullptr;
568 callback_.Reset();
569 }
570
571 bool MarkedAsCompleted() { return callback_.is_null(); }
572
573 Job* job() const { 573 Job* job() const {
574 return job_; 574 return job_;
575 } 575 }
576 576
577 void RemoveJob();
578
577 // NetLog for the source, passed in HostResolver::Resolve. 579 // NetLog for the source, passed in HostResolver::Resolve.
578 const BoundNetLog& source_net_log() { 580 const BoundNetLog& source_net_log() const { return source_net_log_; }
579 return source_net_log_;
580 }
581 581
582 const RequestInfo& info() const { 582 const RequestInfo& info() const {
583 return info_; 583 return info_;
584 } 584 }
585 585
586 RequestPriority priority() const { return priority_; } 586 RequestPriority priority() const { return priority_; }
587 void set_priority(RequestPriority priority) { priority_ = priority; } 587 void set_priority(RequestPriority priority) { priority_ = priority; }
588 588
589 base::TimeTicks request_time() const { return request_time_; } 589 base::TimeTicks request_time() const { return request_time_; }
590 590
591 private: 591 private:
592 const BoundNetLog source_net_log_; 592 const BoundNetLog source_net_log_;
593 593
594 // The request info that started the request. 594 // The request info that started the request.
595 const RequestInfo info_; 595 const RequestInfo info_;
596 596
597 RequestPriority priority_; 597 RequestPriority priority_;
598 598
599 // The resolve job that this request is dependent on. 599 // The resolve job that this request is dependent on.
600 Job* job_; 600 Job* job_;
601 601
602 // The user's callback to invoke when the request completes. 602 // The user's callback to invoke when the request completes.
603 CompletionCallback callback_; 603 CompletionCallback callback_;
604 604
605 // The address list to save result into. 605 // The address list to save result into.
606 AddressList* addresses_; 606 AddressList* addresses_;
607 607
608 const base::TimeTicks request_time_; 608 const base::TimeTicks request_time_;
609 609
610 DISALLOW_COPY_AND_ASSIGN(Request); 610 DISALLOW_COPY_AND_ASSIGN(RequestImpl);
611 }; 611 };
612 612
613 //------------------------------------------------------------------------------ 613 //------------------------------------------------------------------------------
614 614
615 // Calls HostResolverProc using a worker task runner. Performs retries if 615 // Calls HostResolverProc using a worker task runner. Performs retries if
616 // necessary. 616 // necessary.
617 // 617 //
618 // Whenever we try to resolve the host, we post a delayed task to check if host 618 // Whenever we try to resolve the host, we post a delayed task to check if host
619 // resolution (OnLookupComplete) is completed or not. If the original attempt 619 // resolution (OnLookupComplete) is completed or not. If the original attempt
620 // hasn't completed, then we start another attempt for host resolution. We take 620 // hasn't completed, then we start another attempt for host resolution. We take
(...skipping 697 matching lines...) Expand 10 before | Expand all | Expand 10 after
1318 ERR_ABORTED); 1318 ERR_ABORTED);
1319 } else if (is_queued()) { 1319 } else if (is_queued()) {
1320 // |resolver_| was destroyed without running this Job. 1320 // |resolver_| was destroyed without running this Job.
1321 // TODO(szym): is there any benefit in having this distinction? 1321 // TODO(szym): is there any benefit in having this distinction?
1322 net_log_.AddEvent(NetLog::TYPE_CANCELLED); 1322 net_log_.AddEvent(NetLog::TYPE_CANCELLED);
1323 net_log_.EndEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_JOB); 1323 net_log_.EndEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_JOB);
1324 } 1324 }
1325 // else CompleteRequests logged EndEvent. 1325 // else CompleteRequests logged EndEvent.
1326 1326
1327 // Log any remaining Requests as cancelled. 1327 // Log any remaining Requests as cancelled.
1328 for (const std::unique_ptr<Request>& req : requests_) { 1328 for (RequestImpl* req : requests_) {
1329 if (req->was_canceled()) 1329 if (!req || req->MarkedAsCompleted())
1330 continue; 1330 continue;
1331 DCHECK_EQ(this, req->job()); 1331 DCHECK_EQ(this, req->job());
1332 LogCancelRequest(req->source_net_log(), req->info()); 1332 LogCancelRequest(req->source_net_log(), req->info());
1333 req->MarkAsCompleted();
1333 } 1334 }
1334 } 1335 }
1335 1336
1336 // Add this job to the dispatcher. If "at_head" is true, adds at the front 1337 // Add this job to the dispatcher. If "at_head" is true, adds at the front
1337 // of the queue. 1338 // of the queue.
1338 void Schedule(bool at_head) { 1339 void Schedule(bool at_head) {
1339 DCHECK(!is_queued()); 1340 DCHECK(!is_queued());
1340 PrioritizedDispatcher::Handle handle; 1341 PrioritizedDispatcher::Handle handle;
1341 if (!at_head) { 1342 if (!at_head) {
1342 handle = resolver_->dispatcher_->Add(this, priority()); 1343 handle = resolver_->dispatcher_->Add(this, priority());
1343 } else { 1344 } else {
1344 handle = resolver_->dispatcher_->AddAtHead(this, priority()); 1345 handle = resolver_->dispatcher_->AddAtHead(this, priority());
1345 } 1346 }
1346 // The dispatcher could have started |this| in the above call to Add, which 1347 // The dispatcher could have started |this| in the above call to Add, which
1347 // could have called Schedule again. In that case |handle| will be null, 1348 // could have called Schedule again. In that case |handle| will be null,
1348 // but |handle_| may have been set by the other nested call to Schedule. 1349 // but |handle_| may have been set by the other nested call to Schedule.
1349 if (!handle.is_null()) { 1350 if (!handle.is_null()) {
1350 DCHECK(handle_.is_null()); 1351 DCHECK(handle_.is_null());
1351 handle_ = handle; 1352 handle_ = handle;
1352 } 1353 }
1353 } 1354 }
1354 1355
1355 void AddRequest(std::unique_ptr<Request> req) { 1356 void AddRequest(RequestImpl* req) {
1356 DCHECK_EQ(key_.hostname, req->info().hostname()); 1357 DCHECK_EQ(key_.hostname, req->info().hostname());
1357 1358
1358 req->set_job(this); 1359 req->set_job(this);
1359 priority_tracker_.Add(req->priority()); 1360 priority_tracker_.Add(req->priority());
1360 1361
1361 req->source_net_log().AddEvent( 1362 req->source_net_log().AddEvent(
1362 NetLog::TYPE_HOST_RESOLVER_IMPL_JOB_ATTACH, 1363 NetLog::TYPE_HOST_RESOLVER_IMPL_JOB_ATTACH,
1363 net_log_.source().ToEventParametersCallback()); 1364 net_log_.source().ToEventParametersCallback());
1364 1365
1365 net_log_.AddEvent( 1366 net_log_.AddEvent(
1366 NetLog::TYPE_HOST_RESOLVER_IMPL_JOB_REQUEST_ATTACH, 1367 NetLog::TYPE_HOST_RESOLVER_IMPL_JOB_REQUEST_ATTACH,
1367 base::Bind(&NetLogJobAttachCallback, 1368 base::Bind(&NetLogJobAttachCallback,
1368 req->source_net_log().source(), 1369 req->source_net_log().source(),
1369 priority())); 1370 priority()));
1370 1371
1371 // TODO(szym): Check if this is still needed. 1372 // TODO(szym): Check if this is still needed.
1372 if (!req->info().is_speculative()) { 1373 if (!req->info().is_speculative()) {
1373 had_non_speculative_request_ = true; 1374 had_non_speculative_request_ = true;
1374 if (proc_task_.get()) 1375 if (proc_task_.get())
1375 proc_task_->set_had_non_speculative_request(); 1376 proc_task_->set_had_non_speculative_request();
1376 } 1377 }
1377 1378
1378 requests_.push_back(std::move(req)); 1379 requests_.push_back(req);
1379 1380
1380 UpdatePriority(); 1381 UpdatePriority();
1381 } 1382 }
1382 1383
1383 void ChangeRequestPriority(Request* req, RequestPriority priority) { 1384 void ChangeRequestPriority(RequestImpl* req, RequestPriority priority) {
1384 DCHECK_EQ(key_.hostname, req->info().hostname()); 1385 DCHECK_EQ(key_.hostname, req->info().hostname());
1385 DCHECK(!req->was_canceled());
1386 1386
1387 priority_tracker_.Remove(req->priority()); 1387 priority_tracker_.Remove(req->priority());
1388 req->set_priority(priority); 1388 req->set_priority(priority);
1389 priority_tracker_.Add(req->priority()); 1389 priority_tracker_.Add(req->priority());
1390 UpdatePriority(); 1390 UpdatePriority();
1391 } 1391 }
1392 1392
1393 // Marks |req| as cancelled. If it was the last active Request, also finishes 1393 // Remove |req|. If it was the last active Request, also finishes
1394 // this Job, marking it as cancelled, and deletes it. 1394 // this Job, marking it as cancelled, and deletes it.
1395 void CancelRequest(Request* req) { 1395 void CancelRequest(RequestImpl* req) {
1396 DCHECK_EQ(key_.hostname, req->info().hostname()); 1396 DCHECK_EQ(key_.hostname, req->info().hostname());
1397 DCHECK(!req->was_canceled());
1398 1397
1399 // Don't remove it from |requests_| just mark it canceled. 1398 RemoveRequest(req);
1400 req->MarkAsCanceled();
1401 LogCancelRequest(req->source_net_log(), req->info()); 1399 LogCancelRequest(req->source_net_log(), req->info());
1402 1400
1403 priority_tracker_.Remove(req->priority());
1404 net_log_.AddEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_JOB_REQUEST_DETACH, 1401 net_log_.AddEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_JOB_REQUEST_DETACH,
1405 base::Bind(&NetLogJobAttachCallback, 1402 base::Bind(&NetLogJobAttachCallback,
1406 req->source_net_log().source(), 1403 req->source_net_log().source(), priority()));
1407 priority()));
1408 1404
1409 if (num_active_requests() > 0) { 1405 if (num_active_requests() > 0) {
1410 UpdatePriority(); 1406 UpdatePriority();
1411 } else { 1407 } else {
1412 // If we were called from a Request's callback within CompleteRequests, 1408 // If we were called from a Request's callback within CompleteRequests,
1413 // that Request could not have been cancelled, so num_active_requests() 1409 // that Request could not have been cancelled, so num_active_requests()
1414 // could not be 0. Therefore, we are not in CompleteRequests(). 1410 // could not be 0. Therefore, we are not in CompleteRequests().
1415 CompleteRequestsWithError(OK /* cancelled */); 1411 CompleteRequestsWithError(OK /* cancelled */);
1416 } 1412 }
1417 } 1413 }
1418 1414
1415 void RemoveRequest(RequestImpl* req) {
1416 size_t req_position =
1417 std::find(requests_.begin(), requests_.end(), req) - requests_.begin();
1418 if (req_position >= requests_.size())
1419 return; // no request found, might have already been removed
mmenke 2016/07/12 18:50:23 Does this case ever happen? Doesn't seem like it
maksims (do not use this acc) 2016/07/13 11:40:26 right, I just wanted to be sure.
1420
1421 priority_tracker_.Remove(req->priority());
1422 requests_[req_position] = nullptr;
mmenke 2016/07/12 18:50:23 Growing requests_ eternally over the lifetime of t
maksims (do not use this acc) 2016/07/13 11:40:27 The problem is that the request might have already
mmenke 2016/07/14 18:25:31 Right, the problem is CancelRequest calls this met
maksims (do not use this acc) 2016/07/19 15:00:26 It should be better now considering changed the re
1423 }
1424
1419 // Called from AbortAllInProgressJobs. Completes all requests and destroys 1425 // Called from AbortAllInProgressJobs. Completes all requests and destroys
1420 // the job. This currently assumes the abort is due to a network change. 1426 // the job. This currently assumes the abort is due to a network change.
1421 // TODO This should not delete |this|. 1427 // TODO This should not delete |this|.
1422 void Abort() { 1428 void Abort() {
1423 DCHECK(is_running()); 1429 DCHECK(is_running());
1424 CompleteRequestsWithError(ERR_NETWORK_CHANGED); 1430 CompleteRequestsWithError(ERR_NETWORK_CHANGED);
1425 } 1431 }
1426 1432
1427 // If DnsTask present, abort it and fall back to ProcTask. 1433 // If DnsTask present, abort it and fall back to ProcTask.
1428 void AbortDnsTask() { 1434 void AbortDnsTask() {
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
1491 resolver_->dispatcher_->Cancel(handle_); 1497 resolver_->dispatcher_->Cancel(handle_);
1492 handle_.Reset(); 1498 handle_.Reset();
1493 } else if (num_occupied_job_slots_ > 1) { 1499 } else if (num_occupied_job_slots_ > 1) {
1494 resolver_->dispatcher_->OnJobFinished(); 1500 resolver_->dispatcher_->OnJobFinished();
1495 --num_occupied_job_slots_; 1501 --num_occupied_job_slots_;
1496 } 1502 }
1497 DCHECK_EQ(1u, num_occupied_job_slots_); 1503 DCHECK_EQ(1u, num_occupied_job_slots_);
1498 } 1504 }
1499 1505
1500 AddressList MakeAddressListForRequest(const AddressList& list) const { 1506 AddressList MakeAddressListForRequest(const AddressList& list) const {
1501 if (requests_.empty()) 1507 if (requests_.empty()) {
mmenke 2016/07/12 18:50:23 We walk through everything in requests_ if request
maksims (do not use this acc) 2016/07/13 11:40:27 no,no,no. my fault. sorry
maksims (do not use this acc) 2016/07/19 15:00:26 Reverted as long as new implementation allows old
1502 return list; 1508 for (const RequestImpl* req : requests_) {
1503 return AddressList::CopyWithPort(list, requests_.front()->info().port()); 1509 if (!req)
1510 continue;
1511 return AddressList::CopyWithPort(list, req->info().port());
1512 }
1513 }
1514 return list;
1504 } 1515 }
1505 1516
1506 void UpdatePriority() { 1517 void UpdatePriority() {
1507 if (is_queued()) { 1518 if (is_queued()) {
1508 if (priority() != static_cast<RequestPriority>(handle_.priority())) 1519 if (priority() != static_cast<RequestPriority>(handle_.priority()))
1509 priority_change_time_ = base::TimeTicks::Now(); 1520 priority_change_time_ = base::TimeTicks::Now();
1510 handle_ = resolver_->dispatcher_->ChangePriority(handle_, priority()); 1521 handle_ = resolver_->dispatcher_->ChangePriority(handle_, priority());
1511 } 1522 }
1512 } 1523 }
1513 1524
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
1770 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.HaveDnsConfig", 1781 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.HaveDnsConfig",
1771 resolver_->received_dns_config_); 1782 resolver_->received_dns_config_);
1772 } 1783 }
1773 1784
1774 bool did_complete = (entry.error() != ERR_NETWORK_CHANGED) && 1785 bool did_complete = (entry.error() != ERR_NETWORK_CHANGED) &&
1775 (entry.error() != ERR_HOST_RESOLVER_QUEUE_TOO_LARGE); 1786 (entry.error() != ERR_HOST_RESOLVER_QUEUE_TOO_LARGE);
1776 if (did_complete) 1787 if (did_complete)
1777 resolver_->CacheResult(key_, entry, ttl); 1788 resolver_->CacheResult(key_, entry, ttl);
1778 1789
1779 // Complete all of the requests that were attached to the job. 1790 // Complete all of the requests that were attached to the job.
1780 for (const std::unique_ptr<Request>& req : requests_) { 1791 for (RequestImpl* req : requests_) {
1781 if (req->was_canceled()) 1792 if (!req || req->MarkedAsCompleted())
1782 continue; 1793 continue;
1783
1784 DCHECK_EQ(this, req->job()); 1794 DCHECK_EQ(this, req->job());
1785 // Update the net log and notify registered observers. 1795 // Update the net log and notify registered observers.
1786 LogFinishRequest(req->source_net_log(), req->info(), entry.error()); 1796 LogFinishRequest(req->source_net_log(), req->info(), entry.error());
1787 if (did_complete) { 1797 if (did_complete) {
1788 // Record effective total time from creation to completion. 1798 // Record effective total time from creation to completion.
1789 RecordTotalTime(had_dns_config_, req->info().is_speculative(), 1799 RecordTotalTime(had_dns_config_, req->info().is_speculative(),
1790 base::TimeTicks::Now() - req->request_time()); 1800 base::TimeTicks::Now() - req->request_time());
1791 } 1801 }
1792 req->OnComplete(entry.error(), entry.addresses()); 1802 req->OnComplete(entry.error(), entry.addresses());
1793 1803
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1843 1853
1844 BoundNetLog net_log_; 1854 BoundNetLog net_log_;
1845 1855
1846 // Resolves the host using a HostResolverProc. 1856 // Resolves the host using a HostResolverProc.
1847 scoped_refptr<ProcTask> proc_task_; 1857 scoped_refptr<ProcTask> proc_task_;
1848 1858
1849 // Resolves the host using a DnsTransaction. 1859 // Resolves the host using a DnsTransaction.
1850 std::unique_ptr<DnsTask> dns_task_; 1860 std::unique_ptr<DnsTask> dns_task_;
1851 1861
1852 // All Requests waiting for the result of this Job. Some can be canceled. 1862 // All Requests waiting for the result of this Job. Some can be canceled.
1853 std::vector<std::unique_ptr<Request>> requests_; 1863 std::vector<RequestImpl*> requests_;
1854 1864
1855 // A handle used in |HostResolverImpl::dispatcher_|. 1865 // A handle used in |HostResolverImpl::dispatcher_|.
1856 PrioritizedDispatcher::Handle handle_; 1866 PrioritizedDispatcher::Handle handle_;
1857 }; 1867 };
1858 1868
1859 //----------------------------------------------------------------------------- 1869 //-----------------------------------------------------------------------------
1860 1870
1861 HostResolverImpl::ProcTaskParams::ProcTaskParams( 1871 HostResolverImpl::ProcTaskParams::ProcTaskParams(
1862 HostResolverProc* resolver_proc, 1872 HostResolverProc* resolver_proc,
1863 size_t max_retry_attempts) 1873 size_t max_retry_attempts)
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1898 void HostResolverImpl::SetMaxQueuedJobs(size_t value) { 1908 void HostResolverImpl::SetMaxQueuedJobs(size_t value) {
1899 DCHECK_EQ(0u, dispatcher_->num_queued_jobs()); 1909 DCHECK_EQ(0u, dispatcher_->num_queued_jobs());
1900 DCHECK_GT(value, 0u); 1910 DCHECK_GT(value, 0u);
1901 max_queued_jobs_ = value; 1911 max_queued_jobs_ = value;
1902 } 1912 }
1903 1913
1904 int HostResolverImpl::Resolve(const RequestInfo& info, 1914 int HostResolverImpl::Resolve(const RequestInfo& info,
1905 RequestPriority priority, 1915 RequestPriority priority,
1906 AddressList* addresses, 1916 AddressList* addresses,
1907 const CompletionCallback& callback, 1917 const CompletionCallback& callback,
1908 RequestHandle* out_req, 1918 std::unique_ptr<Request>* out_req,
1909 const BoundNetLog& source_net_log) { 1919 const BoundNetLog& source_net_log) {
1910 DCHECK(addresses); 1920 DCHECK(addresses);
1911 DCHECK(CalledOnValidThread()); 1921 DCHECK(CalledOnValidThread());
1912 DCHECK_EQ(false, callback.is_null()); 1922 DCHECK_EQ(false, callback.is_null());
1913 1923
1914 // Check that the caller supplied a valid hostname to resolve. 1924 // Check that the caller supplied a valid hostname to resolve.
1915 std::string labeled_hostname; 1925 std::string labeled_hostname;
1916 if (!DNSDomainFromDot(info.hostname(), &labeled_hostname)) 1926 if (!DNSDomainFromDot(info.hostname(), &labeled_hostname))
1917 return ERR_NAME_NOT_RESOLVED; 1927 return ERR_NAME_NOT_RESOLVED;
1918 1928
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1955 LogFinishRequest(source_net_log, info, rv); 1965 LogFinishRequest(source_net_log, info, rv);
1956 return rv; 1966 return rv;
1957 } 1967 }
1958 } 1968 }
1959 jobs_.insert(jobit, std::make_pair(key, job)); 1969 jobs_.insert(jobit, std::make_pair(key, job));
1960 } else { 1970 } else {
1961 job = jobit->second; 1971 job = jobit->second;
1962 } 1972 }
1963 1973
1964 // Can't complete synchronously. Create and attach request. 1974 // Can't complete synchronously. Create and attach request.
1965 std::unique_ptr<Request> req( 1975 std::unique_ptr<RequestImpl> req(
1966 new Request(source_net_log, info, priority, callback, addresses)); 1976 new RequestImpl(source_net_log, info, priority, callback, addresses));
1967 if (out_req) 1977 job->AddRequest(req.get());
1968 *out_req = reinterpret_cast<RequestHandle>(req.get()); 1978 *out_req = std::move(req);
1969 1979
1970 job->AddRequest(std::move(req));
1971 // Completion happens during Job::CompleteRequests(). 1980 // Completion happens during Job::CompleteRequests().
1972 return ERR_IO_PENDING; 1981 return ERR_IO_PENDING;
1973 } 1982 }
1974 1983
1975 HostResolverImpl::HostResolverImpl( 1984 HostResolverImpl::HostResolverImpl(
1976 const Options& options, 1985 const Options& options,
1977 NetLog* net_log, 1986 NetLog* net_log,
1978 scoped_refptr<base::TaskRunner> worker_task_runner) 1987 scoped_refptr<base::TaskRunner> worker_task_runner)
1979 : max_queued_jobs_(0), 1988 : max_queued_jobs_(0),
1980 proc_params_(NULL, options.max_retry_attempts), 1989 proc_params_(NULL, options.max_retry_attempts),
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
2091 ip_address_ptr = &ip_address; 2100 ip_address_ptr = &ip_address;
2092 2101
2093 Key key = GetEffectiveKeyForRequest(info, ip_address_ptr, source_net_log); 2102 Key key = GetEffectiveKeyForRequest(info, ip_address_ptr, source_net_log);
2094 2103
2095 int rv = ResolveHelper(key, info, ip_address_ptr, addresses, false, nullptr, 2104 int rv = ResolveHelper(key, info, ip_address_ptr, addresses, false, nullptr,
2096 source_net_log); 2105 source_net_log);
2097 LogFinishRequest(source_net_log, info, rv); 2106 LogFinishRequest(source_net_log, info, rv);
2098 return rv; 2107 return rv;
2099 } 2108 }
2100 2109
2101 void HostResolverImpl::ChangeRequestPriority(RequestHandle req_handle,
2102 RequestPriority priority) {
2103 DCHECK(CalledOnValidThread());
2104 Request* req = reinterpret_cast<Request*>(req_handle);
2105 DCHECK(req);
2106 Job* job = req->job();
2107 DCHECK(job);
2108 job->ChangeRequestPriority(req, priority);
2109 }
2110
2111 void HostResolverImpl::CancelRequest(RequestHandle req_handle) {
2112 DCHECK(CalledOnValidThread());
2113 Request* req = reinterpret_cast<Request*>(req_handle);
2114 DCHECK(req);
2115 Job* job = req->job();
2116 DCHECK(job);
2117 job->CancelRequest(req);
2118 }
2119
2120 void HostResolverImpl::SetDnsClientEnabled(bool enabled) { 2110 void HostResolverImpl::SetDnsClientEnabled(bool enabled) {
2121 DCHECK(CalledOnValidThread()); 2111 DCHECK(CalledOnValidThread());
2122 #if defined(ENABLE_BUILT_IN_DNS) 2112 #if defined(ENABLE_BUILT_IN_DNS)
2123 if (enabled && !dns_client_) { 2113 if (enabled && !dns_client_) {
2124 SetDnsClient(DnsClient::CreateClient(net_log_)); 2114 SetDnsClient(DnsClient::CreateClient(net_log_));
2125 } else if (!enabled && dns_client_) { 2115 } else if (!enabled && dns_client_) {
2126 SetDnsClient(std::unique_ptr<DnsClient>()); 2116 SetDnsClient(std::unique_ptr<DnsClient>());
2127 } 2117 }
2128 #endif 2118 #endif
2129 } 2119 }
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after
2551 NetworkChangeNotifier::GetDnsConfig(&dns_config); 2541 NetworkChangeNotifier::GetDnsConfig(&dns_config);
2552 dns_client_->SetConfig(dns_config); 2542 dns_client_->SetConfig(dns_config);
2553 num_dns_failures_ = 0; 2543 num_dns_failures_ = 0;
2554 if (dns_client_->GetConfig()) 2544 if (dns_client_->GetConfig())
2555 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", true); 2545 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", true);
2556 } 2546 }
2557 2547
2558 AbortDnsTasks(); 2548 AbortDnsTasks();
2559 } 2549 }
2560 2550
2551 HostResolverImpl::RequestImpl::~RequestImpl() {
2552 if (job_)
2553 job_->CancelRequest(this);
2554 }
2555
2556 void HostResolverImpl::RequestImpl::ChangeRequestPriority(
2557 RequestPriority priority) {
2558 job_->ChangeRequestPriority(this, priority);
2559 }
2560
2561 void HostResolverImpl::RequestImpl::RemoveJob() {
2562 job_->RemoveRequest(this);
2563 job_ = nullptr;
2564 }
mmenke 2016/07/12 18:50:24 These methods should all be inlined, since all the
maksims (do not use this acc) 2016/07/13 11:40:27 Nope, otherwise ../../net/dns/host_resolver_impl.
2565
2561 } // namespace net 2566 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698