Chromium Code Reviews| 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_wrapper.h" | 5 #include "net/proxy/proxy_resolver_v8_tracing_wrapper.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 753 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 764 // has been received. The resolve requests it receives will never be completed. | 764 // has been received. The resolve requests it receives will never be completed. |
| 765 class BlockableHostResolver : public HostResolver { | 765 class BlockableHostResolver : public HostResolver { |
| 766 public: | 766 public: |
| 767 BlockableHostResolver() | 767 BlockableHostResolver() |
| 768 : num_cancelled_requests_(0), waiting_for_resolve_(false) {} | 768 : num_cancelled_requests_(0), waiting_for_resolve_(false) {} |
| 769 | 769 |
| 770 int Resolve(const RequestInfo& info, | 770 int Resolve(const RequestInfo& info, |
| 771 RequestPriority priority, | 771 RequestPriority priority, |
| 772 AddressList* addresses, | 772 AddressList* addresses, |
| 773 const CompletionCallback& callback, | 773 const CompletionCallback& callback, |
| 774 RequestHandle* out_req, | 774 std::unique_ptr<Request>* out_req, |
| 775 const BoundNetLog& net_log) override { | 775 const BoundNetLog& net_log) override { |
| 776 EXPECT_FALSE(callback.is_null()); | 776 EXPECT_FALSE(callback.is_null()); |
| 777 EXPECT_TRUE(out_req); | 777 EXPECT_TRUE(out_req); |
| 778 | 778 |
| 779 if (!action_.is_null()) | 779 if (!action_.is_null()) |
| 780 action_.Run(); | 780 action_.Run(); |
| 781 | 781 |
| 782 // Indicate to the caller that a request was received. | 782 // Indicate to the caller that a request was received. |
| 783 EXPECT_TRUE(waiting_for_resolve_); | 783 EXPECT_TRUE(waiting_for_resolve_); |
| 784 base::MessageLoop::current()->QuitWhenIdle(); | 784 base::MessageLoop::current()->QuitWhenIdle(); |
| 785 | 785 |
| 786 // This line is intentionally after action_.Run(), since one of the | 786 // This line is intentionally after action_.Run(), since one of the |
| 787 // tests does a cancellation inside of Resolve(), and it is more | 787 // tests does a cancellation inside of Resolve(), and it is more |
| 788 // interesting if *out_req hasn't been written yet at that point. | 788 // interesting if *out_req hasn't been written yet at that point. |
| 789 *out_req = reinterpret_cast<RequestHandle*>(1); // Magic value. | 789 (*out_req).reset(new RequestImpl(this)); |
|
mmenke
2016/07/19 19:03:56
out_req->reset
| |
| 790 | 790 |
| 791 // Return ERR_IO_PENDING as this request will NEVER be completed. | 791 // Return ERR_IO_PENDING as this request will NEVER be completed. |
| 792 // Expectation is for the caller to later cancel the request. | 792 // Expectation is for the caller to later cancel the request. |
| 793 return ERR_IO_PENDING; | 793 return ERR_IO_PENDING; |
| 794 } | 794 } |
| 795 | 795 |
| 796 int ResolveFromCache(const RequestInfo& info, | 796 int ResolveFromCache(const RequestInfo& info, |
| 797 AddressList* addresses, | 797 AddressList* addresses, |
| 798 const BoundNetLog& net_log) override { | 798 const BoundNetLog& net_log) override { |
| 799 NOTREACHED(); | 799 NOTREACHED(); |
| 800 return ERR_DNS_CACHE_MISS; | 800 return ERR_DNS_CACHE_MISS; |
| 801 } | 801 } |
| 802 | 802 |
| 803 void CancelRequest(RequestHandle req) override { | 803 void IncreaseNumOfCancelledRequests() { num_cancelled_requests_++; } |
| 804 EXPECT_EQ(reinterpret_cast<RequestHandle*>(1), req); | |
| 805 num_cancelled_requests_++; | |
| 806 } | |
| 807 | 804 |
| 808 void SetAction(const base::Callback<void(void)>& action) { action_ = action; } | 805 void SetAction(const base::Callback<void(void)>& action) { action_ = action; } |
| 809 | 806 |
| 810 // Waits until Resolve() has been called. | 807 // Waits until Resolve() has been called. |
| 811 void WaitUntilRequestIsReceived() { | 808 void WaitUntilRequestIsReceived() { |
| 812 waiting_for_resolve_ = true; | 809 waiting_for_resolve_ = true; |
| 813 base::RunLoop().Run(); | 810 base::RunLoop().Run(); |
| 814 DCHECK(waiting_for_resolve_); | 811 DCHECK(waiting_for_resolve_); |
| 815 waiting_for_resolve_ = false; | 812 waiting_for_resolve_ = false; |
| 816 } | 813 } |
| 817 | 814 |
| 818 int num_cancelled_requests() const { return num_cancelled_requests_; } | 815 int num_cancelled_requests() const { return num_cancelled_requests_; } |
| 819 | 816 |
| 820 private: | 817 private: |
| 818 class RequestImpl : public HostResolver::Request { | |
| 819 public: | |
| 820 RequestImpl(BlockableHostResolver* resolver) : resolver_(resolver) {} | |
| 821 | |
| 822 ~RequestImpl() override { | |
| 823 if (resolver_) | |
| 824 resolver_->IncreaseNumOfCancelledRequests(); | |
| 825 } | |
| 826 | |
| 827 void ChangeRequestPriority(RequestPriority priority) override {} | |
| 828 | |
| 829 private: | |
| 830 BlockableHostResolver* resolver_; | |
| 831 | |
| 832 DISALLOW_COPY_AND_ASSIGN(RequestImpl); | |
| 833 }; | |
| 834 | |
| 821 int num_cancelled_requests_; | 835 int num_cancelled_requests_; |
| 822 bool waiting_for_resolve_; | 836 bool waiting_for_resolve_; |
| 823 base::Callback<void(void)> action_; | 837 base::Callback<void(void)> action_; |
| 824 }; | 838 }; |
| 825 | 839 |
| 826 // This cancellation test exercises a more predictable cancellation codepath -- | 840 // This cancellation test exercises a more predictable cancellation codepath -- |
| 827 // when the request has an outstanding DNS request in flight. | 841 // when the request has an outstanding DNS request in flight. |
| 828 TEST_F(ProxyResolverV8TracingWrapperTest, | 842 TEST_F(ProxyResolverV8TracingWrapperTest, |
| 829 CancelWhileOutstandingNonBlockingDns) { | 843 CancelWhileOutstandingNonBlockingDns) { |
| 830 BlockableHostResolver host_resolver; | 844 BlockableHostResolver host_resolver; |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1132 proxy_uri.substr(0, proxy_uri.find(':') + 1)); | 1146 proxy_uri.substr(0, proxy_uri.find(':') + 1)); |
| 1133 } else { | 1147 } else { |
| 1134 NOTREACHED(); | 1148 NOTREACHED(); |
| 1135 } | 1149 } |
| 1136 } | 1150 } |
| 1137 } | 1151 } |
| 1138 | 1152 |
| 1139 } // namespace | 1153 } // namespace |
| 1140 | 1154 |
| 1141 } // namespace net | 1155 } // namespace net |
| OLD | NEW |