Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(369)

Unified Diff: net/proxy/mock_proxy_resolver.h

Issue 1102463002: Add a MockAsyncProxyResolverFactory and update some tests to use it. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@proxy-factory-refactor
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: net/proxy/mock_proxy_resolver.h
diff --git a/net/proxy/mock_proxy_resolver.h b/net/proxy/mock_proxy_resolver.h
index 024a08370f7ccd1a091c535513959e8c46d7a2ab..5630ad7c2a74222fc25e4d9e077375b9648e2818 100644
--- a/net/proxy/mock_proxy_resolver.h
+++ b/net/proxy/mock_proxy_resolver.h
@@ -124,18 +124,79 @@ class MockAsyncProxyResolverExpectsBytes : public MockAsyncProxyResolverBase {
: MockAsyncProxyResolverBase(true /*expects_pac_bytes*/) {}
};
-// This factory returns ProxyResolvers that forward all requests to
-// |resolver|. |resolver| must remain so long as any value returned from
-// CreateProxyResolver remains in use.
-class ForwardingProxyResolverFactory : public LegacyProxyResolverFactory {
+// Asynchronous mock proxy resolver factory . All requests complete
+// asynchronously; the user must call Request::CompleteNow() on a pending
+// request to signal it.
+class MockAsyncProxyResolverFactory : public ProxyResolverFactory {
public:
- explicit ForwardingProxyResolverFactory(ProxyResolver* resolver);
+ class Request : public base::RefCounted<Request> {
+ public:
+ Request(MockAsyncProxyResolverFactory* factory,
+ const scoped_refptr<ProxyResolverScriptData>& script_data,
+ scoped_ptr<ProxyResolver>* resolver,
+ const net::CompletionCallback& callback);
+
+ 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.
+ return script_data_.get();
+ }
+
+ // Completes this request. A ForwardingProxyResolver that forwards to
+ // |resolver| will be returned to the requester. |resolver| must not be
+ // null and must remain as long as the resolver returned by this request
+ // remains in use.
+ void CompleteNowWithForwarder(int rv, ProxyResolver* resolver);
+
+ void CompleteNow(int rv, scoped_ptr<ProxyResolver> resolver);
+
+ private:
+ friend class base::RefCounted<Request>;
+
+ ~Request();
+
+ MockAsyncProxyResolverFactory* factory_;
+ const scoped_refptr<ProxyResolverScriptData> script_data_;
+ scoped_ptr<ProxyResolver>* resolver_;
+ net::CompletionCallback callback_;
+ };
+
+ using RequestsList = std::vector<scoped_refptr<Request>>;
+
+ explicit MockAsyncProxyResolverFactory(bool resolvers_expect_pac_bytes);
+ ~MockAsyncProxyResolverFactory() override;
+
+ int CreateProxyResolver(
+ const scoped_refptr<ProxyResolverScriptData>& pac_script,
+ scoped_ptr<ProxyResolver>* resolver,
+ const net::CompletionCallback& callback,
+ scoped_ptr<ProxyResolverFactory::Request>* request) override;
+
+ const RequestsList& pending_requests() const { return pending_requests_; }
+
+ const RequestsList& cancelled_requests() const { return cancelled_requests_; }
+
+ void RemovePendingRequest(Request* request);
+
+ private:
+ class Job;
+ RequestsList pending_requests_;
+ RequestsList cancelled_requests_;
+};
+
+// This factory forwards all calls to |impl|. |impl| must remain so long as this
+// remains in use.
+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.
+ public:
+ explicit ForwardingProxyResolverFactory(ProxyResolverFactory* impl);
- // LegacyProxyResolverFactory override.
- scoped_ptr<ProxyResolver> CreateProxyResolver() override;
+ // ProxyResolverFactory override.
+ int CreateProxyResolver(
+ const scoped_refptr<ProxyResolverScriptData>& pac_script,
+ scoped_ptr<ProxyResolver>* resolver,
+ const net::CompletionCallback& callback,
+ scoped_ptr<Request>* request) override;
private:
- ProxyResolver* resolver_;
+ ProxyResolverFactory* impl_;
DISALLOW_COPY_AND_ASSIGN(ForwardingProxyResolverFactory);
};

Powered by Google App Engine
This is Rietveld 408576698