1 // Copyright 2015 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef NET_PROXY_RESOLUTION_PROXY_RESOLVER_FACTORY_H_ 6 #define NET_PROXY_RESOLUTION_PROXY_RESOLVER_FACTORY_H_ 7 8 #include <memory> 9 #include <set> 10 11 #include "base/memory/scoped_refptr.h" 12 #include "net/base/completion_once_callback.h" 13 #include "net/base/net_export.h" 14 #include "net/proxy_resolution/pac_file_data.h" 15 16 namespace net { 17 18 class ProxyResolver; 19 20 // ProxyResolverFactory is an interface for creating ProxyResolver instances. 21 class NET_EXPORT ProxyResolverFactory { 22 public: 23 // A handle to a request. Deleting it will cancel the request. 24 class Request { 25 public: 26 virtual ~Request() = default; 27 }; 28 29 // See |expects_pac_bytes()| for the meaning of |expects_pac_bytes|. 30 explicit ProxyResolverFactory(bool expects_pac_bytes); 31 32 ProxyResolverFactory(const ProxyResolverFactory&) = delete; 33 ProxyResolverFactory& operator=(const ProxyResolverFactory&) = delete; 34 35 virtual ~ProxyResolverFactory(); 36 37 // Creates a new ProxyResolver. If the request will complete asynchronously, 38 // it returns ERR_IO_PENDING and notifies the result by running |callback|. 39 // If the result is OK, then |resolver| contains the ProxyResolver. In the 40 // case of asynchronous completion |*request| is written to, and can be 41 // deleted to cancel the request. All requests in progress are cancelled if 42 // the ProxyResolverFactory is deleted. 43 virtual int CreateProxyResolver(const scoped_refptr<PacFileData>& pac_script, 44 std::unique_ptr<ProxyResolver>* resolver, 45 CompletionOnceCallback callback, 46 std::unique_ptr<Request>* request) = 0; 47 48 // The PAC script backend can be specified to the ProxyResolverFactory either 49 // via URL, or via the javascript text itself. If |expects_pac_bytes| is true, 50 // then the PacFileData passed to CreateProxyResolver() should 51 // contain the actual script bytes rather than just the URL. expects_pac_bytes()52 bool expects_pac_bytes() const { return expects_pac_bytes_; } 53 54 private: 55 bool expects_pac_bytes_; 56 }; 57 58 } // namespace net 59 60 #endif // NET_PROXY_RESOLUTION_PROXY_RESOLVER_FACTORY_H_ 61