1 // Copyright 2018 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_PROXY_LOOKUP_REQUEST_H_ 6 #define SERVICES_NETWORK_PROXY_LOOKUP_REQUEST_H_ 7 8 #include <stdint.h> 9 10 #include <memory> 11 12 #include "base/component_export.h" 13 #include "base/macros.h" 14 #include "mojo/public/cpp/bindings/pending_remote.h" 15 #include "mojo/public/cpp/bindings/remote.h" 16 #include "net/base/network_isolation_key.h" 17 #include "net/proxy_resolution/proxy_info.h" 18 #include "services/network/public/mojom/proxy_lookup_client.mojom.h" 19 #include "url/gurl.h" 20 21 namespace net { 22 23 class ProxyResolutionRequest; 24 25 } // namespace net 26 27 namespace network { 28 29 class NetworkContext; 30 31 // Single-use object to manage a proxy lookup. COMPONENT_EXPORT(NETWORK_SERVICE)32class COMPONENT_EXPORT(NETWORK_SERVICE) ProxyLookupRequest { 33 public: 34 ProxyLookupRequest( 35 mojo::PendingRemote<mojom::ProxyLookupClient> proxy_lookup_client, 36 NetworkContext* network_context, 37 const net::NetworkIsolationKey& network_isolation_key); 38 ~ProxyLookupRequest(); 39 40 // Starts looking up what proxy to use for |url|. On completion, will inform 41 // both the ProxyLookupClient and the NetworkContext that it has completed. 42 // On synchronous completion, will inform the NetworkContext of completion 43 // re-entrantly. If destroyed before the lookup completes, informs the client 44 // that the lookup was aborted. 45 void Start(const GURL& url); 46 47 private: 48 void OnResolveComplete(int result); 49 50 // Cancels |request_| and tells |network_context_| to delete |this|. 51 void DestroySelf(); 52 53 NetworkContext* const network_context_; 54 const net::NetworkIsolationKey network_isolation_key_; 55 mojo::Remote<mojom::ProxyLookupClient> proxy_lookup_client_; 56 57 net::ProxyInfo proxy_info_; 58 std::unique_ptr<net::ProxyResolutionRequest> request_; 59 60 DISALLOW_COPY_AND_ASSIGN(ProxyLookupRequest); 61 }; 62 63 } // namespace network 64 65 #endif // SERVICES_NETWORK_PROXY_LOOKUP_REQUEST_H_ 66