pac_file_fetcher.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // Copyright (c) 2011 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. // PacFileFetcher is an async interface for fetching a proxy auto config
  5. // script. It is specific to fetching a PAC script; enforces timeout, max-size,
  6. // status code.
  7. #ifndef NET_PROXY_RESOLUTION_PAC_FILE_FETCHER_H_
  8. #define NET_PROXY_RESOLUTION_PAC_FILE_FETCHER_H_
  9. #include <string>
  10. #include "net/base/completion_once_callback.h"
  11. #include "net/base/isolation_info.h"
  12. #include "net/base/net_export.h"
  13. #include "net/traffic_annotation/network_traffic_annotation.h"
  14. class GURL;
  15. namespace net {
  16. class URLRequestContext;
  17. // Interface for downloading a PAC script. Implementations can enforce
  18. // timeouts, maximum size constraints, content encoding, etc..
  19. class NET_EXPORT_PRIVATE PacFileFetcher {
  20. public:
  21. PacFileFetcher();
  22. PacFileFetcher(const PacFileFetcher&) = delete;
  23. PacFileFetcher& operator=(const PacFileFetcher&) = delete;
  24. // Destruction should cancel any outstanding requests.
  25. virtual ~PacFileFetcher();
  26. // Downloads the given PAC URL, and invokes |callback| on completion.
  27. // Returns OK on success, otherwise the error code. If the return code is
  28. // ERR_IO_PENDING, then the request completes asynchronously, and |callback|
  29. // will be invoked later with the final error code.
  30. // After synchronous or asynchronous completion with a result code of OK,
  31. // |*utf16_text| is filled with the response. On failure, the result text is
  32. // an empty string, and the result code is a network error. Some special
  33. // network errors that may occur are:
  34. //
  35. // ERR_TIMED_OUT -- the fetch took too long to complete.
  36. // ERR_FILE_TOO_BIG -- the response's body was too large.
  37. // ERR_HTTP_RESPONSE_CODE_FAILURE -- non-200 HTTP status code.
  38. // ERR_NOT_IMPLEMENTED -- the response required authentication.
  39. //
  40. // If the request is cancelled (either using the "Cancel()" method or by
  41. // deleting |this|), then no callback is invoked.
  42. //
  43. // Only one fetch is allowed to be outstanding at a time.
  44. virtual int Fetch(const GURL& url,
  45. std::u16string* utf16_text,
  46. CompletionOnceCallback callback,
  47. const NetworkTrafficAnnotationTag traffic_annotation) = 0;
  48. // Aborts the in-progress fetch (if any).
  49. virtual void Cancel() = 0;
  50. // Returns the request context that this fetcher uses to issue downloads,
  51. // or NULL.
  52. virtual URLRequestContext* GetRequestContext() const = 0;
  53. // Fails the in-progress fetch (if any) and future requests will fail
  54. // immediately. GetRequestContext() will always return nullptr after this is
  55. // called. Must be called before the URLRequestContext the fetcher was
  56. // created with is torn down.
  57. virtual void OnShutdown() = 0;
  58. const IsolationInfo& isolation_info() const { return isolation_info_; }
  59. private:
  60. // Transient IsolationInfo used to fetch PAC scripts and resolve hostnames.
  61. // Safe to reuse because delays for WPAD fetches don't provide information
  62. // to the web platform useful to attackers, and WPAD fetches uniformly
  63. // block all network requests.
  64. const IsolationInfo isolation_info_ = IsolationInfo::CreateTransient();
  65. };
  66. } // namespace net
  67. #endif // NET_PROXY_RESOLUTION_PAC_FILE_FETCHER_H_