[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 | |
Lily Houghton | 9844d32 | 2018-01-20 05:44:01 | [diff] [blame] | 5 | #ifndef NET_PROXY_DHCP_PAC_FILE_FETCHER_H_ |
| 6 | #define NET_PROXY_DHCP_PAC_FILE_FETCHER_H_ |
[email protected] | 7258def | 2011-05-17 19:53:00 | [diff] [blame] | 7 | |
[email protected] | 7258def | 2011-05-17 19:53:00 | [diff] [blame] | 8 | #include "base/compiler_specific.h" |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 9 | #include "base/macros.h" |
[email protected] | fc9be580 | 2013-06-11 10:56:51 | [diff] [blame] | 10 | #include "base/strings/string16.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: |
| 31 | // Destruction should cancel any outstanding requests. |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 32 | virtual ~DhcpPacFileFetcher(); |
[email protected] | 7258def | 2011-05-17 19:53:00 | [diff] [blame] | 33 | |
| 34 | // Attempts to retrieve the most appropriate PAC script configured via DHCP, |
| 35 | // and invokes |callback| on completion. |
| 36 | // |
| 37 | // Returns OK on success, otherwise the error code. If the return code is |
| 38 | // ERR_IO_PENDING, then the request completes asynchronously, and |callback| |
| 39 | // will be invoked later with the final error code. |
| 40 | // |
| 41 | // After synchronous or asynchronous completion with a result code of OK, |
| 42 | // |*utf16_text| is filled with the response. On failure, the result text is |
| 43 | // an empty string, and the result code is a network error. Some special |
| 44 | // network errors that may occur are: |
| 45 | // |
| 46 | // ERR_PAC_NOT_IN_DHCP -- no script configured in DHCP. |
| 47 | // |
| 48 | // The following all indicate there was one or more script configured |
| 49 | // in DHCP but all failed to download, and the error for the most |
| 50 | // preferred adapter that had a script configured was what the error |
| 51 | // code says: |
| 52 | // |
| 53 | // ERR_TIMED_OUT -- fetch took too long to complete. |
| 54 | // ERR_FILE_TOO_BIG -- response body was too large. |
| 55 | // ERR_PAC_STATUS_NOT_OK -- script failed to download. |
| 56 | // ERR_NOT_IMPLEMENTED -- script required authentication. |
| 57 | // |
| 58 | // If the request is cancelled (either using the "Cancel()" method or by |
| 59 | // deleting |this|), then no callback is invoked. |
| 60 | // |
| 61 | // Only one fetch is allowed to be outstanding at a time. |
[email protected] | 42cba2fb | 2013-03-29 19:58:57 | [diff] [blame] | 62 | virtual int Fetch(base::string16* utf16_text, |
Bence Béky | cc5b88a | 2018-05-25 20:24:17 | [diff] [blame^] | 63 | CompletionOnceCallback callback, |
Ramin Halavati | bb8c4d8 | 2018-03-16 08:04:31 | [diff] [blame] | 64 | const NetLogWithSource& net_log, |
| 65 | const NetworkTrafficAnnotationTag traffic_annotation) = 0; |
[email protected] | 7258def | 2011-05-17 19:53:00 | [diff] [blame] | 66 | |
| 67 | // Aborts the in-progress fetch (if any). |
| 68 | virtual void Cancel() = 0; |
| 69 | |
mmenke | ed8d7e43 | 2017-05-03 16:48:33 | [diff] [blame] | 70 | // Fails the in-progress fetch (if any) and future requests will fail |
| 71 | // immediately. Must be called before the URLRequestContext the fetcher was |
| 72 | // created with is torn down. |
| 73 | virtual void OnShutdown() = 0; |
| 74 | |
[email protected] | 7258def | 2011-05-17 19:53:00 | [diff] [blame] | 75 | // After successful completion of |Fetch()|, this will return the URL |
| 76 | // retrieved from DHCP. It is reset if/when |Fetch()| is called again. |
| 77 | virtual const GURL& GetPacURL() const = 0; |
| 78 | |
| 79 | // Intended for unit tests only, so they can test that factories return |
| 80 | // the right types under given circumstances. |
| 81 | virtual std::string GetFetcherName() const; |
| 82 | |
| 83 | protected: |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 84 | DhcpPacFileFetcher(); |
[email protected] | 7258def | 2011-05-17 19:53:00 | [diff] [blame] | 85 | |
| 86 | private: |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 87 | DISALLOW_COPY_AND_ASSIGN(DhcpPacFileFetcher); |
[email protected] | 7258def | 2011-05-17 19:53:00 | [diff] [blame] | 88 | }; |
| 89 | |
| 90 | // A do-nothing retriever, always returns synchronously with |
| 91 | // ERR_NOT_IMPLEMENTED result and empty text. |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 92 | class NET_EXPORT_PRIVATE DoNothingDhcpPacFileFetcher |
| 93 | : public DhcpPacFileFetcher { |
[email protected] | 7258def | 2011-05-17 19:53:00 | [diff] [blame] | 94 | public: |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 95 | DoNothingDhcpPacFileFetcher(); |
| 96 | ~DoNothingDhcpPacFileFetcher() override; |
[email protected] | 7258def | 2011-05-17 19:53:00 | [diff] [blame] | 97 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 98 | int Fetch(base::string16* utf16_text, |
Bence Béky | cc5b88a | 2018-05-25 20:24:17 | [diff] [blame^] | 99 | CompletionOnceCallback callback, |
Ramin Halavati | bb8c4d8 | 2018-03-16 08:04:31 | [diff] [blame] | 100 | const NetLogWithSource& net_log, |
| 101 | const NetworkTrafficAnnotationTag traffic_annotation) override; |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 102 | void Cancel() override; |
mmenke | ed8d7e43 | 2017-05-03 16:48:33 | [diff] [blame] | 103 | void OnShutdown() override; |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 104 | const GURL& GetPacURL() const override; |
mmenke | 14085ad | 2017-06-15 21:53:54 | [diff] [blame] | 105 | std::string GetFetcherName() const override; |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 106 | |
[email protected] | 7258def | 2011-05-17 19:53:00 | [diff] [blame] | 107 | private: |
| 108 | GURL gurl_; |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 109 | DISALLOW_COPY_AND_ASSIGN(DoNothingDhcpPacFileFetcher); |
[email protected] | 7258def | 2011-05-17 19:53:00 | [diff] [blame] | 110 | }; |
| 111 | |
| 112 | } // namespace net |
| 113 | |
Lily Houghton | 9844d32 | 2018-01-20 05:44:01 | [diff] [blame] | 114 | #endif // NET_PROXY_DHCP_PAC_FILE_FETCHER_H_ |