Revert of Revert of Add a WorkerScheduler and a WebThreadImplForWorker (patchset...
[chromium-blink-merge.git] / net / proxy / proxy_resolver_v8.h
blob446800c80d8b3591dad897733c4a53a69582f9d6
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/scoped_ptr.h"
10 #include "net/base/net_export.h"
11 #include "net/proxy/proxy_resolver.h"
13 namespace net {
15 // Implementation of ProxyResolver that uses V8 to evaluate PAC scripts.
16 class NET_EXPORT_PRIVATE ProxyResolverV8 : public ProxyResolver {
17 public:
18 // Interface for the javascript bindings.
19 class NET_EXPORT_PRIVATE JSBindings {
20 public:
21 enum ResolveDnsOperation {
22 DNS_RESOLVE,
23 DNS_RESOLVE_EX,
24 MY_IP_ADDRESS,
25 MY_IP_ADDRESS_EX,
28 JSBindings() {}
30 // Handler for "dnsResolve()", "dnsResolveEx()", "myIpAddress()",
31 // "myIpAddressEx()". Returns true on success and fills |*output| with the
32 // result. If |*terminate| is set to true, then the script execution will
33 // be aborted. Note that termination may not happen right away.
34 virtual bool ResolveDns(const std::string& host,
35 ResolveDnsOperation op,
36 std::string* output,
37 bool* terminate) = 0;
39 // Handler for "alert(message)"
40 virtual void Alert(const base::string16& message) = 0;
42 // Handler for when an error is encountered. |line_number| may be -1
43 // if a line number is not applicable to this error.
44 virtual void OnError(int line_number, const base::string16& error) = 0;
46 protected:
47 virtual ~JSBindings() {}
50 // Constructs a ProxyResolverV8.
51 ProxyResolverV8();
53 ~ProxyResolverV8() override;
55 JSBindings* js_bindings() const { return js_bindings_; }
56 void set_js_bindings(JSBindings* js_bindings) { js_bindings_ = js_bindings; }
58 // ProxyResolver implementation:
59 int GetProxyForURL(const GURL& url,
60 ProxyInfo* results,
61 const net::CompletionCallback& /*callback*/,
62 RequestHandle* /*request*/,
63 const BoundNetLog& net_log) override;
64 void CancelRequest(RequestHandle request) override;
65 LoadState GetLoadState(RequestHandle request) const override;
66 void CancelSetPacScript() override;
67 int SetPacScript(const scoped_refptr<ProxyResolverScriptData>& script_data,
68 const net::CompletionCallback& /*callback*/) override;
70 // Get total/ued heap memory usage of all v8 instances used by the proxy
71 // resolver.
72 static size_t GetTotalHeapSize();
73 static size_t GetUsedHeapSize();
75 private:
76 // Context holds the Javascript state for the most recently loaded PAC
77 // script. It corresponds with the data from the last call to
78 // SetPacScript().
79 class Context;
81 scoped_ptr<Context> context_;
83 JSBindings* js_bindings_;
85 DISALLOW_COPY_AND_ASSIGN(ProxyResolverV8);
88 } // namespace net
90 #endif // NET_PROXY_PROXY_RESOLVER_V8_H_