dhcp_pac_file_fetcher_mojo.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // Copyright 2019 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 SERVICES_NETWORK_DHCP_PAC_FILE_FETCHER_MOJO_H_
  5. #define SERVICES_NETWORK_DHCP_PAC_FILE_FETCHER_MOJO_H_
  6. #include <memory>
  7. #include "base/component_export.h"
  8. #include "base/memory/ref_counted.h"
  9. #include "base/memory/weak_ptr.h"
  10. #include "mojo/public/cpp/bindings/pending_remote.h"
  11. #include "mojo/public/cpp/bindings/remote.h"
  12. #include "net/base/completion_once_callback.h"
  13. #include "net/proxy_resolution/dhcp_pac_file_fetcher.h"
  14. #include "net/traffic_annotation/network_traffic_annotation.h"
  15. #include "services/network/public/mojom/dhcp_wpad_url_client.mojom.h"
  16. #include "url/gurl.h"
  17. namespace net {
  18. class URLRequestContext;
  19. class NetLogWithSource;
  20. class PacFileFetcher;
  21. } // namespace net
  22. namespace network {
  23. // Implementation of DhcpPacFileFetcher that gets the URL of the PAC file from
  24. // the default network over a mojo pipe. The default network points to a single
  25. // PAC file URL, provided by Shill, as reported over DHCP.
  26. // Currently only used on ChromeOS.
  27. class COMPONENT_EXPORT(NETWORK_SERVICE) DhcpPacFileFetcherMojo
  28. : public net::DhcpPacFileFetcher {
  29. public:
  30. DhcpPacFileFetcherMojo(net::URLRequestContext* url_request_context,
  31. mojo::PendingRemote<network::mojom::DhcpWpadUrlClient>
  32. dhcp_wpad_url_client);
  33. DhcpPacFileFetcherMojo(const DhcpPacFileFetcherMojo&) = delete;
  34. DhcpPacFileFetcherMojo& operator=(const DhcpPacFileFetcherMojo&) = delete;
  35. ~DhcpPacFileFetcherMojo() override;
  36. // DhcpPacFileFetcher implementation
  37. int Fetch(std::u16string* utf16_text,
  38. net::CompletionOnceCallback callback,
  39. const net::NetLogWithSource& net_log,
  40. const net::NetworkTrafficAnnotationTag traffic_annotation) override;
  41. void Cancel() override;
  42. void OnShutdown() override;
  43. const GURL& GetPacURL() const override;
  44. std::string GetFetcherName() const override;
  45. void SetPacFileFetcherForTesting(
  46. std::unique_ptr<net::PacFileFetcher> pac_file_fetcher);
  47. private:
  48. void ContinueFetch(std::u16string* utf16_text,
  49. const net::NetworkTrafficAnnotationTag traffic_annotation,
  50. std::string pac_url);
  51. void OnFetchCompleted(int result);
  52. void OnPacUrlReceived(const std::string& url);
  53. net::CompletionOnceCallback callback_;
  54. std::u16string* utf16_text_;
  55. GURL pac_url_;
  56. net::MutableNetworkTrafficAnnotationTag traffic_annotation_;
  57. std::unique_ptr<net::PacFileFetcher> pac_file_fetcher_;
  58. mojo::Remote<network::mojom::DhcpWpadUrlClient> dhcp_wpad_url_client_;
  59. base::WeakPtrFactory<DhcpPacFileFetcherMojo> weak_ptr_factory_{this};
  60. };
  61. } // namespace network
  62. #endif // SERVICES_NETWORK_DHCP_PAC_FILE_FETCHER_MOJO_H_