[email protected] | 5d456c5c | 2012-04-10 16:57:06 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 7258def | 2011-05-17 19:53:00 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Eric Roman | d44cc64 | 2018-11-14 02:04:48 | [diff] [blame] | 5 | #ifndef NET_PROXY_RESOLUTION_DHCP_PAC_FILE_FETCHER_H_ |
| 6 | #define NET_PROXY_RESOLUTION_DHCP_PAC_FILE_FETCHER_H_ |
[email protected] | 7258def | 2011-05-17 19:53:00 | [diff] [blame] | 7 | |
Jan Wilken Dörrie | ad587c3 | 2021-03-11 14:09:27 | [diff] [blame] | 8 | #include <string> |
| 9 | |
[email protected] | 7258def | 2011-05-17 19:53:00 | [diff] [blame] | 10 | #include "base/compiler_specific.h" |
Bence Béky | cc5b88a | 2018-05-25 20:24:17 | [diff] [blame] | 11 | #include "net/base/completion_once_callback.h" |
[email protected] | 172da1b | 2011-08-12 15:52:26 | [diff] [blame] | 12 | #include "net/base/net_export.h" |
Lily Houghton | 582d462 | 2018-01-22 22:43:40 | [diff] [blame] | 13 | #include "net/proxy_resolution/pac_file_fetcher.h" |
Ramin Halavati | bb8c4d8 | 2018-03-16 08:04:31 | [diff] [blame] | 14 | #include "net/traffic_annotation/network_traffic_annotation.h" |
[email protected] | f89276a7 | 2013-07-12 06:41:54 | [diff] [blame] | 15 | #include "url/gurl.h" |
[email protected] | 7258def | 2011-05-17 19:53:00 | [diff] [blame] | 16 | |
| 17 | namespace net { |
| 18 | |
Eric Roman | 1810d43 | 2018-03-03 00:11:15 | [diff] [blame] | 19 | class NetLogWithSource; |
| 20 | |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 21 | // Interface for classes that can fetch a PAC file as configured via DHCP. |
[email protected] | 7258def | 2011-05-17 19:53:00 | [diff] [blame] | 22 | // |
| 23 | // The Fetch method on this interface tries to retrieve the most appropriate |
| 24 | // PAC script configured via DHCP. |
| 25 | // |
| 26 | // Normally there are zero or one DHCP scripts configured, but in the |
| 27 | // presence of multiple adapters with DHCP enabled, the fetcher resolves |
| 28 | // which PAC script to use if one or more are available. |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 29 | class NET_EXPORT_PRIVATE DhcpPacFileFetcher { |
[email protected] | 7258def | 2011-05-17 19:53:00 | [diff] [blame] | 30 | public: |
Peter Boström | 293b134 | 2021-09-22 17:31:43 | [diff] [blame] | 31 | DhcpPacFileFetcher(const DhcpPacFileFetcher&) = delete; |
| 32 | DhcpPacFileFetcher& operator=(const DhcpPacFileFetcher&) = delete; |
| 33 | |
[email protected] | 7258def | 2011-05-17 19:53:00 | [diff] [blame] | 34 | // Destruction should cancel any outstanding requests. |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 35 | virtual ~DhcpPacFileFetcher(); |
[email protected] | 7258def | 2011-05-17 19:53:00 | [diff] [blame] | 36 | |
| 37 | // Attempts to retrieve the most appropriate PAC script configured via DHCP, |
| 38 | // and invokes |callback| on completion. |
| 39 | // |
| 40 | // Returns OK on success, otherwise the error code. If the return code is |
| 41 | // ERR_IO_PENDING, then the request completes asynchronously, and |callback| |
| 42 | // will be invoked later with the final error code. |
| 43 | // |
| 44 | // After synchronous or asynchronous completion with a result code of OK, |
| 45 | // |*utf16_text| is filled with the response. On failure, the result text is |
| 46 | // an empty string, and the result code is a network error. Some special |
| 47 | // network errors that may occur are: |
| 48 | // |
| 49 | // ERR_PAC_NOT_IN_DHCP -- no script configured in DHCP. |
| 50 | // |
| 51 | // The following all indicate there was one or more script configured |
| 52 | // in DHCP but all failed to download, and the error for the most |
| 53 | // preferred adapter that had a script configured was what the error |
| 54 | // code says: |
| 55 | // |
| 56 | // ERR_TIMED_OUT -- fetch took too long to complete. |
| 57 | // ERR_FILE_TOO_BIG -- response body was too large. |
Eric Roman | a22b1f7 | 2019-09-05 19:35:04 | [diff] [blame] | 58 | // ERR_HTTP_RESPONSE_CODE_FAILURE -- script downloaded but returned a |
| 59 | // non-200 HTTP response. |
[email protected] | 7258def | 2011-05-17 19:53:00 | [diff] [blame] | 60 | // ERR_NOT_IMPLEMENTED -- script required authentication. |
| 61 | // |
| 62 | // If the request is cancelled (either using the "Cancel()" method or by |
| 63 | // deleting |this|), then no callback is invoked. |
| 64 | // |
| 65 | // Only one fetch is allowed to be outstanding at a time. |
Jan Wilken Dörrie | 739ccc21 | 2021-03-11 18:13:05 | [diff] [blame] | 66 | virtual int Fetch(std::u16string* utf16_text, |
Bence Béky | cc5b88a | 2018-05-25 20:24:17 | [diff] [blame] | 67 | CompletionOnceCallback callback, |
Ramin Halavati | bb8c4d8 | 2018-03-16 08:04:31 | [diff] [blame] | 68 | const NetLogWithSource& net_log, |
| 69 | const NetworkTrafficAnnotationTag traffic_annotation) = 0; |
[email protected] | 7258def | 2011-05-17 19:53:00 | [diff] [blame] | 70 | |
| 71 | // Aborts the in-progress fetch (if any). |
| 72 | virtual void Cancel() = 0; |
| 73 | |
Matt Menke | 3b1ea485 | 2019-06-28 22:39:35 | [diff] [blame] | 74 | // Cancels the in-progress fetch (if any), without invoking its callback. |
| 75 | // Future requests will fail immediately. Must be called before the |
| 76 | // URLRequestContext the fetcher was created with is torn down. |
mmenke | ed8d7e43 | 2017-05-03 16:48:33 | [diff] [blame] | 77 | virtual void OnShutdown() = 0; |
| 78 | |
[email protected] | 7258def | 2011-05-17 19:53:00 | [diff] [blame] | 79 | // After successful completion of |Fetch()|, this will return the URL |
| 80 | // retrieved from DHCP. It is reset if/when |Fetch()| is called again. |
| 81 | virtual const GURL& GetPacURL() const = 0; |
| 82 | |
| 83 | // Intended for unit tests only, so they can test that factories return |
| 84 | // the right types under given circumstances. |
| 85 | virtual std::string GetFetcherName() const; |
| 86 | |
| 87 | protected: |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 88 | DhcpPacFileFetcher(); |
[email protected] | 7258def | 2011-05-17 19:53:00 | [diff] [blame] | 89 | }; |
| 90 | |
| 91 | // A do-nothing retriever, always returns synchronously with |
| 92 | // ERR_NOT_IMPLEMENTED result and empty text. |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 93 | class NET_EXPORT_PRIVATE DoNothingDhcpPacFileFetcher |
| 94 | : public DhcpPacFileFetcher { |
[email protected] | 7258def | 2011-05-17 19:53:00 | [diff] [blame] | 95 | public: |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 96 | DoNothingDhcpPacFileFetcher(); |
Peter Boström | 293b134 | 2021-09-22 17:31:43 | [diff] [blame] | 97 | |
| 98 | DoNothingDhcpPacFileFetcher(const DoNothingDhcpPacFileFetcher&) = delete; |
| 99 | DoNothingDhcpPacFileFetcher& operator=(const DoNothingDhcpPacFileFetcher&) = |
| 100 | delete; |
| 101 | |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 102 | ~DoNothingDhcpPacFileFetcher() override; |
[email protected] | 7258def | 2011-05-17 19:53:00 | [diff] [blame] | 103 | |
Jan Wilken Dörrie | 739ccc21 | 2021-03-11 18:13:05 | [diff] [blame] | 104 | int Fetch(std::u16string* utf16_text, |
Bence Béky | cc5b88a | 2018-05-25 20:24:17 | [diff] [blame] | 105 | CompletionOnceCallback callback, |
Ramin Halavati | bb8c4d8 | 2018-03-16 08:04:31 | [diff] [blame] | 106 | const NetLogWithSource& net_log, |
| 107 | const NetworkTrafficAnnotationTag traffic_annotation) override; |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 108 | void Cancel() override; |
mmenke | ed8d7e43 | 2017-05-03 16:48:33 | [diff] [blame] | 109 | void OnShutdown() override; |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 110 | const GURL& GetPacURL() const override; |
mmenke | 14085ad | 2017-06-15 21:53:54 | [diff] [blame] | 111 | std::string GetFetcherName() const override; |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 112 | |
[email protected] | 7258def | 2011-05-17 19:53:00 | [diff] [blame] | 113 | private: |
| 114 | GURL gurl_; |
[email protected] | 7258def | 2011-05-17 19:53:00 | [diff] [blame] | 115 | }; |
| 116 | |
| 117 | } // namespace net |
| 118 | |
Eric Roman | d44cc64 | 2018-11-14 02:04:48 | [diff] [blame] | 119 | #endif // NET_PROXY_RESOLUTION_DHCP_PAC_FILE_FETCHER_H_ |