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

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

Issue 2351513002: net: rename BoundNetLog to NetLogWithSource (Closed)
Patch Set: one more fix, content bound_net_log_ Created 4 years, 3 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 #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 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 if (hostname.back() == '.') { 197 if (hostname.back() == '.') {
198 return hostname.size() > kSuffixLen && 198 return hostname.size() > kSuffixLen &&
199 !hostname.compare(hostname.size() - kSuffixLen, kSuffixLen, kSuffix); 199 !hostname.compare(hostname.size() - kSuffixLen, kSuffixLen, kSuffix);
200 } 200 }
201 return hostname.size() > kSuffixLenTrimmed && 201 return hostname.size() > kSuffixLenTrimmed &&
202 !hostname.compare(hostname.size() - kSuffixLenTrimmed, kSuffixLenTrimmed, 202 !hostname.compare(hostname.size() - kSuffixLenTrimmed, kSuffixLenTrimmed,
203 kSuffix, kSuffixLenTrimmed); 203 kSuffix, kSuffixLenTrimmed);
204 } 204 }
205 205
206 // Attempts to connect a UDP socket to |dest|:53. 206 // Attempts to connect a UDP socket to |dest|:53.
207 bool IsGloballyReachable(const IPAddress& dest, const BoundNetLog& net_log) { 207 bool IsGloballyReachable(const IPAddress& dest,
208 const NetLogWithSource& net_log) {
208 // TODO(eroman): Remove ScopedTracker below once crbug.com/455942 is fixed. 209 // TODO(eroman): Remove ScopedTracker below once crbug.com/455942 is fixed.
209 tracked_objects::ScopedTracker tracking_profile_1( 210 tracked_objects::ScopedTracker tracking_profile_1(
210 FROM_HERE_WITH_EXPLICIT_FUNCTION("455942 IsGloballyReachable")); 211 FROM_HERE_WITH_EXPLICIT_FUNCTION("455942 IsGloballyReachable"));
211 212
212 std::unique_ptr<DatagramClientSocket> socket( 213 std::unique_ptr<DatagramClientSocket> socket(
213 ClientSocketFactory::GetDefaultFactory()->CreateDatagramClientSocket( 214 ClientSocketFactory::GetDefaultFactory()->CreateDatagramClientSocket(
214 DatagramSocket::DEFAULT_BIND, RandIntCallback(), net_log.net_log(), 215 DatagramSocket::DEFAULT_BIND, RandIntCallback(), net_log.net_log(),
215 net_log.source())); 216 net_log.source()));
216 int rv = socket->Connect(IPEndPoint(dest, 53)); 217 int rv = socket->Connect(IPEndPoint(dest, 53));
217 if (rv != OK) 218 if (rv != OK)
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); 420 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
420 dict->SetBoolean("ipv6_available", ipv6_available); 421 dict->SetBoolean("ipv6_available", ipv6_available);
421 dict->SetBoolean("cached", cached); 422 dict->SetBoolean("cached", cached);
422 return std::move(dict); 423 return std::move(dict);
423 } 424 }
424 425
425 // The logging routines are defined here because some requests are resolved 426 // The logging routines are defined here because some requests are resolved
426 // without a Request object. 427 // without a Request object.
427 428
428 // Logs when a request has just been started. 429 // Logs when a request has just been started.
429 void LogStartRequest(const BoundNetLog& source_net_log, 430 void LogStartRequest(const NetLogWithSource& source_net_log,
430 const HostResolver::RequestInfo& info) { 431 const HostResolver::RequestInfo& info) {
431 source_net_log.BeginEvent(NetLogEventType::HOST_RESOLVER_IMPL_REQUEST, 432 source_net_log.BeginEvent(NetLogEventType::HOST_RESOLVER_IMPL_REQUEST,
432 base::Bind(&NetLogRequestInfoCallback, &info)); 433 base::Bind(&NetLogRequestInfoCallback, &info));
433 } 434 }
434 435
435 // 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).
436 void LogFinishRequest(const BoundNetLog& source_net_log, 437 void LogFinishRequest(const NetLogWithSource& source_net_log,
437 const HostResolver::RequestInfo& info, 438 const HostResolver::RequestInfo& info,
438 int net_error) { 439 int net_error) {
439 source_net_log.EndEventWithNetErrorCode( 440 source_net_log.EndEventWithNetErrorCode(
440 NetLogEventType::HOST_RESOLVER_IMPL_REQUEST, net_error); 441 NetLogEventType::HOST_RESOLVER_IMPL_REQUEST, net_error);
441 } 442 }
442 443
443 // Logs when a request has been cancelled. 444 // Logs when a request has been cancelled.
444 void LogCancelRequest(const BoundNetLog& source_net_log, 445 void LogCancelRequest(const NetLogWithSource& source_net_log,
445 const HostResolverImpl::RequestInfo& info) { 446 const HostResolverImpl::RequestInfo& info) {
446 source_net_log.AddEvent(NetLogEventType::CANCELLED); 447 source_net_log.AddEvent(NetLogEventType::CANCELLED);
447 source_net_log.EndEvent(NetLogEventType::HOST_RESOLVER_IMPL_REQUEST); 448 source_net_log.EndEvent(NetLogEventType::HOST_RESOLVER_IMPL_REQUEST);
448 } 449 }
449 450
450 //----------------------------------------------------------------------------- 451 //-----------------------------------------------------------------------------
451 452
452 // Keeps track of the highest priority. 453 // Keeps track of the highest priority.
453 class PriorityTracker { 454 class PriorityTracker {
454 public: 455 public:
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 return true; 526 return true;
526 } 527 }
527 528
528 const unsigned HostResolverImpl::kMaximumDnsFailures = 16; 529 const unsigned HostResolverImpl::kMaximumDnsFailures = 16;
529 530
530 // Holds the data for a request that could not be completed synchronously. 531 // Holds the data for a request that could not be completed synchronously.
531 // It is owned by a Job. Canceled Requests are only marked as canceled rather 532 // It is owned by a Job. Canceled Requests are only marked as canceled rather
532 // than removed from the Job's |requests_| list. 533 // than removed from the Job's |requests_| list.
533 class HostResolverImpl::RequestImpl : public HostResolver::Request { 534 class HostResolverImpl::RequestImpl : public HostResolver::Request {
534 public: 535 public:
535 RequestImpl(const BoundNetLog& source_net_log, 536 RequestImpl(const NetLogWithSource& source_net_log,
536 const RequestInfo& info, 537 const RequestInfo& info,
537 RequestPriority priority, 538 RequestPriority priority,
538 const CompletionCallback& callback, 539 const CompletionCallback& callback,
539 AddressList* addresses, 540 AddressList* addresses,
540 Job* job) 541 Job* job)
541 : source_net_log_(source_net_log), 542 : source_net_log_(source_net_log),
542 info_(info), 543 info_(info),
543 priority_(priority), 544 priority_(priority),
544 job_(job), 545 job_(job),
545 callback_(callback), 546 callback_(callback),
(...skipping 19 matching lines...) Expand all
565 job_ = nullptr; 566 job_ = nullptr;
566 addresses_ = nullptr; 567 addresses_ = nullptr;
567 base::ResetAndReturn(&callback_).Run(error); 568 base::ResetAndReturn(&callback_).Run(error);
568 } 569 }
569 570
570 Job* job() const { 571 Job* job() const {
571 return job_; 572 return job_;
572 } 573 }
573 574
574 // NetLog for the source, passed in HostResolver::Resolve. 575 // NetLog for the source, passed in HostResolver::Resolve.
575 const BoundNetLog& source_net_log() { 576 const NetLogWithSource& source_net_log() { return source_net_log_; }
576 return source_net_log_;
577 }
578 577
579 const RequestInfo& info() const { 578 const RequestInfo& info() const {
580 return info_; 579 return info_;
581 } 580 }
582 581
583 RequestPriority priority() const { return priority_; } 582 RequestPriority priority() const { return priority_; }
584 void set_priority(RequestPriority priority) { priority_ = priority; } 583 void set_priority(RequestPriority priority) { priority_ = priority; }
585 584
586 base::TimeTicks request_time() const { return request_time_; } 585 base::TimeTicks request_time() const { return request_time_; }
587 586
588 private: 587 private:
589 const BoundNetLog source_net_log_; 588 const NetLogWithSource source_net_log_;
590 589
591 // The request info that started the request. 590 // The request info that started the request.
592 const RequestInfo info_; 591 const RequestInfo info_;
593 592
594 RequestPriority priority_; 593 RequestPriority priority_;
595 594
596 // The resolve job that this request is dependent on. 595 // The resolve job that this request is dependent on.
597 Job* job_; 596 Job* job_;
598 597
599 // The user's callback to invoke when the request completes. 598 // The user's callback to invoke when the request completes.
(...skipping 23 matching lines...) Expand all
623 class HostResolverImpl::ProcTask 622 class HostResolverImpl::ProcTask
624 : public base::RefCountedThreadSafe<HostResolverImpl::ProcTask> { 623 : public base::RefCountedThreadSafe<HostResolverImpl::ProcTask> {
625 public: 624 public:
626 typedef base::Callback<void(int net_error, 625 typedef base::Callback<void(int net_error,
627 const AddressList& addr_list)> Callback; 626 const AddressList& addr_list)> Callback;
628 627
629 ProcTask(const Key& key, 628 ProcTask(const Key& key,
630 const ProcTaskParams& params, 629 const ProcTaskParams& params,
631 const Callback& callback, 630 const Callback& callback,
632 scoped_refptr<base::TaskRunner> worker_task_runner, 631 scoped_refptr<base::TaskRunner> worker_task_runner,
633 const BoundNetLog& job_net_log) 632 const NetLogWithSource& job_net_log)
634 : key_(key), 633 : key_(key),
635 params_(params), 634 params_(params),
636 callback_(callback), 635 callback_(callback),
637 worker_task_runner_(std::move(worker_task_runner)), 636 worker_task_runner_(std::move(worker_task_runner)),
638 network_task_runner_(base::ThreadTaskRunnerHandle::Get()), 637 network_task_runner_(base::ThreadTaskRunnerHandle::Get()),
639 attempt_number_(0), 638 attempt_number_(0),
640 completed_attempt_number_(0), 639 completed_attempt_number_(0),
641 completed_attempt_error_(ERR_UNEXPECTED), 640 completed_attempt_error_(ERR_UNEXPECTED),
642 had_non_speculative_request_(false), 641 had_non_speculative_request_(false),
643 net_log_(job_net_log) { 642 net_log_(job_net_log) {
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
982 base::TimeTicks retry_attempt_finished_time_; 981 base::TimeTicks retry_attempt_finished_time_;
983 982
984 // True if a non-speculative request was ever attached to this job 983 // True if a non-speculative request was ever attached to this job
985 // (regardless of whether or not it was later canceled. 984 // (regardless of whether or not it was later canceled.
986 // This boolean is used for histogramming the duration of jobs used to 985 // This boolean is used for histogramming the duration of jobs used to
987 // service non-speculative requests. 986 // service non-speculative requests.
988 bool had_non_speculative_request_; 987 bool had_non_speculative_request_;
989 988
990 AddressList results_; 989 AddressList results_;
991 990
992 BoundNetLog net_log_; 991 NetLogWithSource net_log_;
993 992
994 DISALLOW_COPY_AND_ASSIGN(ProcTask); 993 DISALLOW_COPY_AND_ASSIGN(ProcTask);
995 }; 994 };
996 995
997 //----------------------------------------------------------------------------- 996 //-----------------------------------------------------------------------------
998 997
999 // Wraps a call to HaveOnlyLoopbackAddresses to be executed on a 998 // Wraps a call to HaveOnlyLoopbackAddresses to be executed on a
1000 // |worker_task_runner|, as it takes 40-100ms and should not block 999 // |worker_task_runner|, as it takes 40-100ms and should not block
1001 // initialization. 1000 // initialization.
1002 class HostResolverImpl::LoopbackProbeJob { 1001 class HostResolverImpl::LoopbackProbeJob {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1060 virtual void OnFirstDnsTransactionComplete() = 0; 1059 virtual void OnFirstDnsTransactionComplete() = 0;
1061 1060
1062 protected: 1061 protected:
1063 Delegate() {} 1062 Delegate() {}
1064 virtual ~Delegate() {} 1063 virtual ~Delegate() {}
1065 }; 1064 };
1066 1065
1067 DnsTask(DnsClient* client, 1066 DnsTask(DnsClient* client,
1068 const Key& key, 1067 const Key& key,
1069 Delegate* delegate, 1068 Delegate* delegate,
1070 const BoundNetLog& job_net_log) 1069 const NetLogWithSource& job_net_log)
1071 : client_(client), 1070 : client_(client),
1072 key_(key), 1071 key_(key),
1073 delegate_(delegate), 1072 delegate_(delegate),
1074 net_log_(job_net_log), 1073 net_log_(job_net_log),
1075 num_completed_transactions_(0), 1074 num_completed_transactions_(0),
1076 task_start_time_(base::TimeTicks::Now()) { 1075 task_start_time_(base::TimeTicks::Now()) {
1077 DCHECK(client); 1076 DCHECK(client);
1078 DCHECK(delegate_); 1077 DCHECK(delegate_);
1079 } 1078 }
1080 1079
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
1243 net_log_.EndEvent(NetLogEventType::HOST_RESOLVER_IMPL_DNS_TASK, 1242 net_log_.EndEvent(NetLogEventType::HOST_RESOLVER_IMPL_DNS_TASK,
1244 addr_list.CreateNetLogCallback()); 1243 addr_list.CreateNetLogCallback());
1245 delegate_->OnDnsTaskComplete(task_start_time_, OK, addr_list, ttl_); 1244 delegate_->OnDnsTaskComplete(task_start_time_, OK, addr_list, ttl_);
1246 } 1245 }
1247 1246
1248 DnsClient* client_; 1247 DnsClient* client_;
1249 Key key_; 1248 Key key_;
1250 1249
1251 // The listener to the results of this DnsTask. 1250 // The listener to the results of this DnsTask.
1252 Delegate* delegate_; 1251 Delegate* delegate_;
1253 const BoundNetLog net_log_; 1252 const NetLogWithSource net_log_;
1254 1253
1255 std::unique_ptr<DnsTransaction> transaction_a_; 1254 std::unique_ptr<DnsTransaction> transaction_a_;
1256 std::unique_ptr<DnsTransaction> transaction_aaaa_; 1255 std::unique_ptr<DnsTransaction> transaction_aaaa_;
1257 1256
1258 unsigned num_completed_transactions_; 1257 unsigned num_completed_transactions_;
1259 1258
1260 // These are updated as each transaction completes. 1259 // These are updated as each transaction completes.
1261 base::TimeDelta ttl_; 1260 base::TimeDelta ttl_;
1262 // IPv6 addresses must appear first in the list. 1261 // IPv6 addresses must appear first in the list.
1263 AddressList addr_list_; 1262 AddressList addr_list_;
1264 1263
1265 base::TimeTicks task_start_time_; 1264 base::TimeTicks task_start_time_;
1266 1265
1267 DISALLOW_COPY_AND_ASSIGN(DnsTask); 1266 DISALLOW_COPY_AND_ASSIGN(DnsTask);
1268 }; 1267 };
1269 1268
1270 //----------------------------------------------------------------------------- 1269 //-----------------------------------------------------------------------------
1271 1270
1272 // Aggregates all Requests for the same Key. Dispatched via PriorityDispatch. 1271 // Aggregates all Requests for the same Key. Dispatched via PriorityDispatch.
1273 class HostResolverImpl::Job : public PrioritizedDispatcher::Job, 1272 class HostResolverImpl::Job : public PrioritizedDispatcher::Job,
1274 public HostResolverImpl::DnsTask::Delegate { 1273 public HostResolverImpl::DnsTask::Delegate {
1275 public: 1274 public:
1276 // Creates new job for |key| where |request_net_log| is bound to the 1275 // Creates new job for |key| where |request_net_log| is bound to the
1277 // request that spawned it. 1276 // request that spawned it.
1278 Job(const base::WeakPtr<HostResolverImpl>& resolver, 1277 Job(const base::WeakPtr<HostResolverImpl>& resolver,
1279 const Key& key, 1278 const Key& key,
1280 RequestPriority priority, 1279 RequestPriority priority,
1281 scoped_refptr<base::TaskRunner> worker_task_runner, 1280 scoped_refptr<base::TaskRunner> worker_task_runner,
1282 const BoundNetLog& source_net_log) 1281 const NetLogWithSource& source_net_log)
1283 : resolver_(resolver), 1282 : resolver_(resolver),
1284 key_(key), 1283 key_(key),
1285 priority_tracker_(priority), 1284 priority_tracker_(priority),
1286 worker_task_runner_(std::move(worker_task_runner)), 1285 worker_task_runner_(std::move(worker_task_runner)),
1287 had_non_speculative_request_(false), 1286 had_non_speculative_request_(false),
1288 had_dns_config_(false), 1287 had_dns_config_(false),
1289 num_occupied_job_slots_(0), 1288 num_occupied_job_slots_(0),
1290 dns_task_error_(OK), 1289 dns_task_error_(OK),
1291 creation_time_(base::TimeTicks::Now()), 1290 creation_time_(base::TimeTicks::Now()),
1292 priority_change_time_(creation_time_), 1291 priority_change_time_(creation_time_),
1293 net_log_(BoundNetLog::Make(source_net_log.net_log(), 1292 net_log_(
1293 NetLogWithSource::Make(source_net_log.net_log(),
1294 NetLogSourceType::HOST_RESOLVER_IMPL_JOB)) { 1294 NetLogSourceType::HOST_RESOLVER_IMPL_JOB)) {
1295 source_net_log.AddEvent(NetLogEventType::HOST_RESOLVER_IMPL_CREATE_JOB); 1295 source_net_log.AddEvent(NetLogEventType::HOST_RESOLVER_IMPL_CREATE_JOB);
1296 1296
1297 net_log_.BeginEvent(NetLogEventType::HOST_RESOLVER_IMPL_JOB, 1297 net_log_.BeginEvent(NetLogEventType::HOST_RESOLVER_IMPL_JOB,
1298 base::Bind(&NetLogJobCreationCallback, 1298 base::Bind(&NetLogJobCreationCallback,
1299 source_net_log.source(), &key_.hostname)); 1299 source_net_log.source(), &key_.hostname));
1300 } 1300 }
1301 1301
1302 ~Job() override { 1302 ~Job() override {
1303 if (is_running()) { 1303 if (is_running()) {
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after
1839 1839
1840 // Number of slots occupied by this Job in resolver's PrioritizedDispatcher. 1840 // Number of slots occupied by this Job in resolver's PrioritizedDispatcher.
1841 unsigned num_occupied_job_slots_; 1841 unsigned num_occupied_job_slots_;
1842 1842
1843 // Result of DnsTask. 1843 // Result of DnsTask.
1844 int dns_task_error_; 1844 int dns_task_error_;
1845 1845
1846 const base::TimeTicks creation_time_; 1846 const base::TimeTicks creation_time_;
1847 base::TimeTicks priority_change_time_; 1847 base::TimeTicks priority_change_time_;
1848 1848
1849 BoundNetLog net_log_; 1849 NetLogWithSource net_log_;
1850 1850
1851 // Resolves the host using a HostResolverProc. 1851 // Resolves the host using a HostResolverProc.
1852 scoped_refptr<ProcTask> proc_task_; 1852 scoped_refptr<ProcTask> proc_task_;
1853 1853
1854 // Resolves the host using a DnsTransaction. 1854 // Resolves the host using a DnsTransaction.
1855 std::unique_ptr<DnsTask> dns_task_; 1855 std::unique_ptr<DnsTask> dns_task_;
1856 1856
1857 // All Requests waiting for the result of this Job. Some can be canceled. 1857 // All Requests waiting for the result of this Job. Some can be canceled.
1858 std::deque<RequestImpl*> requests_; 1858 std::deque<RequestImpl*> requests_;
1859 1859
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1904 DCHECK_EQ(0u, dispatcher_->num_queued_jobs()); 1904 DCHECK_EQ(0u, dispatcher_->num_queued_jobs());
1905 DCHECK_GT(value, 0u); 1905 DCHECK_GT(value, 0u);
1906 max_queued_jobs_ = value; 1906 max_queued_jobs_ = value;
1907 } 1907 }
1908 1908
1909 int HostResolverImpl::Resolve(const RequestInfo& info, 1909 int HostResolverImpl::Resolve(const RequestInfo& info,
1910 RequestPriority priority, 1910 RequestPriority priority,
1911 AddressList* addresses, 1911 AddressList* addresses,
1912 const CompletionCallback& callback, 1912 const CompletionCallback& callback,
1913 std::unique_ptr<Request>* out_req, 1913 std::unique_ptr<Request>* out_req,
1914 const BoundNetLog& source_net_log) { 1914 const NetLogWithSource& source_net_log) {
1915 DCHECK(addresses); 1915 DCHECK(addresses);
1916 DCHECK(CalledOnValidThread()); 1916 DCHECK(CalledOnValidThread());
1917 DCHECK_EQ(false, callback.is_null()); 1917 DCHECK_EQ(false, callback.is_null());
1918 DCHECK(out_req); 1918 DCHECK(out_req);
1919 1919
1920 // Check that the caller supplied a valid hostname to resolve. 1920 // Check that the caller supplied a valid hostname to resolve.
1921 if (!IsValidDNSDomain(info.hostname())) 1921 if (!IsValidDNSDomain(info.hostname()))
1922 return ERR_NAME_NOT_RESOLVED; 1922 return ERR_NAME_NOT_RESOLVED;
1923 1923
1924 LogStartRequest(source_net_log, info); 1924 LogStartRequest(source_net_log, info);
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
2038 additional_resolver_flags_ &= ~HOST_RESOLVER_LOOPBACK_ONLY; 2038 additional_resolver_flags_ &= ~HOST_RESOLVER_LOOPBACK_ONLY;
2039 } 2039 }
2040 } 2040 }
2041 2041
2042 int HostResolverImpl::ResolveHelper(const Key& key, 2042 int HostResolverImpl::ResolveHelper(const Key& key,
2043 const RequestInfo& info, 2043 const RequestInfo& info,
2044 const IPAddress* ip_address, 2044 const IPAddress* ip_address,
2045 AddressList* addresses, 2045 AddressList* addresses,
2046 bool allow_stale, 2046 bool allow_stale,
2047 HostCache::EntryStaleness* stale_info, 2047 HostCache::EntryStaleness* stale_info,
2048 const BoundNetLog& source_net_log) { 2048 const NetLogWithSource& source_net_log) {
2049 DCHECK(allow_stale == !!stale_info); 2049 DCHECK(allow_stale == !!stale_info);
2050 // The result of |getaddrinfo| for empty hosts is inconsistent across systems. 2050 // The result of |getaddrinfo| for empty hosts is inconsistent across systems.
2051 // On Windows it gives the default interface's address, whereas on Linux it 2051 // On Windows it gives the default interface's address, whereas on Linux it
2052 // gives an error. We will make it fail on all platforms for consistency. 2052 // gives an error. We will make it fail on all platforms for consistency.
2053 if (info.hostname().empty() || info.hostname().size() > kMaxHostLength) { 2053 if (info.hostname().empty() || info.hostname().size() > kMaxHostLength) {
2054 MakeNotStale(stale_info); 2054 MakeNotStale(stale_info);
2055 return ERR_NAME_NOT_RESOLVED; 2055 return ERR_NAME_NOT_RESOLVED;
2056 } 2056 }
2057 2057
2058 int net_error = ERR_UNEXPECTED; 2058 int net_error = ERR_UNEXPECTED;
(...skipping 19 matching lines...) Expand all
2078 if (ServeLocalhost(key, info, addresses)) { 2078 if (ServeLocalhost(key, info, addresses)) {
2079 MakeNotStale(stale_info); 2079 MakeNotStale(stale_info);
2080 return OK; 2080 return OK;
2081 } 2081 }
2082 2082
2083 return ERR_DNS_CACHE_MISS; 2083 return ERR_DNS_CACHE_MISS;
2084 } 2084 }
2085 2085
2086 int HostResolverImpl::ResolveFromCache(const RequestInfo& info, 2086 int HostResolverImpl::ResolveFromCache(const RequestInfo& info,
2087 AddressList* addresses, 2087 AddressList* addresses,
2088 const BoundNetLog& source_net_log) { 2088 const NetLogWithSource& source_net_log) {
2089 DCHECK(CalledOnValidThread()); 2089 DCHECK(CalledOnValidThread());
2090 DCHECK(addresses); 2090 DCHECK(addresses);
2091 2091
2092 // Update the net log and notify registered observers. 2092 // Update the net log and notify registered observers.
2093 LogStartRequest(source_net_log, info); 2093 LogStartRequest(source_net_log, info);
2094 2094
2095 IPAddress ip_address; 2095 IPAddress ip_address;
2096 IPAddress* ip_address_ptr = nullptr; 2096 IPAddress* ip_address_ptr = nullptr;
2097 if (ip_address.AssignFromIPLiteral(info.hostname())) 2097 if (ip_address.AssignFromIPLiteral(info.hostname()))
2098 ip_address_ptr = &ip_address; 2098 ip_address_ptr = &ip_address;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
2131 if (!dns_config) 2131 if (!dns_config)
2132 return base::MakeUnique<base::DictionaryValue>(); 2132 return base::MakeUnique<base::DictionaryValue>();
2133 2133
2134 return dns_config->ToValue(); 2134 return dns_config->ToValue();
2135 } 2135 }
2136 2136
2137 int HostResolverImpl::ResolveStaleFromCache( 2137 int HostResolverImpl::ResolveStaleFromCache(
2138 const RequestInfo& info, 2138 const RequestInfo& info,
2139 AddressList* addresses, 2139 AddressList* addresses,
2140 HostCache::EntryStaleness* stale_info, 2140 HostCache::EntryStaleness* stale_info,
2141 const BoundNetLog& source_net_log) { 2141 const NetLogWithSource& source_net_log) {
2142 DCHECK(CalledOnValidThread()); 2142 DCHECK(CalledOnValidThread());
2143 DCHECK(addresses); 2143 DCHECK(addresses);
2144 DCHECK(stale_info); 2144 DCHECK(stale_info);
2145 2145
2146 // Update the net log and notify registered observers. 2146 // Update the net log and notify registered observers.
2147 LogStartRequest(source_net_log, info); 2147 LogStartRequest(source_net_log, info);
2148 2148
2149 IPAddress ip_address; 2149 IPAddress ip_address;
2150 IPAddress* ip_address_ptr = nullptr; 2150 IPAddress* ip_address_ptr = nullptr;
2151 if (ip_address.AssignFromIPLiteral(info.hostname())) 2151 if (ip_address.AssignFromIPLiteral(info.hostname()))
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
2299 void HostResolverImpl::RemoveJob(Job* job) { 2299 void HostResolverImpl::RemoveJob(Job* job) {
2300 DCHECK(job); 2300 DCHECK(job);
2301 JobMap::iterator it = jobs_.find(job->key()); 2301 JobMap::iterator it = jobs_.find(job->key());
2302 if (it != jobs_.end() && it->second == job) 2302 if (it != jobs_.end() && it->second == job)
2303 jobs_.erase(it); 2303 jobs_.erase(it);
2304 } 2304 }
2305 2305
2306 HostResolverImpl::Key HostResolverImpl::GetEffectiveKeyForRequest( 2306 HostResolverImpl::Key HostResolverImpl::GetEffectiveKeyForRequest(
2307 const RequestInfo& info, 2307 const RequestInfo& info,
2308 const IPAddress* ip_address, 2308 const IPAddress* ip_address,
2309 const BoundNetLog& net_log) { 2309 const NetLogWithSource& net_log) {
2310 HostResolverFlags effective_flags = 2310 HostResolverFlags effective_flags =
2311 info.host_resolver_flags() | additional_resolver_flags_; 2311 info.host_resolver_flags() | additional_resolver_flags_;
2312 AddressFamily effective_address_family = info.address_family(); 2312 AddressFamily effective_address_family = info.address_family();
2313 2313
2314 if (info.address_family() == ADDRESS_FAMILY_UNSPECIFIED) { 2314 if (info.address_family() == ADDRESS_FAMILY_UNSPECIFIED) {
2315 if (!use_local_ipv6_ && 2315 if (!use_local_ipv6_ &&
2316 // When resolving IPv4 literals, there's no need to probe for IPv6. 2316 // When resolving IPv4 literals, there's no need to probe for IPv6.
2317 // When resolving IPv6 literals, there's no benefit to artificially 2317 // When resolving IPv6 literals, there's no benefit to artificially
2318 // limiting our resolution based on a probe. Prior logic ensures 2318 // limiting our resolution based on a probe. Prior logic ensures
2319 // that this query is UNSPECIFIED (see info.address_family() 2319 // that this query is UNSPECIFIED (see info.address_family()
2320 // check above) so the code requesting the resolution should be amenable 2320 // check above) so the code requesting the resolution should be amenable
2321 // to receiving a IPv6 resolution. 2321 // to receiving a IPv6 resolution.
2322 ip_address == nullptr) { 2322 ip_address == nullptr) {
2323 if (!IsIPv6Reachable(net_log)) { 2323 if (!IsIPv6Reachable(net_log)) {
2324 effective_address_family = ADDRESS_FAMILY_IPV4; 2324 effective_address_family = ADDRESS_FAMILY_IPV4;
2325 effective_flags |= HOST_RESOLVER_DEFAULT_FAMILY_SET_DUE_TO_NO_IPV6; 2325 effective_flags |= HOST_RESOLVER_DEFAULT_FAMILY_SET_DUE_TO_NO_IPV6;
2326 } 2326 }
2327 } 2327 }
2328 } 2328 }
2329 2329
2330 return Key(info.hostname(), effective_address_family, effective_flags); 2330 return Key(info.hostname(), effective_address_family, effective_flags);
2331 } 2331 }
2332 2332
2333 bool HostResolverImpl::IsIPv6Reachable(const BoundNetLog& net_log) { 2333 bool HostResolverImpl::IsIPv6Reachable(const NetLogWithSource& net_log) {
2334 base::TimeTicks now = base::TimeTicks::Now(); 2334 base::TimeTicks now = base::TimeTicks::Now();
2335 bool cached = true; 2335 bool cached = true;
2336 if ((now - last_ipv6_probe_time_).InMilliseconds() > kIPv6ProbePeriodMs) { 2336 if ((now - last_ipv6_probe_time_).InMilliseconds() > kIPv6ProbePeriodMs) {
2337 last_ipv6_probe_result_ = 2337 last_ipv6_probe_result_ =
2338 IsGloballyReachable(IPAddress(kIPv6ProbeAddress), net_log); 2338 IsGloballyReachable(IPAddress(kIPv6ProbeAddress), net_log);
2339 last_ipv6_probe_time_ = now; 2339 last_ipv6_probe_time_ = now;
2340 cached = false; 2340 cached = false;
2341 } 2341 }
2342 net_log.AddEvent(NetLogEventType::HOST_RESOLVER_IMPL_IPV6_REACHABILITY_CHECK, 2342 net_log.AddEvent(NetLogEventType::HOST_RESOLVER_IMPL_IPV6_REACHABILITY_CHECK,
2343 base::Bind(&NetLogIPv6AvailableCallback, 2343 base::Bind(&NetLogIPv6AvailableCallback,
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
2605 if (job_) 2605 if (job_)
2606 job_->CancelRequest(this); 2606 job_->CancelRequest(this);
2607 } 2607 }
2608 2608
2609 void HostResolverImpl::RequestImpl::ChangeRequestPriority( 2609 void HostResolverImpl::RequestImpl::ChangeRequestPriority(
2610 RequestPriority priority) { 2610 RequestPriority priority) {
2611 job_->ChangeRequestPriority(this, priority); 2611 job_->ChangeRequestPriority(this, priority);
2612 } 2612 }
2613 2613
2614 } // namespace net 2614 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698