1 // Copyright 2020 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 NET_PROXY_RESOLUTION_CONFIGURED_PROXY_RESOLUTION_REQUEST_H_ 6 #define NET_PROXY_RESOLUTION_CONFIGURED_PROXY_RESOLUTION_REQUEST_H_ 7 8 #include <memory> 9 #include <string> 10 11 #include "base/memory/raw_ptr.h" 12 #include "base/time/time.h" 13 #include "net/base/completion_once_callback.h" 14 #include "net/base/network_anonymization_key.h" 15 #include "net/log/net_log_with_source.h" 16 #include "net/proxy_resolution/proxy_resolution_request.h" 17 #include "net/proxy_resolution/proxy_resolver.h" 18 #include "net/traffic_annotation/network_traffic_annotation.h" 19 #include "url/gurl.h" 20 21 namespace net { 22 23 class ProxyInfo; 24 class ConfiguredProxyResolutionService; 25 26 // This is the concrete implementation of ProxyResolutionRequest used by 27 // ConfiguredProxyResolutionService. Manages a single asynchronous proxy 28 // resolution request. 29 class ConfiguredProxyResolutionRequest final : public ProxyResolutionRequest { 30 public: 31 ConfiguredProxyResolutionRequest( 32 ConfiguredProxyResolutionService* service, 33 const GURL& url, 34 const std::string& method, 35 const NetworkAnonymizationKey& network_anonymization_key, 36 ProxyInfo* results, 37 const CompletionOnceCallback user_callback, 38 const NetLogWithSource& net_log); 39 40 ConfiguredProxyResolutionRequest(const ConfiguredProxyResolutionRequest&) = 41 delete; 42 ConfiguredProxyResolutionRequest& operator=( 43 const ConfiguredProxyResolutionRequest&) = delete; 44 45 ~ConfiguredProxyResolutionRequest() override; 46 47 // Starts the resolve proxy request. 48 int Start(); 49 is_started()50 bool is_started() const { 51 // Note that !! casts to bool. (VS gives a warning otherwise). 52 return !!resolve_job_.get(); 53 } 54 55 void StartAndCompleteCheckingForSynchronous(); 56 57 void CancelResolveJob(); 58 59 // Returns true if the request has been completed. was_completed()60 bool was_completed() const { return user_callback_.is_null(); } 61 62 // Callback for when the ProxyResolver request has completed. 63 void QueryComplete(int result_code); 64 65 // Helper to call after ProxyResolver completion (both synchronous and 66 // asynchronous). Fixes up the result that is to be returned to user. 67 int QueryDidComplete(int result_code); 68 69 // Helper to call if the request completes synchronously, since in that case 70 // the request will not be added to |pending_requests_| (in 71 // |ConfiguredProxyResolutionService|). 72 int QueryDidCompleteSynchronously(int result_code); 73 net_log()74 NetLogWithSource* net_log() { return &net_log_; } 75 76 // Request implementation: 77 LoadState GetLoadState() const override; 78 79 private: 80 // Note that Request holds a bare pointer to the 81 // ConfiguredProxyResolutionService. Outstanding requests are cancelled during 82 // ~ConfiguredProxyResolutionService, so this is guaranteed to be valid 83 // throughout our lifetime. 84 raw_ptr<ConfiguredProxyResolutionService> service_; 85 CompletionOnceCallback user_callback_; 86 raw_ptr<ProxyInfo> results_; 87 const GURL url_; 88 const std::string method_; 89 const NetworkAnonymizationKey network_anonymization_key_; 90 std::unique_ptr<ProxyResolver::Request> resolve_job_; 91 MutableNetworkTrafficAnnotationTag traffic_annotation_; 92 NetLogWithSource net_log_; 93 // Time when the request was created. Stored here rather than in |results_| 94 // because the time in |results_| will be cleared. 95 base::TimeTicks creation_time_; 96 }; 97 98 } // namespace net 99 100 #endif // NET_PROXY_RESOLUTION_CONFIGURED_PROXY_RESOLUTION_REQUEST_H_ 101