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