#include "services/network/socket_factory.h"
#include <memory>
#include <optional>
#include <string>
#include <utility>
#include "mojo/public/cpp/bindings/type_converter.h"
#include "net/base/completion_once_callback.h"
#include "net/base/net_errors.h"
#include "net/cert/cert_verifier.h"
#include "net/cert/multi_log_ct_verifier.h"
#include "net/http/http_network_session.h"
#include "net/log/net_log.h"
#include "net/socket/client_socket_factory.h"
#include "net/socket/client_socket_handle.h"
#include "net/socket/tcp_server_socket.h"
#include "net/ssl/ssl_config.h"
#include "net/ssl/ssl_config_service.h"
#include "net/url_request/url_request_context.h"
#include "services/network/public/cpp/simple_host_resolver.h"
#include "services/network/restricted_udp_socket.h"
#include "services/network/tls_client_socket.h"
#include "services/network/udp_socket.h"
namespace network {
SocketFactory::SocketFactory(net::NetLog* net_log,
net::URLRequestContext* url_request_context)
: … { … }
SocketFactory::~SocketFactory() = default;
void SocketFactory::CreateUDPSocket(
mojo::PendingReceiver<mojom::UDPSocket> receiver,
mojo::PendingRemote<mojom::UDPSocketListener> listener) { … }
void SocketFactory::CreateRestrictedUDPSocket(
const net::IPEndPoint& addr,
mojom::RestrictedUDPSocketMode mode,
const net::MutableNetworkTrafficAnnotationTag& traffic_annotation,
mojom::RestrictedUDPSocketParamsPtr params,
mojo::PendingReceiver<mojom::RestrictedUDPSocket> receiver,
mojo::PendingRemote<mojom::UDPSocketListener> listener,
std::unique_ptr<SimpleHostResolver> resolver,
mojom::NetworkContext::CreateRestrictedUDPSocketCallback callback) { … }
void SocketFactory::CreateTCPServerSocket(
const net::IPEndPoint& local_addr,
mojom::TCPServerSocketOptionsPtr options,
const net::NetworkTrafficAnnotationTag& traffic_annotation,
mojo::PendingReceiver<mojom::TCPServerSocket> receiver,
mojom::NetworkContext::CreateTCPServerSocketCallback callback) { … }
#if BUILDFLAG(IS_WIN)
void SocketFactory::DidCompleteCreate(
const net::IPEndPoint& local_addr,
mojom::TCPServerSocketOptionsPtr options,
const net::NetworkTrafficAnnotationTag& traffic_annotation,
mojo::PendingReceiver<mojom::TCPServerSocket> receiver,
mojom::NetworkContext::CreateTCPServerSocketCallback callback,
network::TransferableSocket socket,
int result) {
if (result != net::OK) {
std::move(callback).Run(result, std::nullopt);
return;
}
auto tcp_socket =
std::make_unique<net::TCPServerSocket>(net_log_, net::NetLogSource());
tcp_socket->AdoptSocket(socket.TakeSocket());
auto tcp_server_socket = std::make_unique<TCPServerSocket>(
std::move(tcp_socket), 0, this, traffic_annotation);
CreateTCPServerSocketHelper(std::move(tcp_server_socket), local_addr,
std::move(options), traffic_annotation,
std::move(receiver), std::move(callback));
}
void SocketFactory::BindSocketBroker(
mojo::PendingRemote<mojom::SocketBroker> pending_remote) {
socket_broker_.Bind(std::move(pending_remote));
}
#endif
void SocketFactory::CreateTCPServerSocketHelper(
std::unique_ptr<TCPServerSocket> socket,
const net::IPEndPoint& local_addr,
mojom::TCPServerSocketOptionsPtr options,
const net::NetworkTrafficAnnotationTag& traffic_annotation,
mojo::PendingReceiver<mojom::TCPServerSocket> receiver,
mojom::NetworkContext::CreateTCPServerSocketCallback callback) { … }
void SocketFactory::CreateTCPConnectedSocket(
const std::optional<net::IPEndPoint>& local_addr,
const net::AddressList& remote_addr_list,
mojom::TCPConnectedSocketOptionsPtr tcp_connected_socket_options,
const net::NetworkTrafficAnnotationTag& traffic_annotation,
mojo::PendingReceiver<mojom::TCPConnectedSocket> receiver,
mojo::PendingRemote<mojom::SocketObserver> observer,
mojom::NetworkContext::CreateTCPConnectedSocketCallback callback) { … }
void SocketFactory::CreateTCPBoundSocket(
const net::IPEndPoint& local_addr,
const net::NetworkTrafficAnnotationTag& traffic_annotation,
mojo::PendingReceiver<mojom::TCPBoundSocket> receiver,
mojom::NetworkContext::CreateTCPBoundSocketCallback callback) { … }
void SocketFactory::DestroyBoundSocket(mojo::ReceiverId bound_socket_id) { … }
void SocketFactory::OnBoundSocketListening(
mojo::ReceiverId bound_socket_id,
std::unique_ptr<TCPServerSocket> server_socket,
mojo::PendingReceiver<mojom::TCPServerSocket> server_socket_receiver) { … }
void SocketFactory::OnBoundSocketConnected(
mojo::ReceiverId bound_socket_id,
std::unique_ptr<TCPConnectedSocket> connected_socket,
mojo::PendingReceiver<mojom::TCPConnectedSocket>
connected_socket_receiver) { … }
void SocketFactory::OnAccept(
std::unique_ptr<TCPConnectedSocket> socket,
mojo::PendingReceiver<mojom::TCPConnectedSocket> receiver) { … }
}