Evict resources from resource pool after timeout
[chromium-blink-merge.git] / net / proxy / proxy_resolver_v8.h
blob98746ac0279c26e72d6779fce7d84ffc9488a9ab
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_V8_H_
6 #define NET_PROXY_PROXY_RESOLVER_V8_H_
8 #include "base/compiler_specific.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/strings/string16.h"
12 #include "net/base/net_export.h"
14 class GURL;
16 namespace net {
17 class ProxyInfo;
18 class ProxyResolverScriptData;
20 // A synchronous ProxyResolver-like that uses V8 to evaluate PAC scripts.
21 class NET_EXPORT_PRIVATE ProxyResolverV8 {
22 public:
23 // Interface for the javascript bindings.
24 class NET_EXPORT_PRIVATE JSBindings {
25 public:
26 enum ResolveDnsOperation {
27 DNS_RESOLVE,
28 DNS_RESOLVE_EX,
29 MY_IP_ADDRESS,
30 MY_IP_ADDRESS_EX,
33 JSBindings() {}
35 // Handler for "dnsResolve()", "dnsResolveEx()", "myIpAddress()",
36 // "myIpAddressEx()". Returns true on success and fills |*output| with the
37 // result. If |*terminate| is set to true, then the script execution will
38 // be aborted. Note that termination may not happen right away.
39 virtual bool ResolveDns(const std::string& host,
40 ResolveDnsOperation op,
41 std::string* output,
42 bool* terminate) = 0;
44 // Handler for "alert(message)"
45 virtual void Alert(const base::string16& message) = 0;
47 // Handler for when an error is encountered. |line_number| may be -1
48 // if a line number is not applicable to this error.
49 virtual void OnError(int line_number, const base::string16& error) = 0;
51 protected:
52 virtual ~JSBindings() {}
55 // Constructs a ProxyResolverV8.
56 static int Create(const scoped_refptr<ProxyResolverScriptData>& script_data,
57 JSBindings* bindings,
58 scoped_ptr<ProxyResolverV8>* resolver);
60 ~ProxyResolverV8();
62 int GetProxyForURL(const GURL& url, ProxyInfo* results, JSBindings* bindings);
64 // Get total/ued heap memory usage of all v8 instances used by the proxy
65 // resolver.
66 static size_t GetTotalHeapSize();
67 static size_t GetUsedHeapSize();
69 private:
70 // Context holds the Javascript state for the PAC script.
71 class Context;
73 explicit ProxyResolverV8(scoped_ptr<Context> context);
75 scoped_ptr<Context> context_;
77 DISALLOW_COPY_AND_ASSIGN(ProxyResolverV8);
80 } // namespace net
82 #endif // NET_PROXY_PROXY_RESOLVER_V8_H_