proxy_resolver_factory.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // Copyright 2015 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. #ifndef NET_PROXY_RESOLUTION_PROXY_RESOLVER_FACTORY_H_
  5. #define NET_PROXY_RESOLUTION_PROXY_RESOLVER_FACTORY_H_
  6. #include <memory>
  7. #include <set>
  8. #include "base/memory/ref_counted.h"
  9. #include "net/base/completion_once_callback.h"
  10. #include "net/base/net_export.h"
  11. #include "net/proxy_resolution/pac_file_data.h"
  12. namespace net {
  13. class ProxyResolver;
  14. // ProxyResolverFactory is an interface for creating ProxyResolver instances.
  15. class NET_EXPORT ProxyResolverFactory {
  16. public:
  17. // A handle to a request. Deleting it will cancel the request.
  18. class Request {
  19. public:
  20. virtual ~Request() = default;
  21. };
  22. // See |expects_pac_bytes()| for the meaning of |expects_pac_bytes|.
  23. explicit ProxyResolverFactory(bool expects_pac_bytes);
  24. ProxyResolverFactory(const ProxyResolverFactory&) = delete;
  25. ProxyResolverFactory& operator=(const ProxyResolverFactory&) = delete;
  26. virtual ~ProxyResolverFactory();
  27. // Creates a new ProxyResolver. If the request will complete asynchronously,
  28. // it returns ERR_IO_PENDING and notifies the result by running |callback|.
  29. // If the result is OK, then |resolver| contains the ProxyResolver. In the
  30. // case of asynchronous completion |*request| is written to, and can be
  31. // deleted to cancel the request. All requests in progress are cancelled if
  32. // the ProxyResolverFactory is deleted.
  33. virtual int CreateProxyResolver(const scoped_refptr<PacFileData>& pac_script,
  34. std::unique_ptr<ProxyResolver>* resolver,
  35. CompletionOnceCallback callback,
  36. std::unique_ptr<Request>* request) = 0;
  37. // The PAC script backend can be specified to the ProxyResolverFactory either
  38. // via URL, or via the javascript text itself. If |expects_pac_bytes| is true,
  39. // then the PacFileData passed to CreateProxyResolver() should
  40. // contain the actual script bytes rather than just the URL.
  41. bool expects_pac_bytes() const { return expects_pac_bytes_; }
  42. private:
  43. bool expects_pac_bytes_;
  44. };
  45. } // namespace net
  46. #endif // NET_PROXY_RESOLUTION_PROXY_RESOLVER_FACTORY_H_