Nicolas Arciniega | 9d38331 | 2020-02-18 23:36:41 | [diff] [blame] | 1 | // Copyright 2020 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 | |
Nicolas Arciniega | bc39310 | 2020-03-20 23:47:57 | [diff] [blame] | 5 | #ifndef NET_PROXY_RESOLUTION_CONFIGURED_PROXY_RESOLUTION_REQUEST_H_ |
| 6 | #define NET_PROXY_RESOLUTION_CONFIGURED_PROXY_RESOLUTION_REQUEST_H_ |
Nicolas Arciniega | 9d38331 | 2020-02-18 23:36:41 | [diff] [blame] | 7 | |
| 8 | #include <memory> |
| 9 | #include <string> |
| 10 | |
Keishi Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 11 | #include "base/memory/raw_ptr.h" |
Nicolas Arciniega | 9d38331 | 2020-02-18 23:36:41 | [diff] [blame] | 12 | #include "base/time/time.h" |
| 13 | #include "net/base/completion_once_callback.h" |
| 14 | #include "net/base/network_isolation_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 | |
Nicolas Arciniega | c672049 | 2020-03-28 02:35:26 | [diff] [blame] | 26 | // This is the concrete implementation of ProxyResolutionRequest used by |
| 27 | // ConfiguredProxyResolutionService. Manages a single asynchronous proxy |
| 28 | // resolution request. |
Nicolas Arciniega | bc39310 | 2020-03-20 23:47:57 | [diff] [blame] | 29 | class ConfiguredProxyResolutionRequest final : public ProxyResolutionRequest { |
Nicolas Arciniega | 9d38331 | 2020-02-18 23:36:41 | [diff] [blame] | 30 | public: |
Nicolas Arciniega | bc39310 | 2020-03-20 23:47:57 | [diff] [blame] | 31 | ConfiguredProxyResolutionRequest( |
| 32 | ConfiguredProxyResolutionService* service, |
| 33 | const GURL& url, |
| 34 | const std::string& method, |
| 35 | const NetworkIsolationKey& network_isolation_key, |
| 36 | ProxyInfo* results, |
| 37 | const CompletionOnceCallback user_callback, |
| 38 | const NetLogWithSource& net_log); |
Nicolas Arciniega | 9d38331 | 2020-02-18 23:36:41 | [diff] [blame] | 39 | |
Nicolas Arciniega | bc39310 | 2020-03-20 23:47:57 | [diff] [blame] | 40 | ConfiguredProxyResolutionRequest(const ConfiguredProxyResolutionRequest&) = |
Nicolas Arciniega | 9d38331 | 2020-02-18 23:36:41 | [diff] [blame] | 41 | delete; |
Nicolas Arciniega | bc39310 | 2020-03-20 23:47:57 | [diff] [blame] | 42 | ConfiguredProxyResolutionRequest& operator=( |
| 43 | const ConfiguredProxyResolutionRequest&) = delete; |
Nicolas Arciniega | 9d38331 | 2020-02-18 23:36:41 | [diff] [blame] | 44 | |
Nicolas Arciniega | bc39310 | 2020-03-20 23:47:57 | [diff] [blame] | 45 | ~ConfiguredProxyResolutionRequest() override; |
Nicolas Arciniega | 9d38331 | 2020-02-18 23:36:41 | [diff] [blame] | 46 | |
| 47 | // Starts the resolve proxy request. |
| 48 | int Start(); |
| 49 | |
| 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. |
| 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 | |
| 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. |
Keishi Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 84 | raw_ptr<ConfiguredProxyResolutionService> service_; |
Nicolas Arciniega | 9d38331 | 2020-02-18 23:36:41 | [diff] [blame] | 85 | CompletionOnceCallback user_callback_; |
Keishi Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 86 | raw_ptr<ProxyInfo> results_; |
Nicolas Arciniega | 9d38331 | 2020-02-18 23:36:41 | [diff] [blame] | 87 | const GURL url_; |
| 88 | const std::string method_; |
| 89 | const NetworkIsolationKey network_isolation_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 | |
Nicolas Arciniega | bc39310 | 2020-03-20 23:47:57 | [diff] [blame] | 100 | #endif // NET_PROXY_RESOLUTION_CONFIGURED_PROXY_RESOLUTION_REQUEST_H_ |