Upload upstream chromium 108.0.5359.1
[platform/framework/web/chromium-efl.git] / services / proxy_resolver / mojo_proxy_resolver_v8_tracing_bindings.h
1 // Copyright 2015 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_MOJO_PROXY_RESOLVER_V8_TRACING_BINDINGS_H_
6 #define SERVICES_PROXY_RESOLVER_MOJO_PROXY_RESOLVER_V8_TRACING_BINDINGS_H_
7
8 #include <memory>
9 #include <string>
10 #include <utility>
11
12 #include "base/check.h"
13 #include "base/memory/raw_ptr.h"
14 #include "base/strings/utf_string_conversions.h"
15 #include "base/threading/thread_checker.h"
16 #include "net/base/address_family.h"
17 #include "net/base/host_port_pair.h"
18 #include "net/base/network_anonymization_key.h"
19 #include "net/log/net_log_with_source.h"
20 #include "net/proxy_resolution/proxy_resolve_dns_operation.h"
21 #include "services/proxy_resolver/host_resolver_mojo.h"
22 #include "services/proxy_resolver/proxy_host_resolver.h"
23 #include "services/proxy_resolver/proxy_resolver_v8_tracing.h"
24 #include "services/proxy_resolver/public/mojom/proxy_resolver.mojom.h"
25
26 namespace proxy_resolver {
27
28 // An implementation of ProxyResolverV8Tracing::Bindings that forwards requests
29 // onto a Client mojo interface. Alert() and OnError() may be called from any
30 // thread; when they are called from another thread, the calls are proxied to
31 // the origin task runner. GetHostResolver() and GetNetLogWithSource() may only
32 // be called from the origin task runner.
33 template <typename Client>
34 class MojoProxyResolverV8TracingBindings
35     : public ProxyResolverV8Tracing::Bindings,
36       public HostResolverMojo::Impl {
37  public:
38   explicit MojoProxyResolverV8TracingBindings(Client* client)
39       : client_(client), host_resolver_(this) {
40     DCHECK(client_);
41   }
42
43   // ProxyResolverV8Tracing::Bindings overrides.
44   void Alert(const std::u16string& message) override {
45     DCHECK(thread_checker_.CalledOnValidThread());
46     client_->Alert(base::UTF16ToUTF8(message));
47   }
48
49   void OnError(int line_number, const std::u16string& message) override {
50     DCHECK(thread_checker_.CalledOnValidThread());
51     client_->OnError(line_number, base::UTF16ToUTF8(message));
52   }
53
54   ProxyHostResolver* GetHostResolver() override {
55     DCHECK(thread_checker_.CalledOnValidThread());
56     return &host_resolver_;
57   }
58
59   net::NetLogWithSource GetNetLogWithSource() override {
60     DCHECK(thread_checker_.CalledOnValidThread());
61     return net::NetLogWithSource();
62   }
63
64  private:
65   // HostResolverMojo::Impl override.
66   void ResolveDns(
67       const std::string& hostname,
68       net::ProxyResolveDnsOperation operation,
69       const net::NetworkAnonymizationKey& network_anonymization_key,
70       mojo::PendingRemote<mojom::HostResolverRequestClient> client) override {
71     DCHECK(thread_checker_.CalledOnValidThread());
72     client_->ResolveDns(hostname, operation, network_anonymization_key,
73                         std::move(client));
74   }
75
76   base::ThreadChecker thread_checker_;
77   const raw_ptr<Client> client_;
78   HostResolverMojo host_resolver_;
79 };
80
81 }  // namespace proxy_resolver
82
83 #endif  // SERVICES_PROXY_RESOLVER_MOJO_PROXY_RESOLVER_V8_TRACING_BINDINGS_H_