• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_WIN_WINDOWS_SYSTEM_PROXY_RESOLUTION_REQUEST_H_
6 #define NET_PROXY_RESOLUTION_WIN_WINDOWS_SYSTEM_PROXY_RESOLUTION_REQUEST_H_
7 
8 #include <memory>
9 #include <string>
10 
11 #include "base/memory/raw_ptr.h"
12 #include "base/sequence_checker.h"
13 #include "base/time/time.h"
14 #include "net/base/completion_once_callback.h"
15 #include "net/base/net_export.h"
16 #include "net/log/net_log_with_source.h"
17 #include "net/proxy_resolution/proxy_resolution_request.h"
18 #include "net/proxy_resolution/win/windows_system_proxy_resolver.h"
19 #include "net/proxy_resolution/win/winhttp_status.h"
20 #include "url/gurl.h"
21 
22 namespace net {
23 
24 class ProxyInfo;
25 class ProxyList;
26 class WindowsSystemProxyResolutionService;
27 
28 // This is the concrete implementation of ProxyResolutionRequest used by
29 // WindowsSystemProxyResolutionService. Manages a single asynchronous proxy
30 // resolution request.
31 class NET_EXPORT WindowsSystemProxyResolutionRequest
32     : public ProxyResolutionRequest {
33  public:
34   // The |windows_system_proxy_resolver| is not saved by this object. Rather, it
35   // is simply used to kick off proxy resolution in a utility process from
36   // within the constructor. The |windows_system_proxy_resolver| is not needed
37   // after construction. Every other parameter is saved by this object. Details
38   // for each one of these saved parameters can be found below.
39   WindowsSystemProxyResolutionRequest(
40       WindowsSystemProxyResolutionService* service,
41       const GURL& url,
42       const std::string& method,
43       ProxyInfo* results,
44       const CompletionOnceCallback user_callback,
45       const NetLogWithSource& net_log,
46       WindowsSystemProxyResolver* windows_system_proxy_resolver);
47 
48   WindowsSystemProxyResolutionRequest(
49       const WindowsSystemProxyResolutionRequest&) = delete;
50   WindowsSystemProxyResolutionRequest& operator=(
51       const WindowsSystemProxyResolutionRequest&) = delete;
52 
53   ~WindowsSystemProxyResolutionRequest() override;
54 
55   // ProxyResolutionRequest
56   LoadState GetLoadState() const override;
57 
58   // Callback for when the cross-process proxy resolution has completed. The
59   // |proxy_list| is the list of proxies returned by WinHttp translated into
60   // Chromium-friendly terms. The |winhttp_status| describes the status of the
61   // proxy resolution request. If WinHttp fails for some reason, |windows_error|
62   // contains the specific error returned by WinHttp.
63   virtual void ProxyResolutionComplete(const ProxyList& proxy_list,
64                                        WinHttpStatus winhttp_status,
65                                        int windows_error);
66 
67   WindowsSystemProxyResolver::Request* GetProxyResolutionRequestForTesting();
68   void ResetProxyResolutionRequestForTesting();
69 
70  private:
71   // Cancels the callback from the resolver for a previously started proxy
72   // resolution.
73   void CancelResolveRequest();
74 
75   // Returns true if the request has been completed.
was_completed()76   bool was_completed() const { return user_callback_.is_null(); }
77 
78   // Note that Request holds a bare pointer to the
79   // WindowsSystemProxyResolutionService. Outstanding requests are cancelled
80   // during ~WindowsSystemProxyResolutionService, so this is guaranteed to be
81   // valid throughout the lifetime of this object.
82   raw_ptr<WindowsSystemProxyResolutionService> service_;
83   CompletionOnceCallback user_callback_;
84   raw_ptr<ProxyInfo> results_;
85   const GURL url_;
86   const std::string method_;
87   NetLogWithSource net_log_;
88   // Time when the request was created.  Stored here rather than in |results_|
89   // because the time in |results_| will be cleared.
90   base::TimeTicks creation_time_;
91 
92   // Manages the cross-process proxy resolution. Deleting this will cancel a
93   // pending proxy resolution. After a callback has been received via
94   // ProxyResolutionComplete(), this object will no longer do anything.
95   std::unique_ptr<WindowsSystemProxyResolver::Request>
96       proxy_resolution_request_;
97 
98   SEQUENCE_CHECKER(sequence_checker_);
99 };
100 
101 }  // namespace net
102 
103 #endif  // NET_PROXY_RESOLUTION_WIN_WINDOWS_SYSTEM_PROXY_RESOLUTION_REQUEST_H_
104