Home | History | Annotate | Download | only in proxy
      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 #pragma once
      8 
      9 #include "base/logging.h"
     10 #include "base/memory/ref_counted.h"
     11 #include "base/string16.h"
     12 #include "googleurl/src/gurl.h"
     13 #include "net/base/completion_callback.h"
     14 #include "net/proxy/proxy_resolver_script_data.h"
     15 
     16 namespace net {
     17 
     18 class BoundNetLog;
     19 class ProxyInfo;
     20 
     21 // Interface for "proxy resolvers". A ProxyResolver fills in a list of proxies
     22 // to use for a particular URL. Generally the backend for a ProxyResolver is
     23 // a PAC script, but it doesn't need to be. ProxyResolver can service multiple
     24 // requests at a time.
     25 class ProxyResolver {
     26  public:
     27   // Opaque pointer type, to return a handle to cancel outstanding requests.
     28   typedef void* RequestHandle;
     29 
     30   // See |expects_pac_bytes()| for the meaning of |expects_pac_bytes|.
     31   explicit ProxyResolver(bool expects_pac_bytes)
     32       : expects_pac_bytes_(expects_pac_bytes) {}
     33 
     34   virtual ~ProxyResolver() {}
     35 
     36   // Gets a list of proxy servers to use for |url|. If the request will
     37   // complete asynchronously returns ERR_IO_PENDING and notifies the result
     38   // by running |callback|.  If the result code is OK then
     39   // the request was successful and |results| contains the proxy
     40   // resolution information.  In the case of asynchronous completion
     41   // |*request| is written to, and can be passed to CancelRequest().
     42   virtual int GetProxyForURL(const GURL& url,
     43                              ProxyInfo* results,
     44                              CompletionCallback* callback,
     45                              RequestHandle* request,
     46                              const BoundNetLog& net_log) = 0;
     47 
     48   // Cancels |request|.
     49   virtual void CancelRequest(RequestHandle request) = 0;
     50 
     51   // The PAC script backend can be specified to the ProxyResolver either via
     52   // URL, or via the javascript text itself.  If |expects_pac_bytes| is true,
     53   // then the ProxyResolverScriptData passed to SetPacScript() should
     54   // contain the actual script bytes rather than just the URL.
     55   bool expects_pac_bytes() const { return expects_pac_bytes_; }
     56 
     57   virtual void CancelSetPacScript() = 0;
     58 
     59   // Frees any unneeded memory held by the resolver, e.g. garbage in the JS
     60   // engine.  Most subclasses don't need to do anything, so we provide a default
     61   // no-op implementation.
     62   virtual void PurgeMemory() {}
     63 
     64   // Called to set the PAC script backend to use.
     65   // Returns ERR_IO_PENDING in the case of asynchronous completion, and notifies
     66   // the result through |callback|.
     67   virtual int SetPacScript(
     68       const scoped_refptr<ProxyResolverScriptData>& pac_script,
     69       CompletionCallback* callback) = 0;
     70 
     71   // Optional shutdown code to be run before destruction. This is only used
     72   // by the multithreaded runner to signal cleanup from origin thread
     73   virtual void Shutdown() {}
     74 
     75  private:
     76   const bool expects_pac_bytes_;
     77 
     78   DISALLOW_COPY_AND_ASSIGN(ProxyResolver);
     79 };
     80 
     81 }  // namespace net
     82 
     83 #endif  // NET_PROXY_PROXY_RESOLVER_H_
     84