blob: caf36faa7bb4dece8027d650e80423fefdd40882 [file] [log] [blame]
[email protected]3b63f8f42011-03-28 01:54:151// Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]61b84d52010-07-09 03:32:002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Lily Houghton582d4622018-01-22 22:43:405#ifndef NET_PROXY_RESOLUTION_MULTI_THREADED_PROXY_RESOLVER_H_
6#define NET_PROXY_RESOLUTION_MULTI_THREADED_PROXY_RESOLVER_H_
[email protected]61b84d52010-07-09 03:32:007
Avi Drissman13fc8932015-12-20 04:40:468#include <stddef.h>
9
danakj8a98ca22016-04-16 02:47:3610#include <memory>
sammc514748c2015-05-01 06:15:0411#include <set>
[email protected]61b84d52010-07-09 03:32:0012
[email protected]3b63f8f42011-03-28 01:54:1513#include "base/memory/ref_counted.h"
[email protected]172da1b2011-08-12 15:52:2614#include "net/base/net_export.h"
Lily Houghton582d4622018-01-22 22:43:4015#include "net/proxy_resolution/proxy_resolver_factory.h"
[email protected]61b84d52010-07-09 03:32:0016
17namespace net {
sammc514748c2015-05-01 06:15:0418class ProxyResolver;
[email protected]61b84d52010-07-09 03:32:0019
sammc514748c2015-05-01 06:15:0420// MultiThreadedProxyResolverFactory creates instances of a ProxyResolver
21// implementation that runs synchronous ProxyResolver implementations on worker
22// threads.
[email protected]61b84d52010-07-09 03:32:0023//
24// Threads are created lazily on demand, up to a maximum total. The advantage
25// of having a pool of threads, is faster performance. In particular, being
26// able to keep servicing PAC requests even if one blocks its execution.
27//
sammc514748c2015-05-01 06:15:0428// During initialization (CreateProxyResolver), a single thread is spun up to
29// test the script. If this succeeds, we cache the input script, and will re-use
[email protected]61b84d52010-07-09 03:32:0030// this to lazily provision any new threads as needed.
31//
sammc514748c2015-05-01 06:15:0432// For each new thread that we spawn in a particular MultiThreadedProxyResolver
33// instance, a corresponding new ProxyResolver is created using the
34// ProxyResolverFactory returned by CreateProxyResolverFactory().
[email protected]61b84d52010-07-09 03:32:0035//
36// Because we are creating multiple ProxyResolver instances, this means we
37// are duplicating script contexts for what is ordinarily seen as being a
38// single script. This can affect compatibility on some classes of PAC
39// script:
40//
41// (a) Scripts whose initialization has external dependencies on network or
42// time may end up successfully initializing on some threads, but not
43// others. So depending on what thread services the request, the result
44// may jump between several possibilities.
45//
46// (b) Scripts whose FindProxyForURL() depends on side-effects may now
47// work differently. For example, a PAC script which was incrementing
48// a global counter and using that to make a decision. In the
49// multi-threaded model, each thread may have a different value for this
50// counter, so it won't globally be seen as monotonically increasing!
sammc514748c2015-05-01 06:15:0451class NET_EXPORT_PRIVATE MultiThreadedProxyResolverFactory
52 : public ProxyResolverFactory {
[email protected]61b84d52010-07-09 03:32:0053 public:
sammc514748c2015-05-01 06:15:0454 MultiThreadedProxyResolverFactory(size_t max_num_threads,
55 bool factory_expects_bytes);
56 ~MultiThreadedProxyResolverFactory() override;
[email protected]61b84d52010-07-09 03:32:0057
sammc514748c2015-05-01 06:15:0458 int CreateProxyResolver(
59 const scoped_refptr<ProxyResolverScriptData>& pac_script,
danakj8a98ca22016-04-16 02:47:3660 std::unique_ptr<ProxyResolver>* resolver,
sammc514748c2015-05-01 06:15:0461 const CompletionCallback& callback,
danakj8a98ca22016-04-16 02:47:3662 std::unique_ptr<Request>* request) override;
[email protected]61b84d52010-07-09 03:32:0063
64 private:
[email protected]61b84d52010-07-09 03:32:0065 class Job;
[email protected]61b84d52010-07-09 03:32:0066
sammc514748c2015-05-01 06:15:0467 // Invoked to create a ProxyResolverFactory instance to pass to a
68 // MultiThreadedProxyResolver instance.
danakj8a98ca22016-04-16 02:47:3669 virtual std::unique_ptr<ProxyResolverFactory>
70 CreateProxyResolverFactory() = 0;
[email protected]61b84d52010-07-09 03:32:0071
sammc514748c2015-05-01 06:15:0472 void RemoveJob(Job* job);
[email protected]61b84d52010-07-09 03:32:0073
[email protected]61b84d52010-07-09 03:32:0074 const size_t max_num_threads_;
sammc514748c2015-05-01 06:15:0475
76 std::set<Job*> jobs_;
[email protected]61b84d52010-07-09 03:32:0077};
78
79} // namespace net
80
Lily Houghton582d4622018-01-22 22:43:4081#endif // NET_PROXY_RESOLUTION_MULTI_THREADED_PROXY_RESOLVER_H_