Update V8 to version 4.7.42.
[chromium-blink-merge.git] / net / proxy / multi_threaded_proxy_resolver.h
blob30a7b1b1ee6403009ffc6ff033405dc60f599971
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_MULTI_THREADED_PROXY_RESOLVER_H_
6 #define NET_PROXY_MULTI_THREADED_PROXY_RESOLVER_H_
8 #include <set>
10 #include "base/basictypes.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "net/base/net_export.h"
14 #include "net/proxy/proxy_resolver_factory.h"
16 namespace net {
17 class ProxyResolver;
19 // MultiThreadedProxyResolverFactory creates instances of a ProxyResolver
20 // implementation that runs synchronous ProxyResolver implementations on worker
21 // threads.
23 // Threads are created lazily on demand, up to a maximum total. The advantage
24 // of having a pool of threads, is faster performance. In particular, being
25 // able to keep servicing PAC requests even if one blocks its execution.
27 // During initialization (CreateProxyResolver), a single thread is spun up to
28 // test the script. If this succeeds, we cache the input script, and will re-use
29 // this to lazily provision any new threads as needed.
31 // For each new thread that we spawn in a particular MultiThreadedProxyResolver
32 // instance, a corresponding new ProxyResolver is created using the
33 // ProxyResolverFactory returned by CreateProxyResolverFactory().
35 // Because we are creating multiple ProxyResolver instances, this means we
36 // are duplicating script contexts for what is ordinarily seen as being a
37 // single script. This can affect compatibility on some classes of PAC
38 // script:
40 // (a) Scripts whose initialization has external dependencies on network or
41 // time may end up successfully initializing on some threads, but not
42 // others. So depending on what thread services the request, the result
43 // may jump between several possibilities.
45 // (b) Scripts whose FindProxyForURL() depends on side-effects may now
46 // work differently. For example, a PAC script which was incrementing
47 // a global counter and using that to make a decision. In the
48 // multi-threaded model, each thread may have a different value for this
49 // counter, so it won't globally be seen as monotonically increasing!
50 class NET_EXPORT_PRIVATE MultiThreadedProxyResolverFactory
51 : public ProxyResolverFactory {
52 public:
53 MultiThreadedProxyResolverFactory(size_t max_num_threads,
54 bool factory_expects_bytes);
55 ~MultiThreadedProxyResolverFactory() override;
57 int CreateProxyResolver(
58 const scoped_refptr<ProxyResolverScriptData>& pac_script,
59 scoped_ptr<ProxyResolver>* resolver,
60 const CompletionCallback& callback,
61 scoped_ptr<Request>* request) override;
63 private:
64 class Job;
66 // Invoked to create a ProxyResolverFactory instance to pass to a
67 // MultiThreadedProxyResolver instance.
68 virtual scoped_ptr<ProxyResolverFactory> CreateProxyResolverFactory() = 0;
70 void RemoveJob(Job* job);
72 const size_t max_num_threads_;
74 std::set<Job*> jobs_;
77 } // namespace net
79 #endif // NET_PROXY_MULTI_THREADED_PROXY_RESOLVER_H_