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/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 MockAsyncProxyResolver() | 117 MockAsyncProxyResolver() |
118 : MockAsyncProxyResolverBase(false /*expects_pac_bytes*/) {} | 118 : MockAsyncProxyResolverBase(false /*expects_pac_bytes*/) {} |
119 }; | 119 }; |
120 | 120 |
121 class MockAsyncProxyResolverExpectsBytes : public MockAsyncProxyResolverBase { | 121 class MockAsyncProxyResolverExpectsBytes : public MockAsyncProxyResolverBase { |
122 public: | 122 public: |
123 MockAsyncProxyResolverExpectsBytes() | 123 MockAsyncProxyResolverExpectsBytes() |
124 : MockAsyncProxyResolverBase(true /*expects_pac_bytes*/) {} | 124 : MockAsyncProxyResolverBase(true /*expects_pac_bytes*/) {} |
125 }; | 125 }; |
126 | 126 |
127 // This factory returns ProxyResolvers that forward all requests to | 127 // Asynchronous mock proxy resolver factory . All requests complete |
128 // |resolver|. |resolver| must remain so long as any value returned from | 128 // asynchronously; the user must call Request::CompleteNow() on a pending |
129 // CreateProxyResolver remains in use. | 129 // request to signal it. |
130 class ForwardingProxyResolverFactory : public LegacyProxyResolverFactory { | 130 class MockAsyncProxyResolverFactory : public ProxyResolverFactory { |
131 public: | 131 public: |
132 explicit ForwardingProxyResolverFactory(ProxyResolver* resolver); | 132 class Request; |
| 133 using RequestsList = std::vector<scoped_refptr<Request>>; |
133 | 134 |
134 // LegacyProxyResolverFactory override. | 135 explicit MockAsyncProxyResolverFactory(bool resolvers_expect_pac_bytes); |
135 scoped_ptr<ProxyResolver> CreateProxyResolver() override; | 136 ~MockAsyncProxyResolverFactory() override; |
| 137 |
| 138 int CreateProxyResolver( |
| 139 const scoped_refptr<ProxyResolverScriptData>& pac_script, |
| 140 scoped_ptr<ProxyResolver>* resolver, |
| 141 const CompletionCallback& callback, |
| 142 scoped_ptr<ProxyResolverFactory::Request>* request) override; |
| 143 |
| 144 const RequestsList& pending_requests() const { return pending_requests_; } |
| 145 |
| 146 const RequestsList& cancelled_requests() const { return cancelled_requests_; } |
| 147 |
| 148 void RemovePendingRequest(Request* request); |
136 | 149 |
137 private: | 150 private: |
138 ProxyResolver* resolver_; | 151 class Job; |
| 152 RequestsList pending_requests_; |
| 153 RequestsList cancelled_requests_; |
| 154 }; |
139 | 155 |
140 DISALLOW_COPY_AND_ASSIGN(ForwardingProxyResolverFactory); | 156 class MockAsyncProxyResolverFactory::Request |
| 157 : public base::RefCounted<Request> { |
| 158 public: |
| 159 Request(MockAsyncProxyResolverFactory* factory, |
| 160 const scoped_refptr<ProxyResolverScriptData>& script_data, |
| 161 scoped_ptr<ProxyResolver>* resolver, |
| 162 const CompletionCallback& callback); |
| 163 |
| 164 const scoped_refptr<ProxyResolverScriptData>& script_data() const { |
| 165 return script_data_; |
| 166 } |
| 167 |
| 168 // Completes this request. A ForwardingProxyResolver that forwards to |
| 169 // |resolver| will be returned to the requester. |resolver| must not be |
| 170 // null and must remain as long as the resolver returned by this request |
| 171 // remains in use. |
| 172 void CompleteNowWithForwarder(int rv, ProxyResolver* resolver); |
| 173 |
| 174 void CompleteNow(int rv, scoped_ptr<ProxyResolver> resolver); |
| 175 |
| 176 private: |
| 177 friend class base::RefCounted<Request>; |
| 178 friend class MockAsyncProxyResolverFactory; |
| 179 friend class MockAsyncProxyResolverFactory::Job; |
| 180 |
| 181 ~Request(); |
| 182 |
| 183 void FactoryDestroyed(); |
| 184 |
| 185 MockAsyncProxyResolverFactory* factory_; |
| 186 const scoped_refptr<ProxyResolverScriptData> script_data_; |
| 187 scoped_ptr<ProxyResolver>* resolver_; |
| 188 CompletionCallback callback_; |
141 }; | 189 }; |
142 | 190 |
143 // ForwardingProxyResolver forwards all requests to |impl|. |impl| must remain | 191 // ForwardingProxyResolver forwards all requests to |impl|. |impl| must remain |
144 // so long as this remains in use. | 192 // so long as this remains in use. |
145 class ForwardingProxyResolver : public ProxyResolver { | 193 class ForwardingProxyResolver : public ProxyResolver { |
146 public: | 194 public: |
147 explicit ForwardingProxyResolver(ProxyResolver* impl); | 195 explicit ForwardingProxyResolver(ProxyResolver* impl); |
148 | 196 |
149 // ProxyResolver overrides. | 197 // ProxyResolver overrides. |
150 int GetProxyForURL(const GURL& query_url, | 198 int GetProxyForURL(const GURL& query_url, |
151 ProxyInfo* results, | 199 ProxyInfo* results, |
152 const CompletionCallback& callback, | 200 const CompletionCallback& callback, |
153 RequestHandle* request, | 201 RequestHandle* request, |
154 const BoundNetLog& net_log) override; | 202 const BoundNetLog& net_log) override; |
155 void CancelRequest(RequestHandle request) override; | 203 void CancelRequest(RequestHandle request) override; |
156 LoadState GetLoadState(RequestHandle request) const override; | 204 LoadState GetLoadState(RequestHandle request) const override; |
157 void CancelSetPacScript() override; | 205 void CancelSetPacScript() override; |
158 int SetPacScript(const scoped_refptr<ProxyResolverScriptData>& script_data, | 206 int SetPacScript(const scoped_refptr<ProxyResolverScriptData>& script_data, |
159 const CompletionCallback& callback) override; | 207 const CompletionCallback& callback) override; |
160 | 208 |
161 private: | 209 private: |
162 ProxyResolver* impl_; | 210 ProxyResolver* impl_; |
163 | 211 |
164 DISALLOW_COPY_AND_ASSIGN(ForwardingProxyResolver); | 212 DISALLOW_COPY_AND_ASSIGN(ForwardingProxyResolver); |
165 }; | 213 }; |
166 | 214 |
167 } // namespace net | 215 } // namespace net |
168 | 216 |
169 #endif // NET_PROXY_MOCK_PROXY_RESOLVER_H_ | 217 #endif // NET_PROXY_MOCK_PROXY_RESOLVER_H_ |
OLD | NEW |