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