blob: 30a7b1b1ee6403009ffc6ff033405dc60f599971 [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
5#ifndef NET_PROXY_MULTI_THREADED_PROXY_RESOLVER_H_
6#define NET_PROXY_MULTI_THREADED_PROXY_RESOLVER_H_
[email protected]61b84d52010-07-09 03:32:007
sammc514748c2015-05-01 06:15:048#include <set>
[email protected]61b84d52010-07-09 03:32:009
10#include "base/basictypes.h"
[email protected]3b63f8f42011-03-28 01:54:1511#include "base/memory/ref_counted.h"
12#include "base/memory/scoped_ptr.h"
[email protected]172da1b2011-08-12 15:52:2613#include "net/base/net_export.h"
sammc514748c2015-05-01 06:15:0414#include "net/proxy/proxy_resolver_factory.h"
[email protected]61b84d52010-07-09 03:32:0015
16namespace net {
sammc514748c2015-05-01 06:15:0417class ProxyResolver;
[email protected]61b84d52010-07-09 03:32:0018
sammc514748c2015-05-01 06:15:0419// MultiThreadedProxyResolverFactory creates instances of a ProxyResolver
20// implementation that runs synchronous ProxyResolver implementations on worker
21// threads.
[email protected]61b84d52010-07-09 03:32:0022//
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.
26//
sammc514748c2015-05-01 06:15:0427// 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
[email protected]61b84d52010-07-09 03:32:0029// this to lazily provision any new threads as needed.
30//
sammc514748c2015-05-01 06:15:0431// 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().
[email protected]61b84d52010-07-09 03:32:0034//
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:
39//
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.
44//
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!
sammc514748c2015-05-01 06:15:0450class NET_EXPORT_PRIVATE MultiThreadedProxyResolverFactory
51 : public ProxyResolverFactory {
[email protected]61b84d52010-07-09 03:32:0052 public:
sammc514748c2015-05-01 06:15:0453 MultiThreadedProxyResolverFactory(size_t max_num_threads,
54 bool factory_expects_bytes);
55 ~MultiThreadedProxyResolverFactory() override;
[email protected]61b84d52010-07-09 03:32:0056
sammc514748c2015-05-01 06:15:0457 int CreateProxyResolver(
58 const scoped_refptr<ProxyResolverScriptData>& pac_script,
59 scoped_ptr<ProxyResolver>* resolver,
60 const CompletionCallback& callback,
61 scoped_ptr<Request>* request) override;
[email protected]61b84d52010-07-09 03:32:0062
63 private:
[email protected]61b84d52010-07-09 03:32:0064 class Job;
[email protected]61b84d52010-07-09 03:32:0065
sammc514748c2015-05-01 06:15:0466 // Invoked to create a ProxyResolverFactory instance to pass to a
67 // MultiThreadedProxyResolver instance.
68 virtual scoped_ptr<ProxyResolverFactory> CreateProxyResolverFactory() = 0;
[email protected]61b84d52010-07-09 03:32:0069
sammc514748c2015-05-01 06:15:0470 void RemoveJob(Job* job);
[email protected]61b84d52010-07-09 03:32:0071
[email protected]61b84d52010-07-09 03:32:0072 const size_t max_num_threads_;
sammc514748c2015-05-01 06:15:0473
74 std::set<Job*> jobs_;
[email protected]61b84d52010-07-09 03:32:0075};
76
77} // namespace net
78
79#endif // NET_PROXY_MULTI_THREADED_PROXY_RESOLVER_H_