blob: ecd8d13acc3730aea91953b96745d6c1c7059f7b [file] [log] [blame]
[email protected]3b63f8f42011-03-28 01:54:151// Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]943c8082009-02-23 19:10:452// 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]32b76ef2010-07-26 23:08:247#pragma once
[email protected]943c8082009-02-23 19:10:458
[email protected]c4c1b482011-07-22 17:24:269#include "base/compiler_specific.h"
[email protected]3b63f8f42011-03-28 01:54:1510#include "base/memory/scoped_ptr.h"
[email protected]172da1b2011-08-12 15:52:2611#include "net/base/net_export.h"
[email protected]7dc52f22009-03-02 22:37:1812#include "net/proxy/proxy_resolver.h"
[email protected]943c8082009-02-23 19:10:4513
14namespace net {
15
[email protected]90ae1fb2009-08-02 21:07:1216class ProxyResolverJSBindings;
[email protected]8a00f00a2009-06-12 00:49:3817
[email protected]943c8082009-02-23 19:10:4518// 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]172da1b2011-08-12 15:52:2636class NET_EXPORT_PRIVATE ProxyResolverV8 : public ProxyResolver {
[email protected]943c8082009-02-23 19:10:4537 public:
[email protected]50d7d7282009-03-02 21:45:1838 // Constructs a ProxyResolverV8 with custom bindings. ProxyResolverV8 takes
39 // ownership of |custom_js_bindings| and deletes it when ProxyResolverV8
40 // is destroyed.
[email protected]90ae1fb2009-08-02 21:07:1241 explicit ProxyResolverV8(ProxyResolverJSBindings* custom_js_bindings);
[email protected]50d7d7282009-03-02 21:45:1842
[email protected]775fd9e2009-07-26 21:12:2043 virtual ~ProxyResolverV8();
[email protected]943c8082009-02-23 19:10:4544
[email protected]7aefb152011-01-21 23:46:4945 ProxyResolverJSBindings* js_bindings() const { return js_bindings_.get(); }
46
[email protected]943c8082009-02-23 19:10:4547 // ProxyResolver implementation:
[email protected]775fd9e2009-07-26 21:12:2048 virtual int GetProxyForURL(const GURL& url,
49 ProxyInfo* results,
[email protected]235786812011-12-20 02:15:3150 const net::CompletionCallback& /*callback*/,
[email protected]52ae80c2009-09-10 21:27:0051 RequestHandle* /*request*/,
[email protected]c4c1b482011-07-22 17:24:2652 const BoundNetLog& net_log) OVERRIDE;
53 virtual void CancelRequest(RequestHandle request) OVERRIDE;
[email protected]f2c971f2011-11-08 00:33:1754 virtual LoadState GetLoadState(RequestHandle request) const OVERRIDE;
55 virtual LoadState GetLoadStateThreadSafe(
56 RequestHandle request) const OVERRIDE;
[email protected]c4c1b482011-07-22 17:24:2657 virtual void CancelSetPacScript() OVERRIDE;
58 virtual void PurgeMemory() OVERRIDE;
59 virtual void Shutdown() OVERRIDE;
[email protected]24476402010-07-20 20:55:1760 virtual int SetPacScript(
61 const scoped_refptr<ProxyResolverScriptData>& script_data,
[email protected]235786812011-12-20 02:15:3162 const net::CompletionCallback& /*callback*/) OVERRIDE;
[email protected]943c8082009-02-23 19:10:4563
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]620f5712009-08-04 22:43:1267 // SetPacScript().
[email protected]943c8082009-02-23 19:10:4568 class Context;
69 scoped_ptr<Context> context_;
70
[email protected]90ae1fb2009-08-02 21:07:1271 scoped_ptr<ProxyResolverJSBindings> js_bindings_;
[email protected]50d7d7282009-03-02 21:45:1872
[email protected]943c8082009-02-23 19:10:4573 DISALLOW_COPY_AND_ASSIGN(ProxyResolverV8);
74};
75
[email protected]943c8082009-02-23 19:10:4576} // namespace net
77
78#endif // NET_PROXY_PROXY_RESOLVER_V8_H_