proxy_resolving_socket_factory_mojo.cc 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Copyright 2018 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. #include "services/network/proxy_resolving_socket_factory_mojo.h"
  5. #include <utility>
  6. #include "components/webrtc/fake_ssl_client_socket.h"
  7. #include "net/url_request/url_request_context.h"
  8. #include "services/network/proxy_resolving_client_socket.h"
  9. #include "services/network/proxy_resolving_client_socket_factory.h"
  10. #include "services/network/proxy_resolving_socket_mojo.h"
  11. #include "url/gurl.h"
  12. namespace network {
  13. ProxyResolvingSocketFactoryMojo::ProxyResolvingSocketFactoryMojo(
  14. net::URLRequestContext* request_context)
  15. : factory_impl_(request_context), tls_socket_factory_(request_context) {}
  16. ProxyResolvingSocketFactoryMojo::~ProxyResolvingSocketFactoryMojo() {}
  17. void ProxyResolvingSocketFactoryMojo::CreateProxyResolvingSocket(
  18. const GURL& url,
  19. const net::NetworkIsolationKey& network_isolation_key,
  20. mojom::ProxyResolvingSocketOptionsPtr options,
  21. const net::MutableNetworkTrafficAnnotationTag& traffic_annotation,
  22. mojo::PendingReceiver<mojom::ProxyResolvingSocket> receiver,
  23. mojo::PendingRemote<mojom::SocketObserver> observer,
  24. CreateProxyResolvingSocketCallback callback) {
  25. std::unique_ptr<net::StreamSocket> net_socket = factory_impl_.CreateSocket(
  26. url, network_isolation_key, options && options->use_tls);
  27. if (options && options->fake_tls_handshake) {
  28. DCHECK(!options->use_tls);
  29. net_socket =
  30. std::make_unique<webrtc::FakeSSLClientSocket>(std::move(net_socket));
  31. }
  32. auto socket = std::make_unique<ProxyResolvingSocketMojo>(
  33. std::move(net_socket),
  34. static_cast<net::NetworkTrafficAnnotationTag>(traffic_annotation),
  35. std::move(observer), &tls_socket_factory_);
  36. ProxyResolvingSocketMojo* socket_raw = socket.get();
  37. proxy_resolving_socket_receivers_.Add(std::move(socket), std::move(receiver));
  38. socket_raw->Connect(std::move(callback));
  39. }
  40. } // namespace network