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 118100: Avoid doing concurrent DNS resolves of the same hostname (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Get compiling on mac Created 11 years, 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 <string> 8 #include <string>
9 9
10 #include "base/scoped_ptr.h" 10 #include "base/scoped_ptr.h"
11 #include "net/proxy/proxy_resolver.h" 11 #include "net/proxy/proxy_resolver.h"
12 12
13 class MessageLoop;
14
13 namespace net { 15 namespace net {
14 16
17 class HostResolver;
18
15 // Implementation of ProxyResolver that uses V8 to evaluate PAC scripts. 19 // Implementation of ProxyResolver that uses V8 to evaluate PAC scripts.
16 // 20 //
17 // ---------------------------------------------------------------------------- 21 // ----------------------------------------------------------------------------
18 // !!! Important note on threading model: 22 // !!! Important note on threading model:
19 // ---------------------------------------------------------------------------- 23 // ----------------------------------------------------------------------------
20 // There can be only one instance of V8 running at a time. To enforce this 24 // There can be only one instance of V8 running at a time. To enforce this
21 // constraint, ProxyResolverV8 holds a v8::Locker during execution. Therefore 25 // constraint, ProxyResolverV8 holds a v8::Locker during execution. Therefore
22 // it is OK to run multiple instances of ProxyResolverV8 on different threads, 26 // it is OK to run multiple instances of ProxyResolverV8 on different threads,
23 // since only one will be running inside V8 at a time. 27 // since only one will be running inside V8 at a time.
24 // 28 //
25 // It is important that *ALL* instances of V8 in the process be using 29 // It is important that *ALL* instances of V8 in the process be using
26 // v8::Locker. If not there can be race conditions beween the non-locked V8 30 // v8::Locker. If not there can be race conditions beween the non-locked V8
27 // instances and the locked V8 instances used by ProxyResolverV8 (assuming they 31 // instances and the locked V8 instances used by ProxyResolverV8 (assuming they
28 // run on different threads). 32 // run on different threads).
29 // 33 //
30 // This is the case with the V8 instance used by chromium's renderer -- it runs 34 // This is the case with the V8 instance used by chromium's renderer -- it runs
31 // on a different thread from ProxyResolver (renderer thread vs PAC thread), 35 // on a different thread from ProxyResolver (renderer thread vs PAC thread),
32 // and does not use locking since it expects to be alone. 36 // and does not use locking since it expects to be alone.
33 class ProxyResolverV8 : public ProxyResolver { 37 class ProxyResolverV8 : public ProxyResolver {
34 public: 38 public:
35 // Constructs a ProxyResolverV8 with default javascript bindings.
36 //
37 // The default javascript bindings will:
38 // - Send script error messages to LOG(INFO)
39 // - Send script alert()s to LOG(INFO)
40 // - Use the default host mapper to service dnsResolve(), synchronously
41 // on the V8 thread.
42 //
43 // For clients that need more control (for example, sending the script output
44 // to a UI widget), use the ProxyResolverV8(JSBindings*) and specify your
45 // own bindings.
46 ProxyResolverV8();
47
48 class JSBindings; 39 class JSBindings;
49 40
50 // Constructs a ProxyResolverV8 with custom bindings. ProxyResolverV8 takes 41 // Constructs a ProxyResolverV8 with custom bindings. ProxyResolverV8 takes
51 // ownership of |custom_js_bindings| and deletes it when ProxyResolverV8 42 // ownership of |custom_js_bindings| and deletes it when ProxyResolverV8
52 // is destroyed. 43 // is destroyed.
53 explicit ProxyResolverV8(JSBindings* custom_js_bindings); 44 explicit ProxyResolverV8(JSBindings* custom_js_bindings);
54 45
55 ~ProxyResolverV8(); 46 ~ProxyResolverV8();
56 47
57 // ProxyResolver implementation: 48 // ProxyResolver implementation:
58 virtual int GetProxyForURL(const GURL& query_url, 49 virtual int GetProxyForURL(const GURL& query_url,
59 const GURL& /*pac_url*/, 50 const GURL& /*pac_url*/,
60 ProxyInfo* results); 51 ProxyInfo* results);
61 virtual void SetPacScript(const std::string& bytes); 52 virtual void SetPacScript(const std::string& bytes);
62 53
63 JSBindings* js_bindings() const { return js_bindings_.get(); } 54 JSBindings* js_bindings() const { return js_bindings_.get(); }
64 55
56 // Creates a default javascript bindings implementation that will:
57 // - Send script error messages to LOG(INFO)
58 // - Send script alert()s to LOG(INFO)
59 // - Use the provided host mapper to service dnsResolve().
60 //
61 // For clients that need more control (for example, sending the script output
62 // to a UI widget), use the ProxyResolverV8(JSBindings*) and specify your
63 // own bindings.
64 //
65 // |host_resolver| will be used in async mode on |host_resolver_loop|. If
66 // |host_resolver_loop| is NULL, then |host_resolver| will be used in sync
67 // mode on the PAC thread.
68 static JSBindings* CreateDefaultBindings(HostResolver* host_resolver,
69 MessageLoop* host_resolver_loop);
70
65 private: 71 private:
66 // Context holds the Javascript state for the most recently loaded PAC 72 // Context holds the Javascript state for the most recently loaded PAC
67 // script. It corresponds with the data from the last call to 73 // script. It corresponds with the data from the last call to
68 // SetPacScript(). 74 // SetPacScript().
69 class Context; 75 class Context;
70 scoped_ptr<Context> context_; 76 scoped_ptr<Context> context_;
71 77
72 scoped_ptr<JSBindings> js_bindings_; 78 scoped_ptr<JSBindings> js_bindings_;
73 79
74 DISALLOW_COPY_AND_ASSIGN(ProxyResolverV8); 80 DISALLOW_COPY_AND_ASSIGN(ProxyResolverV8);
(...skipping 14 matching lines...) Expand all
89 virtual std::string DnsResolve(const std::string& host) = 0; 95 virtual std::string DnsResolve(const std::string& host) = 0;
90 96
91 // Handler for when an error is encountered. |line_number| may be -1 97 // Handler for when an error is encountered. |line_number| may be -1
92 // if a line number is not applicable to this error. 98 // if a line number is not applicable to this error.
93 virtual void OnError(int line_number, const std::string& error) = 0; 99 virtual void OnError(int line_number, const std::string& error) = 0;
94 }; 100 };
95 101
96 } // namespace net 102 } // namespace net
97 103
98 #endif // NET_PROXY_PROXY_RESOLVER_V8_H_ 104 #endif // NET_PROXY_PROXY_RESOLVER_V8_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698