blob: ee49706aa1b3114839cc9e8102f9dce8ab5d07c9 [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
Lily Houghton9844d322018-01-20 05:44:015#ifndef NET_PROXY_DHCP_PAC_FILE_FETCHER_H_
6#define NET_PROXY_DHCP_PAC_FILE_FETCHER_H_
[email protected]7258def2011-05-17 19:53:007
[email protected]7258def2011-05-17 19:53:008#include "base/compiler_specific.h"
Avi Drissman13fc8932015-12-20 04:40:469#include "base/macros.h"
[email protected]fc9be5802013-06-11 10:56:5110#include "base/strings/string16.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:
31 // Destruction should cancel any outstanding requests.
Lily Houghton99597862018-03-07 16:40:4232 virtual ~DhcpPacFileFetcher();
[email protected]7258def2011-05-17 19:53:0033
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]42cba2fb2013-03-29 19:58:5762 virtual int Fetch(base::string16* utf16_text,
Bence Békycc5b88a2018-05-25 20:24:1763 CompletionOnceCallback callback,
Ramin Halavatibb8c4d82018-03-16 08:04:3164 const NetLogWithSource& net_log,
65 const NetworkTrafficAnnotationTag traffic_annotation) = 0;
[email protected]7258def2011-05-17 19:53:0066
67 // Aborts the in-progress fetch (if any).
68 virtual void Cancel() = 0;
69
mmenkeed8d7e432017-05-03 16:48:3370 // 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]7258def2011-05-17 19:53:0075 // 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 Houghton99597862018-03-07 16:40:4284 DhcpPacFileFetcher();
[email protected]7258def2011-05-17 19:53:0085
86 private:
Lily Houghton99597862018-03-07 16:40:4287 DISALLOW_COPY_AND_ASSIGN(DhcpPacFileFetcher);
[email protected]7258def2011-05-17 19:53:0088};
89
90// A do-nothing retriever, always returns synchronously with
91// ERR_NOT_IMPLEMENTED result and empty text.
Lily Houghton99597862018-03-07 16:40:4292class NET_EXPORT_PRIVATE DoNothingDhcpPacFileFetcher
93 : public DhcpPacFileFetcher {
[email protected]7258def2011-05-17 19:53:0094 public:
Lily Houghton99597862018-03-07 16:40:4295 DoNothingDhcpPacFileFetcher();
96 ~DoNothingDhcpPacFileFetcher() override;
[email protected]7258def2011-05-17 19:53:0097
dchengb03027d2014-10-21 12:00:2098 int Fetch(base::string16* utf16_text,
Bence Békycc5b88a2018-05-25 20:24:1799 CompletionOnceCallback callback,
Ramin Halavatibb8c4d82018-03-16 08:04:31100 const NetLogWithSource& net_log,
101 const NetworkTrafficAnnotationTag traffic_annotation) override;
dchengb03027d2014-10-21 12:00:20102 void Cancel() override;
mmenkeed8d7e432017-05-03 16:48:33103 void OnShutdown() override;
dchengb03027d2014-10-21 12:00:20104 const GURL& GetPacURL() const override;
mmenke14085ad2017-06-15 21:53:54105 std::string GetFetcherName() const override;
dchengb03027d2014-10-21 12:00:20106
[email protected]7258def2011-05-17 19:53:00107 private:
108 GURL gurl_;
Lily Houghton99597862018-03-07 16:40:42109 DISALLOW_COPY_AND_ASSIGN(DoNothingDhcpPacFileFetcher);
[email protected]7258def2011-05-17 19:53:00110};
111
112} // namespace net
113
Lily Houghton9844d322018-01-20 05:44:01114#endif // NET_PROXY_DHCP_PAC_FILE_FETCHER_H_