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