| 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/proxy/multi_threaded_proxy_resolver.h" | 5 #include "net/proxy/multi_threaded_proxy_resolver.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 namespace net { | 32 namespace net { |
| 33 | 33 |
| 34 namespace { | 34 namespace { |
| 35 | 35 |
| 36 // A synchronous mock ProxyResolver implementation, which can be used in | 36 // A synchronous mock ProxyResolver implementation, which can be used in |
| 37 // conjunction with MultiThreadedProxyResolver. | 37 // conjunction with MultiThreadedProxyResolver. |
| 38 // - returns a single-item proxy list with the query's host. | 38 // - returns a single-item proxy list with the query's host. |
| 39 class MockProxyResolver : public ProxyResolver { | 39 class MockProxyResolver : public ProxyResolver { |
| 40 public: | 40 public: |
| 41 MockProxyResolver() | 41 MockProxyResolver() |
| 42 : ProxyResolver(true /*expects_pac_bytes*/), | 42 : worker_loop_(base::MessageLoop::current()), request_count_(0) {} |
| 43 worker_loop_(base::MessageLoop::current()), | |
| 44 request_count_(0) {} | |
| 45 | 43 |
| 46 // ProxyResolver implementation. | 44 // ProxyResolver implementation. |
| 47 int GetProxyForURL(const GURL& query_url, | 45 int GetProxyForURL(const GURL& query_url, |
| 48 ProxyInfo* results, | 46 ProxyInfo* results, |
| 49 const CompletionCallback& callback, | 47 const CompletionCallback& callback, |
| 50 RequestHandle* request, | 48 RequestHandle* request, |
| 51 const BoundNetLog& net_log) override { | 49 const BoundNetLog& net_log) override { |
| 52 if (resolve_latency_ != base::TimeDelta()) | 50 if (resolve_latency_ != base::TimeDelta()) |
| 53 base::PlatformThread::Sleep(resolve_latency_); | 51 base::PlatformThread::Sleep(resolve_latency_); |
| 54 | 52 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 66 return request_count_++; | 64 return request_count_++; |
| 67 } | 65 } |
| 68 | 66 |
| 69 void CancelRequest(RequestHandle request) override { NOTREACHED(); } | 67 void CancelRequest(RequestHandle request) override { NOTREACHED(); } |
| 70 | 68 |
| 71 LoadState GetLoadState(RequestHandle request) const override { | 69 LoadState GetLoadState(RequestHandle request) const override { |
| 72 NOTREACHED(); | 70 NOTREACHED(); |
| 73 return LOAD_STATE_IDLE; | 71 return LOAD_STATE_IDLE; |
| 74 } | 72 } |
| 75 | 73 |
| 76 void CancelSetPacScript() override { NOTREACHED(); } | |
| 77 int SetPacScript(const scoped_refptr<ProxyResolverScriptData>& script_data, | |
| 78 const CompletionCallback& callback) override { | |
| 79 NOTREACHED(); | |
| 80 return ERR_NOT_IMPLEMENTED; | |
| 81 } | |
| 82 | |
| 83 int request_count() const { return request_count_; } | 74 int request_count() const { return request_count_; } |
| 84 | 75 |
| 85 void SetResolveLatency(base::TimeDelta latency) { | 76 void SetResolveLatency(base::TimeDelta latency) { |
| 86 resolve_latency_ = latency; | 77 resolve_latency_ = latency; |
| 87 } | 78 } |
| 88 | 79 |
| 89 private: | 80 private: |
| 90 void CheckIsOnWorkerThread() { | 81 void CheckIsOnWorkerThread() { |
| 91 EXPECT_EQ(base::MessageLoop::current(), worker_loop_); | 82 EXPECT_EQ(base::MessageLoop::current(), worker_loop_); |
| 92 } | 83 } |
| (...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 780 } | 771 } |
| 781 // The factory destructor will block until the worker thread stops, but it may | 772 // The factory destructor will block until the worker thread stops, but it may |
| 782 // post tasks to the origin message loop which are still pending. Run them | 773 // post tasks to the origin message loop which are still pending. Run them |
| 783 // now to ensure it works as expected. | 774 // now to ensure it works as expected. |
| 784 base::RunLoop().RunUntilIdle(); | 775 base::RunLoop().RunUntilIdle(); |
| 785 } | 776 } |
| 786 | 777 |
| 787 } // namespace | 778 } // namespace |
| 788 | 779 |
| 789 } // namespace net | 780 } // namespace net |
| OLD | NEW |