| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 #include "net/dns/address_sorter.h" | 48 #include "net/dns/address_sorter.h" |
| 49 #include "net/dns/dns_client.h" | 49 #include "net/dns/dns_client.h" |
| 50 #include "net/dns/dns_config_service.h" | 50 #include "net/dns/dns_config_service.h" |
| 51 #include "net/dns/dns_protocol.h" | 51 #include "net/dns/dns_protocol.h" |
| 52 #include "net/dns/dns_reloader.h" | 52 #include "net/dns/dns_reloader.h" |
| 53 #include "net/dns/dns_response.h" | 53 #include "net/dns/dns_response.h" |
| 54 #include "net/dns/dns_transaction.h" | 54 #include "net/dns/dns_transaction.h" |
| 55 #include "net/dns/dns_util.h" | 55 #include "net/dns/dns_util.h" |
| 56 #include "net/dns/host_resolver_proc.h" | 56 #include "net/dns/host_resolver_proc.h" |
| 57 #include "net/log/net_log.h" | 57 #include "net/log/net_log.h" |
| 58 #include "net/log/net_log_event_type.h" |
| 59 #include "net/log/net_log_source_type.h" |
| 58 #include "net/socket/client_socket_factory.h" | 60 #include "net/socket/client_socket_factory.h" |
| 59 #include "net/udp/datagram_client_socket.h" | 61 #include "net/udp/datagram_client_socket.h" |
| 60 #include "url/url_canon_ip.h" | 62 #include "url/url_canon_ip.h" |
| 61 | 63 |
| 62 #if defined(OS_WIN) | 64 #if defined(OS_WIN) |
| 63 #include "net/base/winsock_init.h" | 65 #include "net/base/winsock_init.h" |
| 64 #endif | 66 #endif |
| 65 | 67 |
| 66 namespace net { | 68 namespace net { |
| 67 | 69 |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 dict->SetBoolean("cached", cached); | 421 dict->SetBoolean("cached", cached); |
| 420 return std::move(dict); | 422 return std::move(dict); |
| 421 } | 423 } |
| 422 | 424 |
| 423 // The logging routines are defined here because some requests are resolved | 425 // The logging routines are defined here because some requests are resolved |
| 424 // without a Request object. | 426 // without a Request object. |
| 425 | 427 |
| 426 // Logs when a request has just been started. | 428 // Logs when a request has just been started. |
| 427 void LogStartRequest(const BoundNetLog& source_net_log, | 429 void LogStartRequest(const BoundNetLog& source_net_log, |
| 428 const HostResolver::RequestInfo& info) { | 430 const HostResolver::RequestInfo& info) { |
| 429 source_net_log.BeginEvent( | 431 source_net_log.BeginEvent(NetLogEventType::HOST_RESOLVER_IMPL_REQUEST, |
| 430 NetLog::TYPE_HOST_RESOLVER_IMPL_REQUEST, | 432 base::Bind(&NetLogRequestInfoCallback, &info)); |
| 431 base::Bind(&NetLogRequestInfoCallback, &info)); | |
| 432 } | 433 } |
| 433 | 434 |
| 434 // Logs when a request has just completed (before its callback is run). | 435 // Logs when a request has just completed (before its callback is run). |
| 435 void LogFinishRequest(const BoundNetLog& source_net_log, | 436 void LogFinishRequest(const BoundNetLog& source_net_log, |
| 436 const HostResolver::RequestInfo& info, | 437 const HostResolver::RequestInfo& info, |
| 437 int net_error) { | 438 int net_error) { |
| 438 source_net_log.EndEventWithNetErrorCode( | 439 source_net_log.EndEventWithNetErrorCode( |
| 439 NetLog::TYPE_HOST_RESOLVER_IMPL_REQUEST, net_error); | 440 NetLogEventType::HOST_RESOLVER_IMPL_REQUEST, net_error); |
| 440 } | 441 } |
| 441 | 442 |
| 442 // Logs when a request has been cancelled. | 443 // Logs when a request has been cancelled. |
| 443 void LogCancelRequest(const BoundNetLog& source_net_log, | 444 void LogCancelRequest(const BoundNetLog& source_net_log, |
| 444 const HostResolverImpl::RequestInfo& info) { | 445 const HostResolverImpl::RequestInfo& info) { |
| 445 source_net_log.AddEvent(NetLog::TYPE_CANCELLED); | 446 source_net_log.AddEvent(NetLogEventType::CANCELLED); |
| 446 source_net_log.EndEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_REQUEST); | 447 source_net_log.EndEvent(NetLogEventType::HOST_RESOLVER_IMPL_REQUEST); |
| 447 } | 448 } |
| 448 | 449 |
| 449 //----------------------------------------------------------------------------- | 450 //----------------------------------------------------------------------------- |
| 450 | 451 |
| 451 // Keeps track of the highest priority. | 452 // Keeps track of the highest priority. |
| 452 class PriorityTracker { | 453 class PriorityTracker { |
| 453 public: | 454 public: |
| 454 explicit PriorityTracker(RequestPriority initial_priority) | 455 explicit PriorityTracker(RequestPriority initial_priority) |
| 455 : highest_priority_(initial_priority), total_count_(0) { | 456 : highest_priority_(initial_priority), total_count_(0) { |
| 456 memset(counts_, 0, sizeof(counts_)); | 457 memset(counts_, 0, sizeof(counts_)); |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 642 net_log_(job_net_log) { | 643 net_log_(job_net_log) { |
| 643 if (!params_.resolver_proc.get()) | 644 if (!params_.resolver_proc.get()) |
| 644 params_.resolver_proc = HostResolverProc::GetDefault(); | 645 params_.resolver_proc = HostResolverProc::GetDefault(); |
| 645 // If default is unset, use the system proc. | 646 // If default is unset, use the system proc. |
| 646 if (!params_.resolver_proc.get()) | 647 if (!params_.resolver_proc.get()) |
| 647 params_.resolver_proc = new SystemHostResolverProc(); | 648 params_.resolver_proc = new SystemHostResolverProc(); |
| 648 } | 649 } |
| 649 | 650 |
| 650 void Start() { | 651 void Start() { |
| 651 DCHECK(network_task_runner_->BelongsToCurrentThread()); | 652 DCHECK(network_task_runner_->BelongsToCurrentThread()); |
| 652 net_log_.BeginEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_PROC_TASK); | 653 net_log_.BeginEvent(NetLogEventType::HOST_RESOLVER_IMPL_PROC_TASK); |
| 653 StartLookupAttempt(); | 654 StartLookupAttempt(); |
| 654 } | 655 } |
| 655 | 656 |
| 656 // Cancels this ProcTask. It will be orphaned. Any outstanding resolve | 657 // Cancels this ProcTask. It will be orphaned. Any outstanding resolve |
| 657 // attempts running on worker thread will continue running. Only once all the | 658 // attempts running on worker thread will continue running. Only once all the |
| 658 // attempts complete will the final reference to this ProcTask be released. | 659 // attempts complete will the final reference to this ProcTask be released. |
| 659 void Cancel() { | 660 void Cancel() { |
| 660 DCHECK(network_task_runner_->BelongsToCurrentThread()); | 661 DCHECK(network_task_runner_->BelongsToCurrentThread()); |
| 661 | 662 |
| 662 if (was_canceled() || was_completed()) | 663 if (was_canceled() || was_completed()) |
| 663 return; | 664 return; |
| 664 | 665 |
| 665 callback_.Reset(); | 666 callback_.Reset(); |
| 666 net_log_.EndEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_PROC_TASK); | 667 net_log_.EndEvent(NetLogEventType::HOST_RESOLVER_IMPL_PROC_TASK); |
| 667 } | 668 } |
| 668 | 669 |
| 669 void set_had_non_speculative_request() { | 670 void set_had_non_speculative_request() { |
| 670 DCHECK(network_task_runner_->BelongsToCurrentThread()); | 671 DCHECK(network_task_runner_->BelongsToCurrentThread()); |
| 671 had_non_speculative_request_ = true; | 672 had_non_speculative_request_ = true; |
| 672 } | 673 } |
| 673 | 674 |
| 674 bool was_canceled() const { | 675 bool was_canceled() const { |
| 675 DCHECK(network_task_runner_->BelongsToCurrentThread()); | 676 DCHECK(network_task_runner_->BelongsToCurrentThread()); |
| 676 return callback_.is_null(); | 677 return callback_.is_null(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 698 // Since this method may have been called from Resolve(), can't just call | 699 // Since this method may have been called from Resolve(), can't just call |
| 699 // OnLookupComplete(). Instead, must wait until Resolve() has returned | 700 // OnLookupComplete(). Instead, must wait until Resolve() has returned |
| 700 // (IO_PENDING). | 701 // (IO_PENDING). |
| 701 network_task_runner_->PostTask( | 702 network_task_runner_->PostTask( |
| 702 FROM_HERE, | 703 FROM_HERE, |
| 703 base::Bind(&ProcTask::OnLookupComplete, this, AddressList(), | 704 base::Bind(&ProcTask::OnLookupComplete, this, AddressList(), |
| 704 start_time, attempt_number_, ERR_UNEXPECTED, 0)); | 705 start_time, attempt_number_, ERR_UNEXPECTED, 0)); |
| 705 return; | 706 return; |
| 706 } | 707 } |
| 707 | 708 |
| 708 net_log_.AddEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_ATTEMPT_STARTED, | 709 net_log_.AddEvent(NetLogEventType::HOST_RESOLVER_IMPL_ATTEMPT_STARTED, |
| 709 NetLog::IntCallback("attempt_number", attempt_number_)); | 710 NetLog::IntCallback("attempt_number", attempt_number_)); |
| 710 | 711 |
| 711 // If the results aren't received within a given time, RetryIfNotComplete | 712 // If the results aren't received within a given time, RetryIfNotComplete |
| 712 // will start a new attempt if none of the outstanding attempts have | 713 // will start a new attempt if none of the outstanding attempts have |
| 713 // completed yet. | 714 // completed yet. |
| 714 if (attempt_number_ <= params_.max_retry_attempts) { | 715 if (attempt_number_ <= params_.max_retry_attempts) { |
| 715 network_task_runner_->PostDelayedTask( | 716 network_task_runner_->PostDelayedTask( |
| 716 FROM_HERE, base::Bind(&ProcTask::RetryIfNotComplete, this), | 717 FROM_HERE, base::Bind(&ProcTask::RetryIfNotComplete, this), |
| 717 params_.unresponsive_delay); | 718 params_.unresponsive_delay); |
| 718 } | 719 } |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 794 | 795 |
| 795 NetLog::ParametersCallback net_log_callback; | 796 NetLog::ParametersCallback net_log_callback; |
| 796 if (error != OK) { | 797 if (error != OK) { |
| 797 net_log_callback = base::Bind(&NetLogProcTaskFailedCallback, | 798 net_log_callback = base::Bind(&NetLogProcTaskFailedCallback, |
| 798 attempt_number, | 799 attempt_number, |
| 799 error, | 800 error, |
| 800 os_error); | 801 os_error); |
| 801 } else { | 802 } else { |
| 802 net_log_callback = NetLog::IntCallback("attempt_number", attempt_number); | 803 net_log_callback = NetLog::IntCallback("attempt_number", attempt_number); |
| 803 } | 804 } |
| 804 net_log_.AddEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_ATTEMPT_FINISHED, | 805 net_log_.AddEvent(NetLogEventType::HOST_RESOLVER_IMPL_ATTEMPT_FINISHED, |
| 805 net_log_callback); | 806 net_log_callback); |
| 806 | 807 |
| 807 if (was_completed()) | 808 if (was_completed()) |
| 808 return; | 809 return; |
| 809 | 810 |
| 810 // Copy the results from the first worker thread that resolves the host. | 811 // Copy the results from the first worker thread that resolves the host. |
| 811 results_ = results; | 812 results_ = results; |
| 812 completed_attempt_number_ = attempt_number; | 813 completed_attempt_number_ = attempt_number; |
| 813 completed_attempt_error_ = error; | 814 completed_attempt_error_ = error; |
| 814 | 815 |
| 815 if (was_retry_attempt) { | 816 if (was_retry_attempt) { |
| 816 // If retry attempt finishes before 1st attempt, then get stats on how | 817 // If retry attempt finishes before 1st attempt, then get stats on how |
| 817 // much time is saved by having spawned an extra attempt. | 818 // much time is saved by having spawned an extra attempt. |
| 818 retry_attempt_finished_time_ = base::TimeTicks::Now(); | 819 retry_attempt_finished_time_ = base::TimeTicks::Now(); |
| 819 } | 820 } |
| 820 | 821 |
| 821 if (error != OK) { | 822 if (error != OK) { |
| 822 net_log_callback = base::Bind(&NetLogProcTaskFailedCallback, | 823 net_log_callback = base::Bind(&NetLogProcTaskFailedCallback, |
| 823 0, error, os_error); | 824 0, error, os_error); |
| 824 } else { | 825 } else { |
| 825 net_log_callback = results_.CreateNetLogCallback(); | 826 net_log_callback = results_.CreateNetLogCallback(); |
| 826 } | 827 } |
| 827 net_log_.EndEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_PROC_TASK, | 828 net_log_.EndEvent(NetLogEventType::HOST_RESOLVER_IMPL_PROC_TASK, |
| 828 net_log_callback); | 829 net_log_callback); |
| 829 | 830 |
| 830 callback_.Run(error, results_); | 831 callback_.Run(error, results_); |
| 831 } | 832 } |
| 832 | 833 |
| 833 void RecordPerformanceHistograms(const base::TimeTicks& start_time, | 834 void RecordPerformanceHistograms(const base::TimeTicks& start_time, |
| 834 const int error, | 835 const int error, |
| 835 const int os_error) const { | 836 const int os_error) const { |
| 836 DCHECK(network_task_runner_->BelongsToCurrentThread()); | 837 DCHECK(network_task_runner_->BelongsToCurrentThread()); |
| 837 enum Category { // Used in UMA_HISTOGRAM_ENUMERATION. | 838 enum Category { // Used in UMA_HISTOGRAM_ENUMERATION. |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1080 bool needs_two_transactions() const { | 1081 bool needs_two_transactions() const { |
| 1081 return key_.address_family == ADDRESS_FAMILY_UNSPECIFIED; | 1082 return key_.address_family == ADDRESS_FAMILY_UNSPECIFIED; |
| 1082 } | 1083 } |
| 1083 | 1084 |
| 1084 bool needs_another_transaction() const { | 1085 bool needs_another_transaction() const { |
| 1085 return needs_two_transactions() && !transaction_aaaa_; | 1086 return needs_two_transactions() && !transaction_aaaa_; |
| 1086 } | 1087 } |
| 1087 | 1088 |
| 1088 void StartFirstTransaction() { | 1089 void StartFirstTransaction() { |
| 1089 DCHECK_EQ(0u, num_completed_transactions_); | 1090 DCHECK_EQ(0u, num_completed_transactions_); |
| 1090 net_log_.BeginEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_DNS_TASK); | 1091 net_log_.BeginEvent(NetLogEventType::HOST_RESOLVER_IMPL_DNS_TASK); |
| 1091 if (key_.address_family == ADDRESS_FAMILY_IPV6) { | 1092 if (key_.address_family == ADDRESS_FAMILY_IPV6) { |
| 1092 StartAAAA(); | 1093 StartAAAA(); |
| 1093 } else { | 1094 } else { |
| 1094 StartA(); | 1095 StartA(); |
| 1095 } | 1096 } |
| 1096 } | 1097 } |
| 1097 | 1098 |
| 1098 void StartSecondTransaction() { | 1099 void StartSecondTransaction() { |
| 1099 DCHECK(needs_two_transactions()); | 1100 DCHECK(needs_two_transactions()); |
| 1100 StartAAAA(); | 1101 StartAAAA(); |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1225 OnFailure(ERR_NAME_NOT_RESOLVED, DnsResponse::DNS_PARSE_OK); | 1226 OnFailure(ERR_NAME_NOT_RESOLVED, DnsResponse::DNS_PARSE_OK); |
| 1226 return; | 1227 return; |
| 1227 } | 1228 } |
| 1228 | 1229 |
| 1229 OnSuccess(addr_list); | 1230 OnSuccess(addr_list); |
| 1230 } | 1231 } |
| 1231 | 1232 |
| 1232 void OnFailure(int net_error, DnsResponse::Result result) { | 1233 void OnFailure(int net_error, DnsResponse::Result result) { |
| 1233 DCHECK_NE(OK, net_error); | 1234 DCHECK_NE(OK, net_error); |
| 1234 net_log_.EndEvent( | 1235 net_log_.EndEvent( |
| 1235 NetLog::TYPE_HOST_RESOLVER_IMPL_DNS_TASK, | 1236 NetLogEventType::HOST_RESOLVER_IMPL_DNS_TASK, |
| 1236 base::Bind(&NetLogDnsTaskFailedCallback, net_error, result)); | 1237 base::Bind(&NetLogDnsTaskFailedCallback, net_error, result)); |
| 1237 delegate_->OnDnsTaskComplete(task_start_time_, net_error, AddressList(), | 1238 delegate_->OnDnsTaskComplete(task_start_time_, net_error, AddressList(), |
| 1238 base::TimeDelta()); | 1239 base::TimeDelta()); |
| 1239 } | 1240 } |
| 1240 | 1241 |
| 1241 void OnSuccess(const AddressList& addr_list) { | 1242 void OnSuccess(const AddressList& addr_list) { |
| 1242 net_log_.EndEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_DNS_TASK, | 1243 net_log_.EndEvent(NetLogEventType::HOST_RESOLVER_IMPL_DNS_TASK, |
| 1243 addr_list.CreateNetLogCallback()); | 1244 addr_list.CreateNetLogCallback()); |
| 1244 delegate_->OnDnsTaskComplete(task_start_time_, OK, addr_list, ttl_); | 1245 delegate_->OnDnsTaskComplete(task_start_time_, OK, addr_list, ttl_); |
| 1245 } | 1246 } |
| 1246 | 1247 |
| 1247 DnsClient* client_; | 1248 DnsClient* client_; |
| 1248 Key key_; | 1249 Key key_; |
| 1249 | 1250 |
| 1250 // The listener to the results of this DnsTask. | 1251 // The listener to the results of this DnsTask. |
| 1251 Delegate* delegate_; | 1252 Delegate* delegate_; |
| 1252 const BoundNetLog net_log_; | 1253 const BoundNetLog net_log_; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1283 key_(key), | 1284 key_(key), |
| 1284 priority_tracker_(priority), | 1285 priority_tracker_(priority), |
| 1285 worker_task_runner_(std::move(worker_task_runner)), | 1286 worker_task_runner_(std::move(worker_task_runner)), |
| 1286 had_non_speculative_request_(false), | 1287 had_non_speculative_request_(false), |
| 1287 had_dns_config_(false), | 1288 had_dns_config_(false), |
| 1288 num_occupied_job_slots_(0), | 1289 num_occupied_job_slots_(0), |
| 1289 dns_task_error_(OK), | 1290 dns_task_error_(OK), |
| 1290 creation_time_(base::TimeTicks::Now()), | 1291 creation_time_(base::TimeTicks::Now()), |
| 1291 priority_change_time_(creation_time_), | 1292 priority_change_time_(creation_time_), |
| 1292 net_log_(BoundNetLog::Make(source_net_log.net_log(), | 1293 net_log_(BoundNetLog::Make(source_net_log.net_log(), |
| 1293 NetLog::SOURCE_HOST_RESOLVER_IMPL_JOB)) { | 1294 NetLogSourceType::HOST_RESOLVER_IMPL_JOB)) { |
| 1294 source_net_log.AddEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_CREATE_JOB); | 1295 source_net_log.AddEvent(NetLogEventType::HOST_RESOLVER_IMPL_CREATE_JOB); |
| 1295 | 1296 |
| 1296 net_log_.BeginEvent( | 1297 net_log_.BeginEvent(NetLogEventType::HOST_RESOLVER_IMPL_JOB, |
| 1297 NetLog::TYPE_HOST_RESOLVER_IMPL_JOB, | 1298 base::Bind(&NetLogJobCreationCallback, |
| 1298 base::Bind(&NetLogJobCreationCallback, | 1299 source_net_log.source(), &key_.hostname)); |
| 1299 source_net_log.source(), | |
| 1300 &key_.hostname)); | |
| 1301 } | 1300 } |
| 1302 | 1301 |
| 1303 ~Job() override { | 1302 ~Job() override { |
| 1304 if (is_running()) { | 1303 if (is_running()) { |
| 1305 // |resolver_| was destroyed with this Job still in flight. | 1304 // |resolver_| was destroyed with this Job still in flight. |
| 1306 // Clean-up, record in the log, but don't run any callbacks. | 1305 // Clean-up, record in the log, but don't run any callbacks. |
| 1307 if (is_proc_running()) { | 1306 if (is_proc_running()) { |
| 1308 proc_task_->Cancel(); | 1307 proc_task_->Cancel(); |
| 1309 proc_task_ = nullptr; | 1308 proc_task_ = nullptr; |
| 1310 } | 1309 } |
| 1311 // Clean up now for nice NetLog. | 1310 // Clean up now for nice NetLog. |
| 1312 KillDnsTask(); | 1311 KillDnsTask(); |
| 1313 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HOST_RESOLVER_IMPL_JOB, | 1312 net_log_.EndEventWithNetErrorCode(NetLogEventType::HOST_RESOLVER_IMPL_JOB, |
| 1314 ERR_ABORTED); | 1313 ERR_ABORTED); |
| 1315 } else if (is_queued()) { | 1314 } else if (is_queued()) { |
| 1316 // |resolver_| was destroyed without running this Job. | 1315 // |resolver_| was destroyed without running this Job. |
| 1317 // TODO(szym): is there any benefit in having this distinction? | 1316 // TODO(szym): is there any benefit in having this distinction? |
| 1318 net_log_.AddEvent(NetLog::TYPE_CANCELLED); | 1317 net_log_.AddEvent(NetLogEventType::CANCELLED); |
| 1319 net_log_.EndEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_JOB); | 1318 net_log_.EndEvent(NetLogEventType::HOST_RESOLVER_IMPL_JOB); |
| 1320 } | 1319 } |
| 1321 // else CompleteRequests logged EndEvent. | 1320 // else CompleteRequests logged EndEvent. |
| 1322 if (!requests_.empty()) { | 1321 if (!requests_.empty()) { |
| 1323 // Log any remaining Requests as cancelled. | 1322 // Log any remaining Requests as cancelled. |
| 1324 for (RequestImpl* req : requests_) { | 1323 for (RequestImpl* req : requests_) { |
| 1325 DCHECK_EQ(this, req->job()); | 1324 DCHECK_EQ(this, req->job()); |
| 1326 LogCancelRequest(req->source_net_log(), req->info()); | 1325 LogCancelRequest(req->source_net_log(), req->info()); |
| 1327 req->OnJobCancelled(this); | 1326 req->OnJobCancelled(this); |
| 1328 } | 1327 } |
| 1329 requests_.clear(); | 1328 requests_.clear(); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1348 handle_ = handle; | 1347 handle_ = handle; |
| 1349 } | 1348 } |
| 1350 } | 1349 } |
| 1351 | 1350 |
| 1352 void AddRequest(RequestImpl* request) { | 1351 void AddRequest(RequestImpl* request) { |
| 1353 DCHECK_EQ(key_.hostname, request->info().hostname()); | 1352 DCHECK_EQ(key_.hostname, request->info().hostname()); |
| 1354 | 1353 |
| 1355 priority_tracker_.Add(request->priority()); | 1354 priority_tracker_.Add(request->priority()); |
| 1356 | 1355 |
| 1357 request->source_net_log().AddEvent( | 1356 request->source_net_log().AddEvent( |
| 1358 NetLog::TYPE_HOST_RESOLVER_IMPL_JOB_ATTACH, | 1357 NetLogEventType::HOST_RESOLVER_IMPL_JOB_ATTACH, |
| 1359 net_log_.source().ToEventParametersCallback()); | 1358 net_log_.source().ToEventParametersCallback()); |
| 1360 | 1359 |
| 1361 net_log_.AddEvent( | 1360 net_log_.AddEvent( |
| 1362 NetLog::TYPE_HOST_RESOLVER_IMPL_JOB_REQUEST_ATTACH, | 1361 NetLogEventType::HOST_RESOLVER_IMPL_JOB_REQUEST_ATTACH, |
| 1363 base::Bind(&NetLogJobAttachCallback, request->source_net_log().source(), | 1362 base::Bind(&NetLogJobAttachCallback, request->source_net_log().source(), |
| 1364 priority())); | 1363 priority())); |
| 1365 | 1364 |
| 1366 // TODO(szym): Check if this is still needed. | 1365 // TODO(szym): Check if this is still needed. |
| 1367 if (!request->info().is_speculative()) { | 1366 if (!request->info().is_speculative()) { |
| 1368 had_non_speculative_request_ = true; | 1367 had_non_speculative_request_ = true; |
| 1369 if (proc_task_.get()) | 1368 if (proc_task_.get()) |
| 1370 proc_task_->set_had_non_speculative_request(); | 1369 proc_task_->set_had_non_speculative_request(); |
| 1371 } | 1370 } |
| 1372 | 1371 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1387 // Detach cancelled request. If it was the last active Request, also finishes | 1386 // Detach cancelled request. If it was the last active Request, also finishes |
| 1388 // this Job. | 1387 // this Job. |
| 1389 void CancelRequest(RequestImpl* request) { | 1388 void CancelRequest(RequestImpl* request) { |
| 1390 DCHECK_EQ(key_.hostname, request->info().hostname()); | 1389 DCHECK_EQ(key_.hostname, request->info().hostname()); |
| 1391 DCHECK(!requests_.empty()); | 1390 DCHECK(!requests_.empty()); |
| 1392 | 1391 |
| 1393 LogCancelRequest(request->source_net_log(), request->info()); | 1392 LogCancelRequest(request->source_net_log(), request->info()); |
| 1394 | 1393 |
| 1395 priority_tracker_.Remove(request->priority()); | 1394 priority_tracker_.Remove(request->priority()); |
| 1396 net_log_.AddEvent( | 1395 net_log_.AddEvent( |
| 1397 NetLog::TYPE_HOST_RESOLVER_IMPL_JOB_REQUEST_DETACH, | 1396 NetLogEventType::HOST_RESOLVER_IMPL_JOB_REQUEST_DETACH, |
| 1398 base::Bind(&NetLogJobAttachCallback, request->source_net_log().source(), | 1397 base::Bind(&NetLogJobAttachCallback, request->source_net_log().source(), |
| 1399 priority())); | 1398 priority())); |
| 1400 | 1399 |
| 1401 if (num_active_requests() > 0) { | 1400 if (num_active_requests() > 0) { |
| 1402 UpdatePriority(); | 1401 UpdatePriority(); |
| 1403 RemoveRequest(request); | 1402 RemoveRequest(request); |
| 1404 } else { | 1403 } else { |
| 1405 // If we were called from a Request's callback within CompleteRequests, | 1404 // If we were called from a Request's callback within CompleteRequests, |
| 1406 // that Request could not have been cancelled, so num_active_requests() | 1405 // that Request could not have been cancelled, so num_active_requests() |
| 1407 // could not be 0. Therefore, we are not in CompleteRequests(). | 1406 // could not be 0. Therefore, we are not in CompleteRequests(). |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1432 } | 1431 } |
| 1433 } | 1432 } |
| 1434 | 1433 |
| 1435 // Called by HostResolverImpl when this job is evicted due to queue overflow. | 1434 // Called by HostResolverImpl when this job is evicted due to queue overflow. |
| 1436 // Completes all requests and destroys the job. | 1435 // Completes all requests and destroys the job. |
| 1437 void OnEvicted() { | 1436 void OnEvicted() { |
| 1438 DCHECK(!is_running()); | 1437 DCHECK(!is_running()); |
| 1439 DCHECK(is_queued()); | 1438 DCHECK(is_queued()); |
| 1440 handle_.Reset(); | 1439 handle_.Reset(); |
| 1441 | 1440 |
| 1442 net_log_.AddEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_JOB_EVICTED); | 1441 net_log_.AddEvent(NetLogEventType::HOST_RESOLVER_IMPL_JOB_EVICTED); |
| 1443 | 1442 |
| 1444 // This signals to CompleteRequests that this job never ran. | 1443 // This signals to CompleteRequests that this job never ran. |
| 1445 CompleteRequestsWithError(ERR_HOST_RESOLVER_QUEUE_TOO_LARGE); | 1444 CompleteRequestsWithError(ERR_HOST_RESOLVER_QUEUE_TOO_LARGE); |
| 1446 } | 1445 } |
| 1447 | 1446 |
| 1448 // Attempts to serve the job from HOSTS. Returns true if succeeded and | 1447 // Attempts to serve the job from HOSTS. Returns true if succeeded and |
| 1449 // this Job was destroyed. | 1448 // this Job was destroyed. |
| 1450 bool ServeFromHosts() { | 1449 bool ServeFromHosts() { |
| 1451 DCHECK_GT(num_active_requests(), 0u); | 1450 DCHECK_GT(num_active_requests(), 0u); |
| 1452 AddressList addr_list; | 1451 AddressList addr_list; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1517 handle_.Reset(); | 1516 handle_.Reset(); |
| 1518 ++num_occupied_job_slots_; | 1517 ++num_occupied_job_slots_; |
| 1519 | 1518 |
| 1520 if (num_occupied_job_slots_ == 2) { | 1519 if (num_occupied_job_slots_ == 2) { |
| 1521 StartSecondDnsTransaction(); | 1520 StartSecondDnsTransaction(); |
| 1522 return; | 1521 return; |
| 1523 } | 1522 } |
| 1524 | 1523 |
| 1525 DCHECK(!is_running()); | 1524 DCHECK(!is_running()); |
| 1526 | 1525 |
| 1527 net_log_.AddEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_JOB_STARTED); | 1526 net_log_.AddEvent(NetLogEventType::HOST_RESOLVER_IMPL_JOB_STARTED); |
| 1528 | 1527 |
| 1529 had_dns_config_ = resolver_->HaveDnsConfig(); | 1528 had_dns_config_ = resolver_->HaveDnsConfig(); |
| 1530 | 1529 |
| 1531 base::TimeTicks now = base::TimeTicks::Now(); | 1530 base::TimeTicks now = base::TimeTicks::Now(); |
| 1532 base::TimeDelta queue_time = now - creation_time_; | 1531 base::TimeDelta queue_time = now - creation_time_; |
| 1533 base::TimeDelta queue_time_after_change = now - priority_change_time_; | 1532 base::TimeDelta queue_time_after_change = now - priority_change_time_; |
| 1534 | 1533 |
| 1535 if (had_dns_config_) { | 1534 if (had_dns_config_) { |
| 1536 DNS_HISTOGRAM_BY_PRIORITY("AsyncDNS.JobQueueTime", priority(), | 1535 DNS_HISTOGRAM_BY_PRIORITY("AsyncDNS.JobQueueTime", priority(), |
| 1537 queue_time); | 1536 queue_time); |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1745 KillDnsTask(); | 1744 KillDnsTask(); |
| 1746 | 1745 |
| 1747 // Signal dispatcher that a slot has opened. | 1746 // Signal dispatcher that a slot has opened. |
| 1748 resolver_->dispatcher_->OnJobFinished(); | 1747 resolver_->dispatcher_->OnJobFinished(); |
| 1749 } else if (is_queued()) { | 1748 } else if (is_queued()) { |
| 1750 resolver_->dispatcher_->Cancel(handle_); | 1749 resolver_->dispatcher_->Cancel(handle_); |
| 1751 handle_.Reset(); | 1750 handle_.Reset(); |
| 1752 } | 1751 } |
| 1753 | 1752 |
| 1754 if (num_active_requests() == 0) { | 1753 if (num_active_requests() == 0) { |
| 1755 net_log_.AddEvent(NetLog::TYPE_CANCELLED); | 1754 net_log_.AddEvent(NetLogEventType::CANCELLED); |
| 1756 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HOST_RESOLVER_IMPL_JOB, | 1755 net_log_.EndEventWithNetErrorCode(NetLogEventType::HOST_RESOLVER_IMPL_JOB, |
| 1757 OK); | 1756 OK); |
| 1758 return; | 1757 return; |
| 1759 } | 1758 } |
| 1760 | 1759 |
| 1761 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HOST_RESOLVER_IMPL_JOB, | 1760 net_log_.EndEventWithNetErrorCode(NetLogEventType::HOST_RESOLVER_IMPL_JOB, |
| 1762 entry.error()); | 1761 entry.error()); |
| 1763 | 1762 |
| 1764 resolver_->SchedulePersist(); | 1763 resolver_->SchedulePersist(); |
| 1765 | 1764 |
| 1766 DCHECK(!requests_.empty()); | 1765 DCHECK(!requests_.empty()); |
| 1767 | 1766 |
| 1768 if (entry.error() == OK) { | 1767 if (entry.error() == OK) { |
| 1769 // Record this histogram here, when we know the system has a valid DNS | 1768 // Record this histogram here, when we know the system has a valid DNS |
| 1770 // configuration. | 1769 // configuration. |
| 1771 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.HaveDnsConfig", | 1770 UMA_HISTOGRAM_BOOLEAN("AsyncDNS.HaveDnsConfig", |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2057 return ERR_NAME_NOT_RESOLVED; | 2056 return ERR_NAME_NOT_RESOLVED; |
| 2058 } | 2057 } |
| 2059 | 2058 |
| 2060 int net_error = ERR_UNEXPECTED; | 2059 int net_error = ERR_UNEXPECTED; |
| 2061 if (ResolveAsIP(key, info, ip_address, &net_error, addresses)) { | 2060 if (ResolveAsIP(key, info, ip_address, &net_error, addresses)) { |
| 2062 MakeNotStale(stale_info); | 2061 MakeNotStale(stale_info); |
| 2063 return net_error; | 2062 return net_error; |
| 2064 } | 2063 } |
| 2065 if (ServeFromCache(key, info, &net_error, addresses, allow_stale, | 2064 if (ServeFromCache(key, info, &net_error, addresses, allow_stale, |
| 2066 stale_info)) { | 2065 stale_info)) { |
| 2067 source_net_log.AddEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_CACHE_HIT); | 2066 source_net_log.AddEvent(NetLogEventType::HOST_RESOLVER_IMPL_CACHE_HIT); |
| 2068 // |ServeFromCache()| will set |*stale_info| as needed. | 2067 // |ServeFromCache()| will set |*stale_info| as needed. |
| 2069 RunCacheHitCallbacks(key, info); | 2068 RunCacheHitCallbacks(key, info); |
| 2070 return net_error; | 2069 return net_error; |
| 2071 } | 2070 } |
| 2072 // TODO(szym): Do not do this if nsswitch.conf instructs not to. | 2071 // TODO(szym): Do not do this if nsswitch.conf instructs not to. |
| 2073 // http://crbug.com/117655 | 2072 // http://crbug.com/117655 |
| 2074 if (ServeFromHosts(key, info, addresses)) { | 2073 if (ServeFromHosts(key, info, addresses)) { |
| 2075 source_net_log.AddEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_HOSTS_HIT); | 2074 source_net_log.AddEvent(NetLogEventType::HOST_RESOLVER_IMPL_HOSTS_HIT); |
| 2076 MakeNotStale(stale_info); | 2075 MakeNotStale(stale_info); |
| 2077 return OK; | 2076 return OK; |
| 2078 } | 2077 } |
| 2079 | 2078 |
| 2080 if (ServeLocalhost(key, info, addresses)) { | 2079 if (ServeLocalhost(key, info, addresses)) { |
| 2081 MakeNotStale(stale_info); | 2080 MakeNotStale(stale_info); |
| 2082 return OK; | 2081 return OK; |
| 2083 } | 2082 } |
| 2084 | 2083 |
| 2085 return ERR_DNS_CACHE_MISS; | 2084 return ERR_DNS_CACHE_MISS; |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2334 | 2333 |
| 2335 bool HostResolverImpl::IsIPv6Reachable(const BoundNetLog& net_log) { | 2334 bool HostResolverImpl::IsIPv6Reachable(const BoundNetLog& net_log) { |
| 2336 base::TimeTicks now = base::TimeTicks::Now(); | 2335 base::TimeTicks now = base::TimeTicks::Now(); |
| 2337 bool cached = true; | 2336 bool cached = true; |
| 2338 if ((now - last_ipv6_probe_time_).InMilliseconds() > kIPv6ProbePeriodMs) { | 2337 if ((now - last_ipv6_probe_time_).InMilliseconds() > kIPv6ProbePeriodMs) { |
| 2339 last_ipv6_probe_result_ = | 2338 last_ipv6_probe_result_ = |
| 2340 IsGloballyReachable(IPAddress(kIPv6ProbeAddress), net_log); | 2339 IsGloballyReachable(IPAddress(kIPv6ProbeAddress), net_log); |
| 2341 last_ipv6_probe_time_ = now; | 2340 last_ipv6_probe_time_ = now; |
| 2342 cached = false; | 2341 cached = false; |
| 2343 } | 2342 } |
| 2344 net_log.AddEvent(NetLog::TYPE_HOST_RESOLVER_IMPL_IPV6_REACHABILITY_CHECK, | 2343 net_log.AddEvent(NetLogEventType::HOST_RESOLVER_IMPL_IPV6_REACHABILITY_CHECK, |
| 2345 base::Bind(&NetLogIPv6AvailableCallback, | 2344 base::Bind(&NetLogIPv6AvailableCallback, |
| 2346 last_ipv6_probe_result_, cached)); | 2345 last_ipv6_probe_result_, cached)); |
| 2347 return last_ipv6_probe_result_; | 2346 return last_ipv6_probe_result_; |
| 2348 } | 2347 } |
| 2349 | 2348 |
| 2350 void HostResolverImpl::RunLoopbackProbeJob() { | 2349 void HostResolverImpl::RunLoopbackProbeJob() { |
| 2351 new LoopbackProbeJob(weak_ptr_factory_.GetWeakPtr(), | 2350 new LoopbackProbeJob(weak_ptr_factory_.GetWeakPtr(), |
| 2352 worker_task_runner_.get()); | 2351 worker_task_runner_.get()); |
| 2353 } | 2352 } |
| 2354 | 2353 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2450 | 2449 |
| 2451 void HostResolverImpl::OnDNSChanged() { | 2450 void HostResolverImpl::OnDNSChanged() { |
| 2452 UpdateDNSConfig(true); | 2451 UpdateDNSConfig(true); |
| 2453 } | 2452 } |
| 2454 | 2453 |
| 2455 void HostResolverImpl::UpdateDNSConfig(bool config_changed) { | 2454 void HostResolverImpl::UpdateDNSConfig(bool config_changed) { |
| 2456 DnsConfig dns_config; | 2455 DnsConfig dns_config; |
| 2457 NetworkChangeNotifier::GetDnsConfig(&dns_config); | 2456 NetworkChangeNotifier::GetDnsConfig(&dns_config); |
| 2458 | 2457 |
| 2459 if (net_log_) { | 2458 if (net_log_) { |
| 2460 net_log_->AddGlobalEntry( | 2459 net_log_->AddGlobalEntry(NetLogEventType::DNS_CONFIG_CHANGED, |
| 2461 NetLog::TYPE_DNS_CONFIG_CHANGED, | 2460 base::Bind(&NetLogDnsConfigCallback, &dns_config)); |
| 2462 base::Bind(&NetLogDnsConfigCallback, &dns_config)); | |
| 2463 } | 2461 } |
| 2464 | 2462 |
| 2465 // TODO(szym): Remove once http://crbug.com/137914 is resolved. | 2463 // TODO(szym): Remove once http://crbug.com/137914 is resolved. |
| 2466 received_dns_config_ = dns_config.IsValid(); | 2464 received_dns_config_ = dns_config.IsValid(); |
| 2467 // Conservatively assume local IPv6 is needed when DnsConfig is not valid. | 2465 // Conservatively assume local IPv6 is needed when DnsConfig is not valid. |
| 2468 use_local_ipv6_ = !dns_config.IsValid() || dns_config.use_local_ipv6; | 2466 use_local_ipv6_ = !dns_config.IsValid() || dns_config.use_local_ipv6; |
| 2469 | 2467 |
| 2470 num_dns_failures_ = 0; | 2468 num_dns_failures_ = 0; |
| 2471 | 2469 |
| 2472 // We want a new DnsSession in place, before we Abort running Jobs, so that | 2470 // We want a new DnsSession in place, before we Abort running Jobs, so that |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2608 if (job_) | 2606 if (job_) |
| 2609 job_->CancelRequest(this); | 2607 job_->CancelRequest(this); |
| 2610 } | 2608 } |
| 2611 | 2609 |
| 2612 void HostResolverImpl::RequestImpl::ChangeRequestPriority( | 2610 void HostResolverImpl::RequestImpl::ChangeRequestPriority( |
| 2613 RequestPriority priority) { | 2611 RequestPriority priority) { |
| 2614 job_->ChangeRequestPriority(this, priority); | 2612 job_->ChangeRequestPriority(this, priority); |
| 2615 } | 2613 } |
| 2616 | 2614 |
| 2617 } // namespace net | 2615 } // namespace net |
| OLD | NEW |