| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/proxy/proxy_resolver_v8_tracing.h" | 5 #include "net/proxy/proxy_resolver_v8_tracing.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| (...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 678 // has been received. The resolve requests it receives will never be completed. | 678 // has been received. The resolve requests it receives will never be completed. |
| 679 class BlockableHostResolver : public HostResolver { | 679 class BlockableHostResolver : public HostResolver { |
| 680 public: | 680 public: |
| 681 BlockableHostResolver() | 681 BlockableHostResolver() |
| 682 : num_cancelled_requests_(0), waiting_for_resolve_(false) {} | 682 : num_cancelled_requests_(0), waiting_for_resolve_(false) {} |
| 683 | 683 |
| 684 int Resolve(const RequestInfo& info, | 684 int Resolve(const RequestInfo& info, |
| 685 RequestPriority priority, | 685 RequestPriority priority, |
| 686 AddressList* addresses, | 686 AddressList* addresses, |
| 687 const CompletionCallback& callback, | 687 const CompletionCallback& callback, |
| 688 RequestHandle* out_req, | 688 std::unique_ptr<Request>* out_req, |
| 689 const BoundNetLog& net_log) override { | 689 const BoundNetLog& net_log) override { |
| 690 EXPECT_FALSE(callback.is_null()); | 690 EXPECT_FALSE(callback.is_null()); |
| 691 EXPECT_TRUE(out_req); | 691 EXPECT_TRUE(out_req); |
| 692 | 692 |
| 693 if (!action_.is_null()) | 693 if (!action_.is_null()) |
| 694 action_.Run(); | 694 action_.Run(); |
| 695 | 695 |
| 696 // Indicate to the caller that a request was received. | 696 // Indicate to the caller that a request was received. |
| 697 EXPECT_TRUE(waiting_for_resolve_); | 697 EXPECT_TRUE(waiting_for_resolve_); |
| 698 base::MessageLoop::current()->QuitWhenIdle(); | 698 base::MessageLoop::current()->QuitWhenIdle(); |
| 699 | 699 |
| 700 // This line is intentionally after action_.Run(), since one of the | 700 // This line is intentionally after action_.Run(), since one of the |
| 701 // tests does a cancellation inside of Resolve(), and it is more | 701 // tests does a cancellation inside of Resolve(), and it is more |
| 702 // interesting if *out_req hasn't been written yet at that point. | 702 // interesting if *out_req hasn't been written yet at that point. |
| 703 *out_req = reinterpret_cast<RequestHandle*>(1); // Magic value. | 703 out_req->reset(new RequestImpl(this)); |
| 704 | 704 |
| 705 // Return ERR_IO_PENDING as this request will NEVER be completed. | 705 // Return ERR_IO_PENDING as this request will NEVER be completed. |
| 706 // Expectation is for the caller to later cancel the request. | 706 // Expectation is for the caller to later cancel the request. |
| 707 return ERR_IO_PENDING; | 707 return ERR_IO_PENDING; |
| 708 } | 708 } |
| 709 | 709 |
| 710 int ResolveFromCache(const RequestInfo& info, | 710 int ResolveFromCache(const RequestInfo& info, |
| 711 AddressList* addresses, | 711 AddressList* addresses, |
| 712 const BoundNetLog& net_log) override { | 712 const BoundNetLog& net_log) override { |
| 713 NOTREACHED(); | 713 NOTREACHED(); |
| 714 return ERR_DNS_CACHE_MISS; | 714 return ERR_DNS_CACHE_MISS; |
| 715 } | 715 } |
| 716 | 716 |
| 717 void CancelRequest(RequestHandle req) override { | 717 void IncreaseNumOfCancelledRequests() { num_cancelled_requests_++; } |
| 718 EXPECT_EQ(reinterpret_cast<RequestHandle*>(1), req); | |
| 719 num_cancelled_requests_++; | |
| 720 } | |
| 721 | 718 |
| 722 void SetAction(const base::Callback<void(void)>& action) { | 719 void SetAction(const base::Callback<void(void)>& action) { |
| 723 action_ = action; | 720 action_ = action; |
| 724 } | 721 } |
| 725 | 722 |
| 726 // Waits until Resolve() has been called. | 723 // Waits until Resolve() has been called. |
| 727 void WaitUntilRequestIsReceived() { | 724 void WaitUntilRequestIsReceived() { |
| 728 waiting_for_resolve_ = true; | 725 waiting_for_resolve_ = true; |
| 729 base::RunLoop().Run(); | 726 base::RunLoop().Run(); |
| 730 DCHECK(waiting_for_resolve_); | 727 DCHECK(waiting_for_resolve_); |
| 731 waiting_for_resolve_ = false; | 728 waiting_for_resolve_ = false; |
| 732 } | 729 } |
| 733 | 730 |
| 734 int num_cancelled_requests() const { | 731 int num_cancelled_requests() const { |
| 735 return num_cancelled_requests_; | 732 return num_cancelled_requests_; |
| 736 } | 733 } |
| 737 | 734 |
| 738 private: | 735 private: |
| 736 class RequestImpl : public HostResolver::Request { |
| 737 public: |
| 738 RequestImpl(BlockableHostResolver* resolver) : resolver_(resolver) {} |
| 739 |
| 740 ~RequestImpl() override { |
| 741 if (resolver_) |
| 742 resolver_->IncreaseNumOfCancelledRequests(); |
| 743 } |
| 744 |
| 745 void ChangeRequestPriority(RequestPriority priority) override {} |
| 746 |
| 747 private: |
| 748 BlockableHostResolver* resolver_; |
| 749 |
| 750 DISALLOW_COPY_AND_ASSIGN(RequestImpl); |
| 751 }; |
| 752 |
| 739 int num_cancelled_requests_; | 753 int num_cancelled_requests_; |
| 740 bool waiting_for_resolve_; | 754 bool waiting_for_resolve_; |
| 741 base::Callback<void(void)> action_; | 755 base::Callback<void(void)> action_; |
| 742 }; | 756 }; |
| 743 | 757 |
| 744 // This cancellation test exercises a more predictable cancellation codepath -- | 758 // This cancellation test exercises a more predictable cancellation codepath -- |
| 745 // when the request has an outstanding DNS request in flight. | 759 // when the request has an outstanding DNS request in flight. |
| 746 TEST_F(ProxyResolverV8TracingTest, CancelWhileOutstandingNonBlockingDns) { | 760 TEST_F(ProxyResolverV8TracingTest, CancelWhileOutstandingNonBlockingDns) { |
| 747 BlockableHostResolver host_resolver; | 761 BlockableHostResolver host_resolver; |
| 748 MockBindings mock_bindings(&host_resolver); | 762 MockBindings mock_bindings(&host_resolver); |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1021 proxy_uri.substr(0, proxy_uri.find(':') + 1)); | 1035 proxy_uri.substr(0, proxy_uri.find(':') + 1)); |
| 1022 } else { | 1036 } else { |
| 1023 NOTREACHED(); | 1037 NOTREACHED(); |
| 1024 } | 1038 } |
| 1025 } | 1039 } |
| 1026 } | 1040 } |
| 1027 | 1041 |
| 1028 } // namespace | 1042 } // namespace |
| 1029 | 1043 |
| 1030 } // namespace net | 1044 } // namespace net |
| OLD | NEW |