Upload upstream chromium 108.0.5359.1
[platform/framework/web/chromium-efl.git] / services / proxy_resolver / proxy_resolver_v8_tracing.h
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.
4
5 #ifndef SERVICES_PROXY_RESOLVER_PROXY_RESOLVER_V8_TRACING_H_
6 #define SERVICES_PROXY_RESOLVER_PROXY_RESOLVER_V8_TRACING_H_
7
8 #include <memory>
9
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"
14
15 namespace net {
16 class NetLogWithSource;
17 class NetworkAnonymizationKey;
18 }  // namespace net
19
20 namespace proxy_resolver {
21
22 class ProxyHostResolver;
23
24 // ProxyResolverV8Tracing is a non-blocking proxy resolver.
25 class ProxyResolverV8Tracing {
26  public:
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.
31   class Bindings {
32    public:
33     Bindings() {}
34
35     Bindings(const Bindings&) = delete;
36     Bindings& operator=(const Bindings&) = delete;
37
38     virtual ~Bindings() {}
39
40     // Invoked in response to an alert() call by the PAC script.
41     virtual void Alert(const std::u16string& message) = 0;
42
43     // Invoked in response to an error in the PAC script.
44     virtual void OnError(int line_number, const std::u16string& message) = 0;
45
46     // Returns a HostResolver to use for DNS resolution.
47     virtual ProxyHostResolver* GetHostResolver() = 0;
48
49     // Returns a NetLogWithSource to be passed to the HostResolver returned by
50     // GetHostResolver().
51     virtual net::NetLogWithSource GetNetLogWithSource() = 0;
52   };
53
54   virtual ~ProxyResolverV8Tracing() {}
55
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
60   // |*request|.
61   virtual void GetProxyForURL(
62       const GURL& url,
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;
68 };
69
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 {
76  public:
77   ProxyResolverV8TracingFactory() {}
78
79   ProxyResolverV8TracingFactory(const ProxyResolverV8TracingFactory&) = delete;
80   ProxyResolverV8TracingFactory& operator=(
81       const ProxyResolverV8TracingFactory&) = delete;
82
83   virtual ~ProxyResolverV8TracingFactory() = default;
84
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;
91
92   static std::unique_ptr<ProxyResolverV8TracingFactory> Create();
93 };
94
95 }  // namespace proxy_resolver
96
97 #endif  // SERVICES_PROXY_RESOLVER_PROXY_RESOLVER_V8_TRACING_H_