Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(144)

Side by Side Diff: net/proxy/proxy_resolver_v8.h

Issue 957933002: Lazily initialize the v8::Isolate used by ProxyResolverV8 (in the browser process). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/proxy/proxy_resolver_perftest.cc ('k') | net/proxy/proxy_resolver_v8.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef NET_PROXY_PROXY_RESOLVER_V8_H_ 5 #ifndef NET_PROXY_PROXY_RESOLVER_V8_H_
6 #define NET_PROXY_PROXY_RESOLVER_V8_H_ 6 #define NET_PROXY_PROXY_RESOLVER_V8_H_
7 7
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "net/base/net_export.h" 10 #include "net/base/net_export.h"
11 #include "net/proxy/proxy_resolver.h" 11 #include "net/proxy/proxy_resolver.h"
12 12
13 namespace gin {
14 class IsolateHolder;
15 } // namespace gin
16
17 namespace v8 {
18 class HeapStatistics;
19 class Isolate;
20 } // namespace v8
21
22 namespace net { 13 namespace net {
23 14
24 // Implementation of ProxyResolver that uses V8 to evaluate PAC scripts. 15 // Implementation of ProxyResolver that uses V8 to evaluate PAC scripts.
25 //
26 // ----------------------------------------------------------------------------
27 // !!! Important note on threading model:
28 // ----------------------------------------------------------------------------
29 // There can be only one instance of V8 running at a time. To enforce this
30 // constraint, ProxyResolverV8 holds a v8::Locker during execution. Therefore
31 // it is OK to run multiple instances of ProxyResolverV8 on different threads,
32 // since only one will be running inside V8 at a time.
33 //
34 // It is important that *ALL* instances of V8 in the process be using
35 // v8::Locker. If not there can be race conditions between the non-locked V8
36 // instances and the locked V8 instances used by ProxyResolverV8 (assuming they
37 // run on different threads).
38 //
39 // This is the case with the V8 instance used by chromium's renderer -- it runs
40 // on a different thread from ProxyResolver (renderer thread vs PAC thread),
41 // and does not use locking since it expects to be alone.
42 class NET_EXPORT_PRIVATE ProxyResolverV8 : public ProxyResolver { 16 class NET_EXPORT_PRIVATE ProxyResolverV8 : public ProxyResolver {
43 public: 17 public:
44 // Interface for the javascript bindings. 18 // Interface for the javascript bindings.
45 class NET_EXPORT_PRIVATE JSBindings { 19 class NET_EXPORT_PRIVATE JSBindings {
46 public: 20 public:
47 enum ResolveDnsOperation { 21 enum ResolveDnsOperation {
48 DNS_RESOLVE, 22 DNS_RESOLVE,
49 DNS_RESOLVE_EX, 23 DNS_RESOLVE_EX,
50 MY_IP_ADDRESS, 24 MY_IP_ADDRESS,
51 MY_IP_ADDRESS_EX, 25 MY_IP_ADDRESS_EX,
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 ProxyInfo* results, 60 ProxyInfo* results,
87 const net::CompletionCallback& /*callback*/, 61 const net::CompletionCallback& /*callback*/,
88 RequestHandle* /*request*/, 62 RequestHandle* /*request*/,
89 const BoundNetLog& net_log) override; 63 const BoundNetLog& net_log) override;
90 void CancelRequest(RequestHandle request) override; 64 void CancelRequest(RequestHandle request) override;
91 LoadState GetLoadState(RequestHandle request) const override; 65 LoadState GetLoadState(RequestHandle request) const override;
92 void CancelSetPacScript() override; 66 void CancelSetPacScript() override;
93 int SetPacScript(const scoped_refptr<ProxyResolverScriptData>& script_data, 67 int SetPacScript(const scoped_refptr<ProxyResolverScriptData>& script_data,
94 const net::CompletionCallback& /*callback*/) override; 68 const net::CompletionCallback& /*callback*/) override;
95 69
96 // Create an isolate to use for the proxy resolver. If the embedder invokes
97 // this method multiple times, it must be invoked in a thread safe manner,
98 // e.g. always from the same thread.
99 static void EnsureIsolateCreated();
100
101 static v8::Isolate* GetDefaultIsolate();
102
103 // Get total/ued heap memory usage of all v8 instances used by the proxy 70 // Get total/ued heap memory usage of all v8 instances used by the proxy
104 // resolver. 71 // resolver.
105 static size_t GetTotalHeapSize(); 72 static size_t GetTotalHeapSize();
106 static size_t GetUsedHeapSize(); 73 static size_t GetUsedHeapSize();
107 74
108 private: 75 private:
109 static gin::IsolateHolder* g_proxy_resolver_isolate_;
110
111 // Context holds the Javascript state for the most recently loaded PAC 76 // Context holds the Javascript state for the most recently loaded PAC
112 // script. It corresponds with the data from the last call to 77 // script. It corresponds with the data from the last call to
113 // SetPacScript(). 78 // SetPacScript().
114 class Context; 79 class Context;
115 80
116 scoped_ptr<Context> context_; 81 scoped_ptr<Context> context_;
117 82
118 JSBindings* js_bindings_; 83 JSBindings* js_bindings_;
119 84
120 DISALLOW_COPY_AND_ASSIGN(ProxyResolverV8); 85 DISALLOW_COPY_AND_ASSIGN(ProxyResolverV8);
121 }; 86 };
122 87
123 } // namespace net 88 } // namespace net
124 89
125 #endif // NET_PROXY_PROXY_RESOLVER_V8_H_ 90 #endif // NET_PROXY_PROXY_RESOLVER_V8_H_
OLDNEW
« no previous file with comments | « net/proxy/proxy_resolver_perftest.cc ('k') | net/proxy/proxy_resolver_v8.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698