proxy_resolver_v8_tracing.h 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // Copyright (c) 2013 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.
  4. #ifndef SERVICES_PROXY_RESOLVER_PROXY_RESOLVER_V8_TRACING_H_
  5. #define SERVICES_PROXY_RESOLVER_PROXY_RESOLVER_V8_TRACING_H_
  6. #include <memory>
  7. #include "base/memory/ref_counted.h"
  8. #include "net/base/completion_once_callback.h"
  9. #include "net/proxy_resolution/proxy_resolver.h"
  10. #include "net/proxy_resolution/proxy_resolver_factory.h"
  11. namespace net {
  12. class NetLogWithSource;
  13. class NetworkIsolationKey;
  14. } // namespace net
  15. namespace proxy_resolver {
  16. class ProxyHostResolver;
  17. // ProxyResolverV8Tracing is a non-blocking proxy resolver.
  18. class ProxyResolverV8Tracing {
  19. public:
  20. // Bindings is an interface used by ProxyResolverV8Tracing to delegate
  21. // per-request functionality. Each instance will be destroyed on the origin
  22. // thread of the ProxyResolverV8Tracing when the request completes or is
  23. // cancelled. All methods will be invoked from the origin thread.
  24. class Bindings {
  25. public:
  26. Bindings() {}
  27. Bindings(const Bindings&) = delete;
  28. Bindings& operator=(const Bindings&) = delete;
  29. virtual ~Bindings() {}
  30. // Invoked in response to an alert() call by the PAC script.
  31. virtual void Alert(const std::u16string& message) = 0;
  32. // Invoked in response to an error in the PAC script.
  33. virtual void OnError(int line_number, const std::u16string& message) = 0;
  34. // Returns a HostResolver to use for DNS resolution.
  35. virtual ProxyHostResolver* GetHostResolver() = 0;
  36. // Returns a NetLogWithSource to be passed to the HostResolver returned by
  37. // GetHostResolver().
  38. virtual net::NetLogWithSource GetNetLogWithSource() = 0;
  39. };
  40. virtual ~ProxyResolverV8Tracing() {}
  41. // Gets a list of proxy servers to use for |url|. This request always
  42. // runs asynchronously and notifies the result by running |callback|. If the
  43. // result code is OK then the request was successful and |results| contains
  44. // the proxy resolution information. Request can be cancelled by resetting
  45. // |*request|.
  46. virtual void GetProxyForURL(
  47. const GURL& url,
  48. const net::NetworkIsolationKey& network_isolation_key,
  49. net::ProxyInfo* results,
  50. net::CompletionOnceCallback callback,
  51. std::unique_ptr<net::ProxyResolver::Request>* request,
  52. std::unique_ptr<Bindings> bindings) = 0;
  53. };
  54. // A factory for ProxyResolverV8Tracing instances. The default implementation,
  55. // returned by Create(), creates ProxyResolverV8Tracing instances that execute
  56. // ProxyResolverV8 on a single helper thread, and do some magic to avoid
  57. // blocking in DNS. For more details see the design document:
  58. // https://docs.google.com/a/google.com/document/d/16Ij5OcVnR3s0MH4Z5XkhI9VTPoMJdaBn9rKreAmGOdE/edit?pli=1
  59. class ProxyResolverV8TracingFactory {
  60. public:
  61. ProxyResolverV8TracingFactory() {}
  62. ProxyResolverV8TracingFactory(const ProxyResolverV8TracingFactory&) = delete;
  63. ProxyResolverV8TracingFactory& operator=(
  64. const ProxyResolverV8TracingFactory&) = delete;
  65. virtual ~ProxyResolverV8TracingFactory() = default;
  66. virtual void CreateProxyResolverV8Tracing(
  67. const scoped_refptr<net::PacFileData>& pac_script,
  68. std::unique_ptr<ProxyResolverV8Tracing::Bindings> bindings,
  69. std::unique_ptr<ProxyResolverV8Tracing>* resolver,
  70. net::CompletionOnceCallback callback,
  71. std::unique_ptr<net::ProxyResolverFactory::Request>* request) = 0;
  72. static std::unique_ptr<ProxyResolverV8TracingFactory> Create();
  73. };
  74. } // namespace proxy_resolver
  75. #endif // SERVICES_PROXY_RESOLVER_PROXY_RESOLVER_V8_TRACING_H_