mojo_host_resolver_impl.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // Copyright 2015 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_NETWORK_MOJO_HOST_RESOLVER_IMPL_H_
  5. #define SERVICES_NETWORK_MOJO_HOST_RESOLVER_IMPL_H_
  6. #include <list>
  7. #include <memory>
  8. #include <string>
  9. #include "base/component_export.h"
  10. #include "base/memory/raw_ptr.h"
  11. #include "base/threading/thread_checker.h"
  12. #include "mojo/public/cpp/bindings/pending_remote.h"
  13. #include "net/log/net_log_with_source.h"
  14. #include "services/proxy_resolver/public/mojom/proxy_resolver.mojom.h"
  15. namespace net {
  16. class HostResolver;
  17. class NetworkIsolationKey;
  18. } // namespace net
  19. namespace network {
  20. // MojoHostResolverImpl handles mojo host resolution requests from the Proxy
  21. // Resolver Service. Inbound Mojo requests are sent to the HostResolver passed
  22. // into the constructor. When destroyed, any outstanding resolver requests are
  23. // cancelled. If a request's HostResolverRequestClient is shut down, the
  24. // associated resolver request is cancelled.
  25. //
  26. // TODO(mmenke): Rename this to something that makes it clearer that this is
  27. // just for use by the ProxyResolverFactoryMojo, or merge it into
  28. // ProxyResolverFactoryMojo.
  29. class COMPONENT_EXPORT(NETWORK_SERVICE) MojoHostResolverImpl {
  30. public:
  31. // |resolver| is expected to outlive |this|.
  32. MojoHostResolverImpl(net::HostResolver* resolver,
  33. const net::NetLogWithSource& net_log);
  34. MojoHostResolverImpl(const MojoHostResolverImpl&) = delete;
  35. MojoHostResolverImpl& operator=(const MojoHostResolverImpl&) = delete;
  36. ~MojoHostResolverImpl();
  37. void Resolve(
  38. const std::string& hostname,
  39. const net::NetworkIsolationKey& network_isolation_key,
  40. bool is_ex,
  41. mojo::PendingRemote<proxy_resolver::mojom::HostResolverRequestClient>
  42. client);
  43. bool request_in_progress() { return !pending_jobs_.empty(); }
  44. private:
  45. class Job;
  46. // Removes |job| from the set of pending jobs.
  47. void DeleteJob(std::list<Job>::iterator job);
  48. // Resolver for resolving incoming requests. Not owned.
  49. raw_ptr<net::HostResolver> resolver_;
  50. // The NetLogWithSource to be passed to |resolver_| for all requests.
  51. const net::NetLogWithSource net_log_;
  52. // All pending jobs, so they can be cancelled when this service is destroyed.
  53. std::list<Job> pending_jobs_;
  54. base::ThreadChecker thread_checker_;
  55. };
  56. } // namespace network
  57. #endif // SERVICES_NETWORK_MOJO_HOST_RESOLVER_IMPL_H_