1 // Copyright 2013 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef SERVICES_PROXY_RESOLVER_PROXY_RESOLVER_V8_TRACING_H_
6 #define SERVICES_PROXY_RESOLVER_PROXY_RESOLVER_V8_TRACING_H_
10 #include "base/memory/ref_counted.h"
11 #include "net/base/completion_once_callback.h"
12 #include "net/proxy_resolution/proxy_resolver.h"
13 #include "net/proxy_resolution/proxy_resolver_factory.h"
16 class NetLogWithSource;
17 class NetworkAnonymizationKey;
20 namespace proxy_resolver {
22 class ProxyHostResolver;
24 // ProxyResolverV8Tracing is a non-blocking proxy resolver.
25 class ProxyResolverV8Tracing {
27 // Bindings is an interface used by ProxyResolverV8Tracing to delegate
28 // per-request functionality. Each instance will be destroyed on the origin
29 // thread of the ProxyResolverV8Tracing when the request completes or is
30 // cancelled. All methods will be invoked from the origin thread.
35 Bindings(const Bindings&) = delete;
36 Bindings& operator=(const Bindings&) = delete;
38 virtual ~Bindings() {}
40 // Invoked in response to an alert() call by the PAC script.
41 virtual void Alert(const std::u16string& message) = 0;
43 // Invoked in response to an error in the PAC script.
44 virtual void OnError(int line_number, const std::u16string& message) = 0;
46 // Returns a HostResolver to use for DNS resolution.
47 virtual ProxyHostResolver* GetHostResolver() = 0;
49 // Returns a NetLogWithSource to be passed to the HostResolver returned by
51 virtual net::NetLogWithSource GetNetLogWithSource() = 0;
54 virtual ~ProxyResolverV8Tracing() {}
56 // Gets a list of proxy servers to use for |url|. This request always
57 // runs asynchronously and notifies the result by running |callback|. If the
58 // result code is OK then the request was successful and |results| contains
59 // the proxy resolution information. Request can be cancelled by resetting
61 virtual void GetProxyForURL(
63 const net::NetworkAnonymizationKey& network_anonymization_key,
64 net::ProxyInfo* results,
65 net::CompletionOnceCallback callback,
66 std::unique_ptr<net::ProxyResolver::Request>* request,
67 std::unique_ptr<Bindings> bindings) = 0;
70 // A factory for ProxyResolverV8Tracing instances. The default implementation,
71 // returned by Create(), creates ProxyResolverV8Tracing instances that execute
72 // ProxyResolverV8 on a single helper thread, and do some magic to avoid
73 // blocking in DNS. For more details see the design document:
74 // https://docs.google.com/a/google.com/document/d/16Ij5OcVnR3s0MH4Z5XkhI9VTPoMJdaBn9rKreAmGOdE/edit?pli=1
75 class ProxyResolverV8TracingFactory {
77 ProxyResolverV8TracingFactory() {}
79 ProxyResolverV8TracingFactory(const ProxyResolverV8TracingFactory&) = delete;
80 ProxyResolverV8TracingFactory& operator=(
81 const ProxyResolverV8TracingFactory&) = delete;
83 virtual ~ProxyResolverV8TracingFactory() = default;
85 virtual void CreateProxyResolverV8Tracing(
86 const scoped_refptr<net::PacFileData>& pac_script,
87 std::unique_ptr<ProxyResolverV8Tracing::Bindings> bindings,
88 std::unique_ptr<ProxyResolverV8Tracing>* resolver,
89 net::CompletionOnceCallback callback,
90 std::unique_ptr<net::ProxyResolverFactory::Request>* request) = 0;
92 static std::unique_ptr<ProxyResolverV8TracingFactory> Create();
95 } // namespace proxy_resolver
97 #endif // SERVICES_PROXY_RESOLVER_PROXY_RESOLVER_V8_TRACING_H_