Check for NULL extension_service and extension_process_map for Android platform
[chromium-blink-merge.git] / net / proxy / proxy_resolver_v8.h
blobc00bb8a4b2465e57ef49f8baa375a87dc61935c8
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 class ProxyResolverJSBindings;
17 // Implementation of ProxyResolver that uses V8 to evaluate PAC scripts.
19 // ----------------------------------------------------------------------------
20 // !!! Important note on threading model:
21 // ----------------------------------------------------------------------------
22 // There can be only one instance of V8 running at a time. To enforce this
23 // constraint, ProxyResolverV8 holds a v8::Locker during execution. Therefore
24 // it is OK to run multiple instances of ProxyResolverV8 on different threads,
25 // since only one will be running inside V8 at a time.
27 // It is important that *ALL* instances of V8 in the process be using
28 // v8::Locker. If not there can be race conditions between the non-locked V8
29 // instances and the locked V8 instances used by ProxyResolverV8 (assuming they
30 // run on different threads).
32 // This is the case with the V8 instance used by chromium's renderer -- it runs
33 // on a different thread from ProxyResolver (renderer thread vs PAC thread),
34 // and does not use locking since it expects to be alone.
35 class NET_EXPORT_PRIVATE ProxyResolverV8 : public ProxyResolver {
36 public:
37 // Constructs a ProxyResolverV8 with custom bindings. ProxyResolverV8 takes
38 // ownership of |custom_js_bindings| and deletes it when ProxyResolverV8
39 // is destroyed.
40 explicit ProxyResolverV8(ProxyResolverJSBindings* custom_js_bindings);
42 virtual ~ProxyResolverV8();
44 ProxyResolverJSBindings* js_bindings() const { return js_bindings_.get(); }
46 // ProxyResolver implementation:
47 virtual int GetProxyForURL(const GURL& url,
48 ProxyInfo* results,
49 const net::CompletionCallback& /*callback*/,
50 RequestHandle* /*request*/,
51 const BoundNetLog& net_log) OVERRIDE;
52 virtual void CancelRequest(RequestHandle request) OVERRIDE;
53 virtual LoadState GetLoadState(RequestHandle request) const OVERRIDE;
54 virtual LoadState GetLoadStateThreadSafe(
55 RequestHandle request) const OVERRIDE;
56 virtual void CancelSetPacScript() OVERRIDE;
57 virtual void PurgeMemory() OVERRIDE;
58 virtual void Shutdown() OVERRIDE;
59 virtual int SetPacScript(
60 const scoped_refptr<ProxyResolverScriptData>& script_data,
61 const net::CompletionCallback& /*callback*/) OVERRIDE;
63 private:
64 // Context holds the Javascript state for the most recently loaded PAC
65 // script. It corresponds with the data from the last call to
66 // SetPacScript().
67 class Context;
68 scoped_ptr<Context> context_;
70 scoped_ptr<ProxyResolverJSBindings> js_bindings_;
72 DISALLOW_COPY_AND_ASSIGN(ProxyResolverV8);
75 } // namespace net
77 #endif // NET_PROXY_PROXY_RESOLVER_V8_H_