blob: ad88693cc8de60eddea46732e85f5cb008ae50f1 [file] [log] [blame]
Nicolas Arciniega9d383312020-02-18 23:36:411// 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 Arciniegabc393102020-03-20 23:47:575#ifndef NET_PROXY_RESOLUTION_CONFIGURED_PROXY_RESOLUTION_REQUEST_H_
6#define NET_PROXY_RESOLUTION_CONFIGURED_PROXY_RESOLUTION_REQUEST_H_
Nicolas Arciniega9d383312020-02-18 23:36:417
8#include <memory>
9#include <string>
10
Keishi Hattori0e45c022021-11-27 09:25:5211#include "base/memory/raw_ptr.h"
Nicolas Arciniega9d383312020-02-18 23:36:4112#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
21namespace net {
22
23class ProxyInfo;
24class ConfiguredProxyResolutionService;
25
Nicolas Arciniegac6720492020-03-28 02:35:2626// This is the concrete implementation of ProxyResolutionRequest used by
27// ConfiguredProxyResolutionService. Manages a single asynchronous proxy
28// resolution request.
Nicolas Arciniegabc393102020-03-20 23:47:5729class ConfiguredProxyResolutionRequest final : public ProxyResolutionRequest {
Nicolas Arciniega9d383312020-02-18 23:36:4130 public:
Nicolas Arciniegabc393102020-03-20 23:47:5731 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 Arciniega9d383312020-02-18 23:36:4139
Nicolas Arciniegabc393102020-03-20 23:47:5740 ConfiguredProxyResolutionRequest(const ConfiguredProxyResolutionRequest&) =
Nicolas Arciniega9d383312020-02-18 23:36:4141 delete;
Nicolas Arciniegabc393102020-03-20 23:47:5742 ConfiguredProxyResolutionRequest& operator=(
43 const ConfiguredProxyResolutionRequest&) = delete;
Nicolas Arciniega9d383312020-02-18 23:36:4144
Nicolas Arciniegabc393102020-03-20 23:47:5745 ~ConfiguredProxyResolutionRequest() override;
Nicolas Arciniega9d383312020-02-18 23:36:4146
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 Hattori0e45c022021-11-27 09:25:5284 raw_ptr<ConfiguredProxyResolutionService> service_;
Nicolas Arciniega9d383312020-02-18 23:36:4185 CompletionOnceCallback user_callback_;
Keishi Hattori0e45c022021-11-27 09:25:5286 raw_ptr<ProxyInfo> results_;
Nicolas Arciniega9d383312020-02-18 23:36:4187 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 Arciniegabc393102020-03-20 23:47:57100#endif // NET_PROXY_RESOLUTION_CONFIGURED_PROXY_RESOLUTION_REQUEST_H_