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 #include <algorithm> | 7 #include <algorithm> |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 #include <tuple> | 10 #include <tuple> |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 quit_on_complete_(false), | 228 quit_on_complete_(false), |
229 result_(ERR_UNEXPECTED) {} | 229 result_(ERR_UNEXPECTED) {} |
230 | 230 |
231 int Resolve() { | 231 int Resolve() { |
232 DCHECK(resolver_); | 232 DCHECK(resolver_); |
233 DCHECK(!request_); | 233 DCHECK(!request_); |
234 list_ = AddressList(); | 234 list_ = AddressList(); |
235 result_ = resolver_->Resolve( | 235 result_ = resolver_->Resolve( |
236 info_, priority_, &list_, | 236 info_, priority_, &list_, |
237 base::Bind(&Request::OnComplete, base::Unretained(this)), &request_, | 237 base::Bind(&Request::OnComplete, base::Unretained(this)), &request_, |
238 BoundNetLog()); | 238 NetLogWithSource()); |
239 if (!list_.empty()) | 239 if (!list_.empty()) |
240 EXPECT_THAT(result_, IsOk()); | 240 EXPECT_THAT(result_, IsOk()); |
241 return result_; | 241 return result_; |
242 } | 242 } |
243 | 243 |
244 int ResolveFromCache() { | 244 int ResolveFromCache() { |
245 DCHECK(resolver_); | 245 DCHECK(resolver_); |
246 DCHECK(!request_); | 246 DCHECK(!request_); |
247 return resolver_->ResolveFromCache(info_, &list_, BoundNetLog()); | 247 return resolver_->ResolveFromCache(info_, &list_, NetLogWithSource()); |
248 } | 248 } |
249 | 249 |
250 int ResolveStaleFromCache() { | 250 int ResolveStaleFromCache() { |
251 DCHECK(resolver_); | 251 DCHECK(resolver_); |
252 DCHECK(!request_); | 252 DCHECK(!request_); |
253 return resolver_->ResolveStaleFromCache(info_, &list_, &staleness_, | 253 return resolver_->ResolveStaleFromCache(info_, &list_, &staleness_, |
254 BoundNetLog()); | 254 NetLogWithSource()); |
255 } | 255 } |
256 | 256 |
257 void ChangePriority(RequestPriority priority) { | 257 void ChangePriority(RequestPriority priority) { |
258 DCHECK(resolver_); | 258 DCHECK(resolver_); |
259 DCHECK(request_); | 259 DCHECK(request_); |
260 request_->ChangeRequestPriority(priority); | 260 request_->ChangeRequestPriority(priority); |
261 priority_ = priority; | 261 priority_ = priority; |
262 } | 262 } |
263 | 263 |
264 void Cancel() { | 264 void Cancel() { |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 TestHostResolverImpl(const Options& options, | 454 TestHostResolverImpl(const Options& options, |
455 NetLog* net_log, | 455 NetLog* net_log, |
456 bool ipv6_reachable) | 456 bool ipv6_reachable) |
457 : HostResolverImpl(options, net_log), ipv6_reachable_(ipv6_reachable) {} | 457 : HostResolverImpl(options, net_log), ipv6_reachable_(ipv6_reachable) {} |
458 | 458 |
459 ~TestHostResolverImpl() override {} | 459 ~TestHostResolverImpl() override {} |
460 | 460 |
461 private: | 461 private: |
462 const bool ipv6_reachable_; | 462 const bool ipv6_reachable_; |
463 | 463 |
464 bool IsIPv6Reachable(const BoundNetLog& net_log) override { | 464 bool IsIPv6Reachable(const NetLogWithSource& net_log) override { |
465 return ipv6_reachable_; | 465 return ipv6_reachable_; |
466 } | 466 } |
467 }; | 467 }; |
468 | 468 |
469 const uint16_t kLocalhostLookupPort = 80; | 469 const uint16_t kLocalhostLookupPort = 80; |
470 | 470 |
471 bool HasEndpoint(const IPEndPoint& endpoint, const AddressList& addresses) { | 471 bool HasEndpoint(const IPEndPoint& endpoint, const AddressList& addresses) { |
472 for (const auto& address : addresses) { | 472 for (const auto& address : addresses) { |
473 if (endpoint == address) | 473 if (endpoint == address) |
474 return true; | 474 return true; |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
605 | 605 |
606 void set_fallback_to_proctask(bool fallback_to_proctask) { | 606 void set_fallback_to_proctask(bool fallback_to_proctask) { |
607 DCHECK(resolver_.get()); | 607 DCHECK(resolver_.get()); |
608 resolver_->fallback_to_proctask_ = fallback_to_proctask; | 608 resolver_->fallback_to_proctask_ = fallback_to_proctask; |
609 } | 609 } |
610 | 610 |
611 static unsigned maximum_dns_failures() { | 611 static unsigned maximum_dns_failures() { |
612 return HostResolverImpl::kMaximumDnsFailures; | 612 return HostResolverImpl::kMaximumDnsFailures; |
613 } | 613 } |
614 | 614 |
615 bool IsIPv6Reachable(const BoundNetLog& net_log) { | 615 bool IsIPv6Reachable(const NetLogWithSource& net_log) { |
616 return resolver_->IsIPv6Reachable(net_log); | 616 return resolver_->IsIPv6Reachable(net_log); |
617 } | 617 } |
618 | 618 |
619 void MakeCacheStale() { | 619 void MakeCacheStale() { |
620 DCHECK(resolver_.get()); | 620 DCHECK(resolver_.get()); |
621 resolver_->GetHostCache()->OnNetworkChange(); | 621 resolver_->GetHostCache()->OnNetworkChange(); |
622 } | 622 } |
623 | 623 |
624 scoped_refptr<MockHostResolverProc> proc_; | 624 scoped_refptr<MockHostResolverProc> proc_; |
625 std::unique_ptr<HostResolverImpl> resolver_; | 625 std::unique_ptr<HostResolverImpl> resolver_; |
(...skipping 903 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1529 EXPECT_THAT(request->Resolve(), IsError(ERR_IO_PENDING)); | 1529 EXPECT_THAT(request->Resolve(), IsError(ERR_IO_PENDING)); |
1530 EXPECT_THAT(request->WaitForResult(), IsOk()); | 1530 EXPECT_THAT(request->WaitForResult(), IsOk()); |
1531 } | 1531 } |
1532 | 1532 |
1533 TEST_F(HostResolverImplTest, IsIPv6Reachable) { | 1533 TEST_F(HostResolverImplTest, IsIPv6Reachable) { |
1534 // The real HostResolverImpl is needed since TestHostResolverImpl will | 1534 // The real HostResolverImpl is needed since TestHostResolverImpl will |
1535 // bypass the IPv6 reachability tests. | 1535 // bypass the IPv6 reachability tests. |
1536 resolver_.reset(new HostResolverImpl(DefaultOptions(), nullptr)); | 1536 resolver_.reset(new HostResolverImpl(DefaultOptions(), nullptr)); |
1537 | 1537 |
1538 // Verify that two consecutive calls return the same value. | 1538 // Verify that two consecutive calls return the same value. |
1539 TestNetLog net_log; | 1539 TestNetLog test_net_log; |
1540 BoundNetLog bound_net_log = | 1540 NetLogWithSource net_log = |
1541 BoundNetLog::Make(&net_log, NetLogSourceType::NONE); | 1541 NetLogWithSource::Make(&test_net_log, NetLogSourceType::NONE); |
1542 bool result1 = IsIPv6Reachable(bound_net_log); | 1542 bool result1 = IsIPv6Reachable(net_log); |
1543 bool result2 = IsIPv6Reachable(bound_net_log); | 1543 bool result2 = IsIPv6Reachable(net_log); |
1544 EXPECT_EQ(result1, result2); | 1544 EXPECT_EQ(result1, result2); |
1545 | 1545 |
1546 // Filter reachability check events and verify that there are two of them. | 1546 // Filter reachability check events and verify that there are two of them. |
1547 TestNetLogEntry::List event_list; | 1547 TestNetLogEntry::List event_list; |
1548 net_log.GetEntries(&event_list); | 1548 test_net_log.GetEntries(&event_list); |
1549 TestNetLogEntry::List probe_event_list; | 1549 TestNetLogEntry::List probe_event_list; |
1550 for (const auto& event : event_list) { | 1550 for (const auto& event : event_list) { |
1551 if (event.type == | 1551 if (event.type == |
1552 NetLogEventType::HOST_RESOLVER_IMPL_IPV6_REACHABILITY_CHECK) { | 1552 NetLogEventType::HOST_RESOLVER_IMPL_IPV6_REACHABILITY_CHECK) { |
1553 probe_event_list.push_back(event); | 1553 probe_event_list.push_back(event); |
1554 } | 1554 } |
1555 } | 1555 } |
1556 ASSERT_EQ(2U, probe_event_list.size()); | 1556 ASSERT_EQ(2U, probe_event_list.size()); |
1557 | 1557 |
1558 // Verify that the first request was not cached and the second one was. | 1558 // Verify that the first request was not cached and the second one was. |
(...skipping 896 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2455 EXPECT_EQ(1, count2); | 2455 EXPECT_EQ(1, count2); |
2456 | 2456 |
2457 // Make another request to make sure both callbacks were cleared. | 2457 // Make another request to make sure both callbacks were cleared. |
2458 req = CreateRequest("just.testing", 80); | 2458 req = CreateRequest("just.testing", 80); |
2459 EXPECT_THAT(req->Resolve(), IsOk()); | 2459 EXPECT_THAT(req->Resolve(), IsOk()); |
2460 EXPECT_EQ(2, count1); | 2460 EXPECT_EQ(2, count1); |
2461 EXPECT_EQ(1, count2); | 2461 EXPECT_EQ(1, count2); |
2462 } | 2462 } |
2463 | 2463 |
2464 } // namespace net | 2464 } // namespace net |
OLD | NEW |