blob: 7838bf5b3a46200955424c71b984fd0304044175 [file] [log] [blame]
[email protected]5d456c5c2012-04-10 16:57:061// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]7258def2011-05-17 19:53:002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Eric Romand44cc642018-11-14 02:04:485#ifndef NET_PROXY_RESOLUTION_DHCP_PAC_FILE_FETCHER_H_
6#define NET_PROXY_RESOLUTION_DHCP_PAC_FILE_FETCHER_H_
[email protected]7258def2011-05-17 19:53:007
Jan Wilken Dörriead587c32021-03-11 14:09:278#include <string>
9
[email protected]7258def2011-05-17 19:53:0010#include "base/compiler_specific.h"
Bence Békycc5b88a2018-05-25 20:24:1711#include "net/base/completion_once_callback.h"
[email protected]172da1b2011-08-12 15:52:2612#include "net/base/net_export.h"
Lily Houghton582d4622018-01-22 22:43:4013#include "net/proxy_resolution/pac_file_fetcher.h"
Ramin Halavatibb8c4d82018-03-16 08:04:3114#include "net/traffic_annotation/network_traffic_annotation.h"
[email protected]f89276a72013-07-12 06:41:5415#include "url/gurl.h"
[email protected]7258def2011-05-17 19:53:0016
17namespace net {
18
Eric Roman1810d432018-03-03 00:11:1519class NetLogWithSource;
20
Lily Houghton99597862018-03-07 16:40:4221// Interface for classes that can fetch a PAC file as configured via DHCP.
[email protected]7258def2011-05-17 19:53:0022//
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 Houghton99597862018-03-07 16:40:4229class NET_EXPORT_PRIVATE DhcpPacFileFetcher {
[email protected]7258def2011-05-17 19:53:0030 public:
Peter Boström293b1342021-09-22 17:31:4331 DhcpPacFileFetcher(const DhcpPacFileFetcher&) = delete;
32 DhcpPacFileFetcher& operator=(const DhcpPacFileFetcher&) = delete;
33
[email protected]7258def2011-05-17 19:53:0034 // Destruction should cancel any outstanding requests.
Lily Houghton99597862018-03-07 16:40:4235 virtual ~DhcpPacFileFetcher();
[email protected]7258def2011-05-17 19:53:0036
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 Romana22b1f72019-09-05 19:35:0458 // ERR_HTTP_RESPONSE_CODE_FAILURE -- script downloaded but returned a
59 // non-200 HTTP response.
[email protected]7258def2011-05-17 19:53:0060 // 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örrie739ccc212021-03-11 18:13:0566 virtual int Fetch(std::u16string* utf16_text,
Bence Békycc5b88a2018-05-25 20:24:1767 CompletionOnceCallback callback,
Ramin Halavatibb8c4d82018-03-16 08:04:3168 const NetLogWithSource& net_log,
69 const NetworkTrafficAnnotationTag traffic_annotation) = 0;
[email protected]7258def2011-05-17 19:53:0070
71 // Aborts the in-progress fetch (if any).
72 virtual void Cancel() = 0;
73
Matt Menke3b1ea4852019-06-28 22:39:3574 // 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.
mmenkeed8d7e432017-05-03 16:48:3377 virtual void OnShutdown() = 0;
78
[email protected]7258def2011-05-17 19:53:0079 // 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 Houghton99597862018-03-07 16:40:4288 DhcpPacFileFetcher();
[email protected]7258def2011-05-17 19:53:0089};
90
91// A do-nothing retriever, always returns synchronously with
92// ERR_NOT_IMPLEMENTED result and empty text.
Lily Houghton99597862018-03-07 16:40:4293class NET_EXPORT_PRIVATE DoNothingDhcpPacFileFetcher
94 : public DhcpPacFileFetcher {
[email protected]7258def2011-05-17 19:53:0095 public:
Lily Houghton99597862018-03-07 16:40:4296 DoNothingDhcpPacFileFetcher();
Peter Boström293b1342021-09-22 17:31:4397
98 DoNothingDhcpPacFileFetcher(const DoNothingDhcpPacFileFetcher&) = delete;
99 DoNothingDhcpPacFileFetcher& operator=(const DoNothingDhcpPacFileFetcher&) =
100 delete;
101
Lily Houghton99597862018-03-07 16:40:42102 ~DoNothingDhcpPacFileFetcher() override;
[email protected]7258def2011-05-17 19:53:00103
Jan Wilken Dörrie739ccc212021-03-11 18:13:05104 int Fetch(std::u16string* utf16_text,
Bence Békycc5b88a2018-05-25 20:24:17105 CompletionOnceCallback callback,
Ramin Halavatibb8c4d82018-03-16 08:04:31106 const NetLogWithSource& net_log,
107 const NetworkTrafficAnnotationTag traffic_annotation) override;
dchengb03027d2014-10-21 12:00:20108 void Cancel() override;
mmenkeed8d7e432017-05-03 16:48:33109 void OnShutdown() override;
dchengb03027d2014-10-21 12:00:20110 const GURL& GetPacURL() const override;
mmenke14085ad2017-06-15 21:53:54111 std::string GetFetcherName() const override;
dchengb03027d2014-10-21 12:00:20112
[email protected]7258def2011-05-17 19:53:00113 private:
114 GURL gurl_;
[email protected]7258def2011-05-17 19:53:00115};
116
117} // namespace net
118
Eric Romand44cc642018-11-14 02:04:48119#endif // NET_PROXY_RESOLUTION_DHCP_PAC_FILE_FETCHER_H_