Upload upstream chromium 108.0.5359.1
[platform/framework/web/chromium-efl.git] / services / proxy_resolver / host_resolver_mojo.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_HOST_RESOLVER_MOJO_H_
6 #define SERVICES_PROXY_RESOLVER_HOST_RESOLVER_MOJO_H_
7
8 #include <memory>
9 #include <string>
10
11 #include "base/memory/raw_ptr.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/threading/thread_checker.h"
14 #include "net/proxy_resolution/proxy_resolve_dns_operation.h"
15 #include "services/proxy_resolver/proxy_host_resolver.h"
16 #include "services/proxy_resolver/proxy_host_resolver_cache.h"
17 #include "services/proxy_resolver/public/mojom/proxy_resolver.mojom.h"
18
19 namespace net {
20 class NetworkAnonymizationKey;
21 }  // namespace net
22
23 namespace proxy_resolver {
24
25 // A ProxyHostResolver implementation that converts requests to mojo types and
26 // forwards them to a mojo Impl interface.
27 class HostResolverMojo : public ProxyHostResolver {
28  public:
29   class Impl {
30    public:
31     virtual ~Impl() = default;
32     virtual void ResolveDns(
33         const std::string& hostname,
34         net::ProxyResolveDnsOperation operation,
35         const net::NetworkAnonymizationKey& network_anonymization_key,
36         mojo::PendingRemote<mojom::HostResolverRequestClient> client) = 0;
37   };
38
39   // |impl| must outlive |this|.
40   explicit HostResolverMojo(Impl* impl);
41
42   HostResolverMojo(const HostResolverMojo&) = delete;
43   HostResolverMojo& operator=(const HostResolverMojo&) = delete;
44
45   ~HostResolverMojo() override;
46
47   // ProxyHostResolver overrides.
48   std::unique_ptr<Request> CreateRequest(
49       const std::string& hostname,
50       net::ProxyResolveDnsOperation operation,
51       const net::NetworkAnonymizationKey& network_anonymization_key) override;
52
53  private:
54   class Job;
55   class RequestImpl;
56
57   const raw_ptr<Impl> impl_;
58
59   ProxyHostResolverCache host_cache_;
60   base::WeakPtrFactory<ProxyHostResolverCache> host_cache_weak_factory_{
61       &host_cache_};
62
63   base::ThreadChecker thread_checker_;
64 };
65
66 }  // namespace proxy_resolver
67
68 #endif  // SERVICES_PROXY_RESOLVER_HOST_RESOLVER_MOJO_H_