[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | 943c808 | 2009-02-23 19:10:45 | [diff] [blame] | 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_V8_H_ | ||||
6 | #define NET_PROXY_PROXY_RESOLVER_V8_H_ | ||||
[email protected] | 32b76ef | 2010-07-26 23:08:24 | [diff] [blame] | 7 | #pragma once |
[email protected] | 943c808 | 2009-02-23 19:10:45 | [diff] [blame] | 8 | |
[email protected] | c4c1b48 | 2011-07-22 17:24:26 | [diff] [blame] | 9 | #include "base/compiler_specific.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 10 | #include "base/memory/scoped_ptr.h" |
[email protected] | 172da1b | 2011-08-12 15:52:26 | [diff] [blame] | 11 | #include "net/base/net_export.h" |
[email protected] | 7dc52f2 | 2009-03-02 22:37:18 | [diff] [blame] | 12 | #include "net/proxy/proxy_resolver.h" |
[email protected] | 943c808 | 2009-02-23 19:10:45 | [diff] [blame] | 13 | |
14 | namespace net { | ||||
15 | |||||
[email protected] | 90ae1fb | 2009-08-02 21:07:12 | [diff] [blame] | 16 | class ProxyResolverJSBindings; |
[email protected] | 8a00f00a | 2009-06-12 00:49:38 | [diff] [blame] | 17 | |
[email protected] | 943c808 | 2009-02-23 19:10:45 | [diff] [blame] | 18 | // Implementation of ProxyResolver that uses V8 to evaluate PAC scripts. |
19 | // | ||||
20 | // ---------------------------------------------------------------------------- | ||||
21 | // !!! Important note on threading model: | ||||
22 | // ---------------------------------------------------------------------------- | ||||
23 | // There can be only one instance of V8 running at a time. To enforce this | ||||
24 | // constraint, ProxyResolverV8 holds a v8::Locker during execution. Therefore | ||||
25 | // it is OK to run multiple instances of ProxyResolverV8 on different threads, | ||||
26 | // since only one will be running inside V8 at a time. | ||||
27 | // | ||||
28 | // It is important that *ALL* instances of V8 in the process be using | ||||
29 | // v8::Locker. If not there can be race conditions beween the non-locked V8 | ||||
30 | // instances and the locked V8 instances used by ProxyResolverV8 (assuming they | ||||
31 | // run on different threads). | ||||
32 | // | ||||
33 | // This is the case with the V8 instance used by chromium's renderer -- it runs | ||||
34 | // on a different thread from ProxyResolver (renderer thread vs PAC thread), | ||||
35 | // and does not use locking since it expects to be alone. | ||||
[email protected] | 172da1b | 2011-08-12 15:52:26 | [diff] [blame] | 36 | class NET_EXPORT_PRIVATE ProxyResolverV8 : public ProxyResolver { |
[email protected] | 943c808 | 2009-02-23 19:10:45 | [diff] [blame] | 37 | public: |
[email protected] | 50d7d728 | 2009-03-02 21:45:18 | [diff] [blame] | 38 | // Constructs a ProxyResolverV8 with custom bindings. ProxyResolverV8 takes |
39 | // ownership of |custom_js_bindings| and deletes it when ProxyResolverV8 | ||||
40 | // is destroyed. | ||||
[email protected] | 90ae1fb | 2009-08-02 21:07:12 | [diff] [blame] | 41 | explicit ProxyResolverV8(ProxyResolverJSBindings* custom_js_bindings); |
[email protected] | 50d7d728 | 2009-03-02 21:45:18 | [diff] [blame] | 42 | |
[email protected] | 775fd9e | 2009-07-26 21:12:20 | [diff] [blame] | 43 | virtual ~ProxyResolverV8(); |
[email protected] | 943c808 | 2009-02-23 19:10:45 | [diff] [blame] | 44 | |
[email protected] | 7aefb15 | 2011-01-21 23:46:49 | [diff] [blame] | 45 | ProxyResolverJSBindings* js_bindings() const { return js_bindings_.get(); } |
46 | |||||
[email protected] | 943c808 | 2009-02-23 19:10:45 | [diff] [blame] | 47 | // ProxyResolver implementation: |
[email protected] | 775fd9e | 2009-07-26 21:12:20 | [diff] [blame] | 48 | virtual int GetProxyForURL(const GURL& url, |
49 | ProxyInfo* results, | ||||
[email protected] | 23578681 | 2011-12-20 02:15:31 | [diff] [blame^] | 50 | const net::CompletionCallback& /*callback*/, |
[email protected] | 52ae80c | 2009-09-10 21:27:00 | [diff] [blame] | 51 | RequestHandle* /*request*/, |
[email protected] | c4c1b48 | 2011-07-22 17:24:26 | [diff] [blame] | 52 | const BoundNetLog& net_log) OVERRIDE; |
53 | virtual void CancelRequest(RequestHandle request) OVERRIDE; | ||||
[email protected] | f2c971f | 2011-11-08 00:33:17 | [diff] [blame] | 54 | virtual LoadState GetLoadState(RequestHandle request) const OVERRIDE; |
55 | virtual LoadState GetLoadStateThreadSafe( | ||||
56 | RequestHandle request) const OVERRIDE; | ||||
[email protected] | c4c1b48 | 2011-07-22 17:24:26 | [diff] [blame] | 57 | virtual void CancelSetPacScript() OVERRIDE; |
58 | virtual void PurgeMemory() OVERRIDE; | ||||
59 | virtual void Shutdown() OVERRIDE; | ||||
[email protected] | 2447640 | 2010-07-20 20:55:17 | [diff] [blame] | 60 | virtual int SetPacScript( |
61 | const scoped_refptr<ProxyResolverScriptData>& script_data, | ||||
[email protected] | 23578681 | 2011-12-20 02:15:31 | [diff] [blame^] | 62 | const net::CompletionCallback& /*callback*/) OVERRIDE; |
[email protected] | 943c808 | 2009-02-23 19:10:45 | [diff] [blame] | 63 | |
64 | private: | ||||
65 | // Context holds the Javascript state for the most recently loaded PAC | ||||
66 | // script. It corresponds with the data from the last call to | ||||
[email protected] | 620f571 | 2009-08-04 22:43:12 | [diff] [blame] | 67 | // SetPacScript(). |
[email protected] | 943c808 | 2009-02-23 19:10:45 | [diff] [blame] | 68 | class Context; |
69 | scoped_ptr<Context> context_; | ||||
70 | |||||
[email protected] | 90ae1fb | 2009-08-02 21:07:12 | [diff] [blame] | 71 | scoped_ptr<ProxyResolverJSBindings> js_bindings_; |
[email protected] | 50d7d728 | 2009-03-02 21:45:18 | [diff] [blame] | 72 | |
[email protected] | 943c808 | 2009-02-23 19:10:45 | [diff] [blame] | 73 | DISALLOW_COPY_AND_ASSIGN(ProxyResolverV8); |
74 | }; | ||||
75 | |||||
[email protected] | 943c808 | 2009-02-23 19:10:45 | [diff] [blame] | 76 | } // namespace net |
77 | |||||
78 | #endif // NET_PROXY_PROXY_RESOLVER_V8_H_ |