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

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

Issue 1928743003: DNS: Support reprioritization of requests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Make a couple of comment changes Created 4 years, 7 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
« no previous file with comments | « net/dns/host_resolver_impl.h ('k') | net/dns/host_resolver_impl_unittest.cc » ('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 #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 556 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 // NetLog for the source, passed in HostResolver::Resolve. 567 // NetLog for the source, passed in HostResolver::Resolve.
568 const BoundNetLog& source_net_log() { 568 const BoundNetLog& source_net_log() {
569 return source_net_log_; 569 return source_net_log_;
570 } 570 }
571 571
572 const RequestInfo& info() const { 572 const RequestInfo& info() const {
573 return info_; 573 return info_;
574 } 574 }
575 575
576 RequestPriority priority() const { return priority_; } 576 RequestPriority priority() const { return priority_; }
577 void set_priority(RequestPriority priority) { priority_ = priority; }
577 578
578 base::TimeTicks request_time() const { return request_time_; } 579 base::TimeTicks request_time() const { return request_time_; }
579 580
580 private: 581 private:
581 const BoundNetLog source_net_log_; 582 const BoundNetLog source_net_log_;
582 583
583 // The request info that started the request. 584 // The request info that started the request.
584 const RequestInfo info_; 585 const RequestInfo info_;
585 586
586 // TODO(akalin): Support reprioritization. 587 RequestPriority priority_;
587 const RequestPriority priority_;
588 588
589 // The resolve job that this request is dependent on. 589 // The resolve job that this request is dependent on.
590 Job* job_; 590 Job* job_;
591 591
592 // The user's callback to invoke when the request completes. 592 // The user's callback to invoke when the request completes.
593 CompletionCallback callback_; 593 CompletionCallback callback_;
594 594
595 // The address list to save result into. 595 // The address list to save result into.
596 AddressList* addresses_; 596 AddressList* addresses_;
597 597
(...skipping 762 matching lines...) Expand 10 before | Expand all | Expand 10 after
1360 had_non_speculative_request_ = true; 1360 had_non_speculative_request_ = true;
1361 if (proc_task_.get()) 1361 if (proc_task_.get())
1362 proc_task_->set_had_non_speculative_request(); 1362 proc_task_->set_had_non_speculative_request();
1363 } 1363 }
1364 1364
1365 requests_.push_back(std::move(req)); 1365 requests_.push_back(std::move(req));
1366 1366
1367 UpdatePriority(); 1367 UpdatePriority();
1368 } 1368 }
1369 1369
1370 void ChangeRequestPriority(Request* req, RequestPriority priority) {
1371 DCHECK_EQ(key_.hostname, req->info().hostname());
1372 DCHECK(!req->was_canceled());
1373
1374 priority_tracker_.Remove(req->priority());
1375 req->set_priority(priority);
1376 priority_tracker_.Add(req->priority());
1377 UpdatePriority();
1378 }
1379
1370 // Marks |req| as cancelled. If it was the last active Request, also finishes 1380 // Marks |req| as cancelled. If it was the last active Request, also finishes
1371 // this Job, marking it as cancelled, and deletes it. 1381 // this Job, marking it as cancelled, and deletes it.
1372 void CancelRequest(Request* req) { 1382 void CancelRequest(Request* req) {
1373 DCHECK_EQ(key_.hostname, req->info().hostname()); 1383 DCHECK_EQ(key_.hostname, req->info().hostname());
1374 DCHECK(!req->was_canceled()); 1384 DCHECK(!req->was_canceled());
1375 1385
1376 // Don't remove it from |requests_| just mark it canceled. 1386 // Don't remove it from |requests_| just mark it canceled.
1377 req->MarkAsCanceled(); 1387 req->MarkAsCanceled();
1378 LogCancelRequest(req->source_net_log(), req->info()); 1388 LogCancelRequest(req->source_net_log(), req->info());
1379 1389
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
1467 if (is_queued()) { 1477 if (is_queued()) {
1468 resolver_->dispatcher_->Cancel(handle_); 1478 resolver_->dispatcher_->Cancel(handle_);
1469 handle_.Reset(); 1479 handle_.Reset();
1470 } else if (num_occupied_job_slots_ > 1) { 1480 } else if (num_occupied_job_slots_ > 1) {
1471 resolver_->dispatcher_->OnJobFinished(); 1481 resolver_->dispatcher_->OnJobFinished();
1472 --num_occupied_job_slots_; 1482 --num_occupied_job_slots_;
1473 } 1483 }
1474 DCHECK_EQ(1u, num_occupied_job_slots_); 1484 DCHECK_EQ(1u, num_occupied_job_slots_);
1475 } 1485 }
1476 1486
1487 AddressList MakeAddressListForRequest(const AddressList& list) const {
1488 if (requests_.empty())
1489 return list;
1490 return AddressList::CopyWithPort(list, requests_.front()->info().port());
1491 }
1492
1477 void UpdatePriority() { 1493 void UpdatePriority() {
1478 if (is_queued()) { 1494 if (is_queued()) {
1479 if (priority() != static_cast<RequestPriority>(handle_.priority())) 1495 if (priority() != static_cast<RequestPriority>(handle_.priority()))
1480 priority_change_time_ = base::TimeTicks::Now(); 1496 priority_change_time_ = base::TimeTicks::Now();
1481 handle_ = resolver_->dispatcher_->ChangePriority(handle_, priority()); 1497 handle_ = resolver_->dispatcher_->ChangePriority(handle_, priority());
1482 } 1498 }
1483 } 1499 }
1484 1500
1485 AddressList MakeAddressListForRequest(const AddressList& list) const {
1486 if (requests_.empty())
1487 return list;
1488 return AddressList::CopyWithPort(list, requests_.front()->info().port());
1489 }
1490
1491 // PriorityDispatch::Job: 1501 // PriorityDispatch::Job:
1492 void Start() override { 1502 void Start() override {
1493 DCHECK_LE(num_occupied_job_slots_, 1u); 1503 DCHECK_LE(num_occupied_job_slots_, 1u);
1494 1504
1495 handle_.Reset(); 1505 handle_.Reset();
1496 ++num_occupied_job_slots_; 1506 ++num_occupied_job_slots_;
1497 1507
1498 if (num_occupied_job_slots_ == 2) { 1508 if (num_occupied_job_slots_ == 2) {
1499 StartSecondDnsTransaction(); 1509 StartSecondDnsTransaction();
1500 return; 1510 return;
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after
2038 if (ip_address.AssignFromIPLiteral(info.hostname())) 2048 if (ip_address.AssignFromIPLiteral(info.hostname()))
2039 ip_address_ptr = &ip_address; 2049 ip_address_ptr = &ip_address;
2040 2050
2041 Key key = GetEffectiveKeyForRequest(info, ip_address_ptr, source_net_log); 2051 Key key = GetEffectiveKeyForRequest(info, ip_address_ptr, source_net_log);
2042 2052
2043 int rv = ResolveHelper(key, info, ip_address_ptr, addresses, source_net_log); 2053 int rv = ResolveHelper(key, info, ip_address_ptr, addresses, source_net_log);
2044 LogFinishRequest(source_net_log, info, rv); 2054 LogFinishRequest(source_net_log, info, rv);
2045 return rv; 2055 return rv;
2046 } 2056 }
2047 2057
2058 void HostResolverImpl::ChangeRequestPriority(RequestHandle req_handle,
2059 RequestPriority priority) {
2060 DCHECK(CalledOnValidThread());
2061 Request* req = reinterpret_cast<Request*>(req_handle);
2062 DCHECK(req);
2063 Job* job = req->job();
2064 DCHECK(job);
2065 job->ChangeRequestPriority(req, priority);
2066 }
2067
2048 void HostResolverImpl::CancelRequest(RequestHandle req_handle) { 2068 void HostResolverImpl::CancelRequest(RequestHandle req_handle) {
2049 DCHECK(CalledOnValidThread()); 2069 DCHECK(CalledOnValidThread());
2050 Request* req = reinterpret_cast<Request*>(req_handle); 2070 Request* req = reinterpret_cast<Request*>(req_handle);
2051 DCHECK(req); 2071 DCHECK(req);
2052 Job* job = req->job(); 2072 Job* job = req->job();
2053 DCHECK(job); 2073 DCHECK(job);
2054 job->CancelRequest(req); 2074 job->CancelRequest(req);
2055 } 2075 }
2056 2076
2057 void HostResolverImpl::SetDnsClientEnabled(bool enabled) { 2077 void HostResolverImpl::SetDnsClientEnabled(bool enabled) {
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
2462 dns_client_->SetConfig(dns_config); 2482 dns_client_->SetConfig(dns_config);
2463 num_dns_failures_ = 0; 2483 num_dns_failures_ = 0;
2464 if (dns_client_->GetConfig()) 2484 if (dns_client_->GetConfig())
2465 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", true); 2485 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.DnsClientEnabled", true);
2466 } 2486 }
2467 2487
2468 AbortDnsTasks(); 2488 AbortDnsTasks();
2469 } 2489 }
2470 2490
2471 } // namespace net 2491 } // namespace net
OLDNEW
« no previous file with comments | « net/dns/host_resolver_impl.h ('k') | net/dns/host_resolver_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698