Chromium Code Reviews| 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 : public base::RefCounted<Request> { |
| 133 public: | |
| 134 Request(MockAsyncProxyResolverFactory* factory, | |
| 135 const scoped_refptr<ProxyResolverScriptData>& script_data, | |
| 136 scoped_ptr<ProxyResolver>* resolver, | |
| 137 const net::CompletionCallback& callback); | |
| 133 | 138 |
| 134 // LegacyProxyResolverFactory override. | 139 const ProxyResolverScriptData* script_data() const { |
|
eroman
2015/04/22 16:30:38
can you return a "const scoped_refptr<ProxyResolve
Sam McNally
2015/04/23 03:04:43
Done.
| |
| 135 scoped_ptr<ProxyResolver> CreateProxyResolver() override; | 140 return script_data_.get(); |
| 141 } | |
| 142 | |
| 143 // Completes this request. A ForwardingProxyResolver that forwards to | |
| 144 // |resolver| will be returned to the requester. |resolver| must not be | |
| 145 // null and must remain as long as the resolver returned by this request | |
| 146 // remains in use. | |
| 147 void CompleteNowWithForwarder(int rv, ProxyResolver* resolver); | |
| 148 | |
| 149 void CompleteNow(int rv, scoped_ptr<ProxyResolver> resolver); | |
| 150 | |
| 151 private: | |
| 152 friend class base::RefCounted<Request>; | |
| 153 | |
| 154 ~Request(); | |
| 155 | |
| 156 MockAsyncProxyResolverFactory* factory_; | |
| 157 const scoped_refptr<ProxyResolverScriptData> script_data_; | |
| 158 scoped_ptr<ProxyResolver>* resolver_; | |
| 159 net::CompletionCallback callback_; | |
| 160 }; | |
| 161 | |
| 162 using RequestsList = std::vector<scoped_refptr<Request>>; | |
| 163 | |
| 164 explicit MockAsyncProxyResolverFactory(bool resolvers_expect_pac_bytes); | |
| 165 ~MockAsyncProxyResolverFactory() override; | |
| 166 | |
| 167 int CreateProxyResolver( | |
| 168 const scoped_refptr<ProxyResolverScriptData>& pac_script, | |
| 169 scoped_ptr<ProxyResolver>* resolver, | |
| 170 const net::CompletionCallback& callback, | |
| 171 scoped_ptr<ProxyResolverFactory::Request>* request) override; | |
| 172 | |
| 173 const RequestsList& pending_requests() const { return pending_requests_; } | |
| 174 | |
| 175 const RequestsList& cancelled_requests() const { return cancelled_requests_; } | |
| 176 | |
| 177 void RemovePendingRequest(Request* request); | |
| 136 | 178 |
| 137 private: | 179 private: |
| 138 ProxyResolver* resolver_; | 180 class Job; |
| 181 RequestsList pending_requests_; | |
| 182 RequestsList cancelled_requests_; | |
| 183 }; | |
| 184 | |
| 185 // This factory forwards all calls to |impl|. |impl| must remain so long as this | |
| 186 // remains in use. | |
| 187 class ForwardingProxyResolverFactory : public ProxyResolverFactory { | |
|
eroman
2015/04/22 16:30:38
Let's delete this. I don't think there is much val
Sam McNally
2015/04/23 03:04:43
Done.
| |
| 188 public: | |
| 189 explicit ForwardingProxyResolverFactory(ProxyResolverFactory* impl); | |
| 190 | |
| 191 // ProxyResolverFactory override. | |
| 192 int CreateProxyResolver( | |
| 193 const scoped_refptr<ProxyResolverScriptData>& pac_script, | |
| 194 scoped_ptr<ProxyResolver>* resolver, | |
| 195 const net::CompletionCallback& callback, | |
| 196 scoped_ptr<Request>* request) override; | |
| 197 | |
| 198 private: | |
| 199 ProxyResolverFactory* impl_; | |
| 139 | 200 |
| 140 DISALLOW_COPY_AND_ASSIGN(ForwardingProxyResolverFactory); | 201 DISALLOW_COPY_AND_ASSIGN(ForwardingProxyResolverFactory); |
| 141 }; | 202 }; |
| 142 | 203 |
| 143 // ForwardingProxyResolver forwards all requests to |impl|. |impl| must remain | 204 // ForwardingProxyResolver forwards all requests to |impl|. |impl| must remain |
| 144 // so long as this remains in use. | 205 // so long as this remains in use. |
| 145 class ForwardingProxyResolver : public ProxyResolver { | 206 class ForwardingProxyResolver : public ProxyResolver { |
| 146 public: | 207 public: |
| 147 explicit ForwardingProxyResolver(ProxyResolver* impl); | 208 explicit ForwardingProxyResolver(ProxyResolver* impl); |
| 148 | 209 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 160 | 221 |
| 161 private: | 222 private: |
| 162 ProxyResolver* impl_; | 223 ProxyResolver* impl_; |
| 163 | 224 |
| 164 DISALLOW_COPY_AND_ASSIGN(ForwardingProxyResolver); | 225 DISALLOW_COPY_AND_ASSIGN(ForwardingProxyResolver); |
| 165 }; | 226 }; |
| 166 | 227 |
| 167 } // namespace net | 228 } // namespace net |
| 168 | 229 |
| 169 #endif // NET_PROXY_MOCK_PROXY_RESOLVER_H_ | 230 #endif // NET_PROXY_MOCK_PROXY_RESOLVER_H_ |
| OLD | NEW |