1 // Copyright (c) 2011 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_PROXY_RESOLVER_H_ 6 #define NET_PROXY_PROXY_RESOLVER_H_ 7 8 #include "base/logging.h" 9 #include "base/memory/ref_counted.h" 10 #include "base/strings/string16.h" 11 #include "net/base/completion_callback.h" 12 #include "net/base/load_states.h" 13 #include "net/base/net_export.h" 14 #include "net/proxy/proxy_resolver_script_data.h" 15 #include "url/gurl.h" 16 17 namespace net { 18 19 class BoundNetLog; 20 class ProxyInfo; 21 22 // Interface for "proxy resolvers". A ProxyResolver fills in a list of proxies 23 // to use for a particular URL. Generally the backend for a ProxyResolver is 24 // a PAC script, but it doesn't need to be. ProxyResolver can service multiple 25 // requests at a time. 26 class NET_EXPORT_PRIVATE ProxyResolver { 27 public: 28 // Opaque pointer type, to return a handle to cancel outstanding requests. 29 typedef void* RequestHandle; 30 31 // See |expects_pac_bytes()| for the meaning of |expects_pac_bytes|. ProxyResolver(bool expects_pac_bytes)32 explicit ProxyResolver(bool expects_pac_bytes) 33 : expects_pac_bytes_(expects_pac_bytes) {} 34 ~ProxyResolver()35 virtual ~ProxyResolver() {} 36 37 // Gets a list of proxy servers to use for |url|. If the request will 38 // complete asynchronously returns ERR_IO_PENDING and notifies the result 39 // by running |callback|. If the result code is OK then 40 // the request was successful and |results| contains the proxy 41 // resolution information. In the case of asynchronous completion 42 // |*request| is written to, and can be passed to CancelRequest(). 43 virtual int GetProxyForURL(const GURL& url, 44 ProxyInfo* results, 45 const net::CompletionCallback& callback, 46 RequestHandle* request, 47 const BoundNetLog& net_log) = 0; 48 49 // Cancels |request|. 50 virtual void CancelRequest(RequestHandle request) = 0; 51 52 // Gets the LoadState for |request|. 53 virtual LoadState GetLoadState(RequestHandle request) const = 0; 54 55 // The PAC script backend can be specified to the ProxyResolver either via 56 // URL, or via the javascript text itself. If |expects_pac_bytes| is true, 57 // then the ProxyResolverScriptData passed to SetPacScript() should 58 // contain the actual script bytes rather than just the URL. expects_pac_bytes()59 bool expects_pac_bytes() const { return expects_pac_bytes_; } 60 61 virtual void CancelSetPacScript() = 0; 62 63 // Called to set the PAC script backend to use. 64 // Returns ERR_IO_PENDING in the case of asynchronous completion, and notifies 65 // the result through |callback|. 66 virtual int SetPacScript( 67 const scoped_refptr<ProxyResolverScriptData>& pac_script, 68 const net::CompletionCallback& callback) = 0; 69 70 private: 71 const bool expects_pac_bytes_; 72 73 DISALLOW_COPY_AND_ASSIGN(ProxyResolver); 74 }; 75 76 } // namespace net 77 78 #endif // NET_PROXY_PROXY_RESOLVER_H_ 79