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