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 #ifndef NET_PROXY_MOCK_PROXY_RESOLVER_H_ | 5 #ifndef NET_PROXY_MOCK_PROXY_RESOLVER_H_ |
6 #define NET_PROXY_MOCK_PROXY_RESOLVER_H_ | 6 #define NET_PROXY_MOCK_PROXY_RESOLVER_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "net/base/net_errors.h" | 12 #include "net/base/net_errors.h" |
13 #include "net/proxy/proxy_resolver.h" | 13 #include "net/proxy/proxy_resolver.h" |
14 #include "net/proxy/proxy_resolver_factory.h" | 14 #include "net/proxy/proxy_resolver_factory.h" |
15 #include "url/gurl.h" | 15 #include "url/gurl.h" |
16 | 16 |
17 namespace base { | 17 namespace base { |
18 class MessageLoop; | 18 class MessageLoop; |
19 } | 19 } |
20 | 20 |
21 namespace net { | 21 namespace net { |
22 | 22 |
23 // Asynchronous mock proxy resolver. All requests complete asynchronously, | 23 // Asynchronous mock proxy resolver. All requests complete asynchronously, |
24 // user must call Request::CompleteNow() on a pending request to signal it. | 24 // user must call Job::CompleteNow() on a pending request to signal it. |
25 class MockAsyncProxyResolver : public ProxyResolver { | 25 class MockAsyncProxyResolver : public ProxyResolver { |
26 public: | 26 public: |
27 class Request : public base::RefCounted<Request> { | 27 class Job : public base::RefCounted<Job> { |
eroman
2016/02/25 17:53:44
Based on our understanding of the failure, this ca
| |
28 public: | 28 public: |
29 Request(MockAsyncProxyResolver* resolver, | 29 Job(MockAsyncProxyResolver* resolver, |
30 const GURL& url, | 30 const GURL& url, |
31 ProxyInfo* results, | 31 ProxyInfo* results, |
32 const CompletionCallback& callback); | 32 const CompletionCallback& callback); |
33 | 33 |
34 const GURL& url() const { return url_; } | 34 const GURL& url() const { return url_; } |
35 ProxyInfo* results() const { return results_; } | 35 ProxyInfo* results() const { return results_; } |
36 const CompletionCallback& callback() const { return callback_; } | 36 const CompletionCallback& callback() const { return callback_; } |
37 MockAsyncProxyResolver* Resolver() const { return resolver_; }; | |
37 | 38 |
38 void CompleteNow(int rv); | 39 void CompleteNow(int rv); |
39 | 40 |
40 private: | 41 private: |
41 friend class base::RefCounted<Request>; | 42 virtual ~Job(); |
eroman
2016/02/25 17:53:44
No need for this to be virtual.
| |
42 | 43 friend class base::RefCounted<Job>; |
43 virtual ~Request(); | |
44 | 44 |
45 MockAsyncProxyResolver* resolver_; | 45 MockAsyncProxyResolver* resolver_; |
46 const GURL url_; | 46 const GURL url_; |
47 ProxyInfo* results_; | 47 ProxyInfo* results_; |
48 CompletionCallback callback_; | 48 CompletionCallback callback_; |
49 base::MessageLoop* origin_loop_; | 49 base::MessageLoop* origin_loop_; |
50 }; | 50 }; |
51 | 51 |
52 typedef std::vector<scoped_refptr<Request> > RequestsList; | 52 class RequestImpl : public ProxyResolver::Request { |
53 public: | |
54 explicit RequestImpl(scoped_refptr<Job> job); | |
55 | |
56 ~RequestImpl() override; | |
57 | |
58 LoadState GetLoadState() override; | |
59 | |
60 private: | |
61 // TODO This should be scoped_ptr but windows compiler have some bug. | |
eroman
2016/02/25 17:53:44
Remove this comment.
The problem as described in
| |
62 // Probably this: https://support.microsoft.com/en-us/kb/121216 | |
63 // Error was `scalar deleting destructor' | |
64 scoped_refptr<Job> job_; | |
65 }; | |
53 | 66 |
54 MockAsyncProxyResolver(); | 67 MockAsyncProxyResolver(); |
55 ~MockAsyncProxyResolver() override; | 68 ~MockAsyncProxyResolver() override; |
56 | 69 |
57 // ProxyResolver implementation. | 70 // ProxyResolver implementation. |
58 int GetProxyForURL(const GURL& url, | 71 int GetProxyForURL(const GURL& url, |
59 ProxyInfo* results, | 72 ProxyInfo* results, |
60 const CompletionCallback& callback, | 73 const CompletionCallback& callback, |
61 RequestHandle* request_handle, | 74 scoped_ptr<Request>* request, |
62 const BoundNetLog& /*net_log*/) override; | 75 const BoundNetLog& /*net_log*/) override; |
63 void CancelRequest(RequestHandle request_handle) override; | 76 const std::vector<Job*>& pending_jobs() const { return pending_jobs_; } |
64 LoadState GetLoadState(RequestHandle request_handle) const override; | 77 |
65 const RequestsList& pending_requests() const { | 78 const std::vector<scoped_refptr<Job>>& cancelled_jobs() const { |
66 return pending_requests_; | 79 return cancelled_jobs_; |
67 } | 80 } |
68 | 81 |
69 const RequestsList& cancelled_requests() const { | 82 void AddCancelledJob(scoped_refptr<Job> job); |
70 return cancelled_requests_; | 83 void RemovePendingJob(Job* job); |
71 } | |
72 | |
73 void RemovePendingRequest(Request* request); | |
74 | 84 |
75 private: | 85 private: |
76 RequestsList pending_requests_; | 86 std::vector<Job*> pending_jobs_; |
77 RequestsList cancelled_requests_; | 87 std::vector<scoped_refptr<Job>> cancelled_jobs_; |
78 }; | 88 }; |
79 | 89 |
80 // Asynchronous mock proxy resolver factory . All requests complete | 90 // Asynchronous mock proxy resolver factory . All requests complete |
81 // asynchronously; the user must call Request::CompleteNow() on a pending | 91 // asynchronously; the user must call Request::CompleteNow() on a pending |
82 // request to signal it. | 92 // request to signal it. |
83 class MockAsyncProxyResolverFactory : public ProxyResolverFactory { | 93 class MockAsyncProxyResolverFactory : public ProxyResolverFactory { |
84 public: | 94 public: |
85 class Request; | 95 class Request; |
86 using RequestsList = std::vector<scoped_refptr<Request>>; | 96 using RequestsList = std::vector<scoped_refptr<Request>>; |
87 | 97 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
144 // ForwardingProxyResolver forwards all requests to |impl|. |impl| must remain | 154 // ForwardingProxyResolver forwards all requests to |impl|. |impl| must remain |
145 // so long as this remains in use. | 155 // so long as this remains in use. |
146 class ForwardingProxyResolver : public ProxyResolver { | 156 class ForwardingProxyResolver : public ProxyResolver { |
147 public: | 157 public: |
148 explicit ForwardingProxyResolver(ProxyResolver* impl); | 158 explicit ForwardingProxyResolver(ProxyResolver* impl); |
149 | 159 |
150 // ProxyResolver overrides. | 160 // ProxyResolver overrides. |
151 int GetProxyForURL(const GURL& query_url, | 161 int GetProxyForURL(const GURL& query_url, |
152 ProxyInfo* results, | 162 ProxyInfo* results, |
153 const CompletionCallback& callback, | 163 const CompletionCallback& callback, |
154 RequestHandle* request, | 164 scoped_ptr<Request>* request, |
155 const BoundNetLog& net_log) override; | 165 const BoundNetLog& net_log) override; |
156 void CancelRequest(RequestHandle request) override; | |
157 LoadState GetLoadState(RequestHandle request) const override; | |
158 | 166 |
159 private: | 167 private: |
160 ProxyResolver* impl_; | 168 ProxyResolver* impl_; |
161 | 169 |
162 DISALLOW_COPY_AND_ASSIGN(ForwardingProxyResolver); | 170 DISALLOW_COPY_AND_ASSIGN(ForwardingProxyResolver); |
163 }; | 171 }; |
164 | 172 |
165 } // namespace net | 173 } // namespace net |
166 | 174 |
167 #endif // NET_PROXY_MOCK_PROXY_RESOLVER_H_ | 175 #endif // NET_PROXY_MOCK_PROXY_RESOLVER_H_ |
OLD | NEW |