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