[go: nahoru, domu]

Adding a socket broker and support for tcp socket create and connect.

This change includes the current virtual interface for the socket broker
as well as part of the implementation for TCP socket creation and
connection. Outside of the transport_client_socket_unittest a broker
instance is not set anywhere yet so no big functionality change.


Bug: 1295329
Change-Id: I0b9047631a1e15d4e0bb40bdfa25e41ee6951321
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3328522
Reviewed-by: Matt Menke <mmenke@chromium.org>
Commit-Queue: Liza Burakova <liza@chromium.org>
Cr-Commit-Position: refs/heads/main@{#995304}
diff --git a/services/network/brokered_client_socket_factory.h b/services/network/brokered_client_socket_factory.h
new file mode 100644
index 0000000..2f33be0
--- /dev/null
+++ b/services/network/brokered_client_socket_factory.h
@@ -0,0 +1,65 @@
+// Copyright 2022 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef SERVICES_NETWORK_BROKERED_CLIENT_SOCKET_FACTORY_H_
+#define SERVICES_NETWORK_BROKERED_CLIENT_SOCKET_FACTORY_H_
+
+#include <memory>
+#include <string>
+
+#include "base/component_export.h"
+#include "net/socket/client_socket_factory.h"
+#include "net/socket/datagram_socket.h"
+#include "net/socket/socket_performance_watcher.h"
+#include "net/socket/transport_client_socket.h"
+#include "net/traffic_annotation/network_traffic_annotation.h"
+
+namespace net {
+
+class AddressList;
+class DatagramClientSocket;
+class HostPortPair;
+class NetLog;
+struct NetLogSource;
+class SSLClientContext;
+class SSLClientSocket;
+struct SSLConfig;
+class NetworkQualityEstimator;
+
+}  // namespace net
+
+namespace network {
+
+// A ClientSocketFactory to create brokered sockets.
+class COMPONENT_EXPORT(NETWORK_SERVICE) BrokeredClientSocketFactory
+    : public net::ClientSocketFactory {
+ public:
+  BrokeredClientSocketFactory();
+  ~BrokeredClientSocketFactory() override;
+
+  BrokeredClientSocketFactory(const BrokeredClientSocketFactory&) = delete;
+  BrokeredClientSocketFactory& operator=(const BrokeredClientSocketFactory&) =
+      delete;
+
+  // ClientSocketFactory:
+  std::unique_ptr<net::DatagramClientSocket> CreateDatagramClientSocket(
+      net::DatagramSocket::BindType bind_type,
+      net::NetLog* net_log,
+      const net::NetLogSource& source) override;
+  std::unique_ptr<net::TransportClientSocket> CreateTransportClientSocket(
+      const net::AddressList& addresses,
+      std::unique_ptr<net::SocketPerformanceWatcher> socket_performance_watcher,
+      net::NetworkQualityEstimator* network_quality_estimator,
+      net::NetLog* net_log,
+      const net::NetLogSource& source) override;
+  std::unique_ptr<net::SSLClientSocket> CreateSSLClientSocket(
+      net::SSLClientContext* context,
+      std::unique_ptr<net::StreamSocket> stream_socket,
+      const net::HostPortPair& host_and_port,
+      const net::SSLConfig& ssl_config) override;
+};
+
+}  // namespace network
+
+#endif  // SERVICES_NETWORK_BROKERED_CLIENT_SOCKET_FACTORY_H_