[go: nahoru, domu]

blob: a6692815606a5d1db9ea67ae25e43436f3d2a799 [file] [log] [blame]
Avi Drissman09875652022-09-15 20:03:191// Copyright 2022 The Chromium Authors
Liza Burakovae948bde2022-04-22 19:19:502// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef SERVICES_NETWORK_BROKERED_CLIENT_SOCKET_FACTORY_H_
6#define SERVICES_NETWORK_BROKERED_CLIENT_SOCKET_FACTORY_H_
7
Liza Burakovae948bde2022-04-22 19:19:508#include "base/component_export.h"
Will Harrisc96b9182022-09-09 22:35:289#include "build/build_config.h"
Liza Burakovaf76ff822022-06-17 23:02:3210#include "mojo/public/cpp/bindings/remote.h"
Liza Burakovae948bde2022-04-22 19:19:5011#include "net/socket/client_socket_factory.h"
12#include "net/socket/datagram_socket.h"
13#include "net/socket/socket_performance_watcher.h"
14#include "net/socket/transport_client_socket.h"
15#include "net/traffic_annotation/network_traffic_annotation.h"
Liza Burakovaf76ff822022-06-17 23:02:3216#include "services/network/public/mojom/socket_broker.mojom.h"
Liza Burakovae948bde2022-04-22 19:19:5017
Will Harrisc96b9182022-09-09 22:35:2818#if BUILDFLAG(IS_WIN)
19#include "services/network/broker_helper_win.h"
20#endif
21
Liza Burakovae948bde2022-04-22 19:19:5022namespace net {
23
24class AddressList;
25class DatagramClientSocket;
26class HostPortPair;
27class NetLog;
28struct NetLogSource;
29class SSLClientContext;
30class SSLClientSocket;
31struct SSLConfig;
32class NetworkQualityEstimator;
33
34} // namespace net
35
36namespace network {
37
38// A ClientSocketFactory to create brokered sockets.
39class COMPONENT_EXPORT(NETWORK_SERVICE) BrokeredClientSocketFactory
40 : public net::ClientSocketFactory {
41 public:
Liza Burakovaf76ff822022-06-17 23:02:3242 explicit BrokeredClientSocketFactory(
43 mojo::PendingRemote<mojom::SocketBroker> pending_remote);
Liza Burakovae948bde2022-04-22 19:19:5044 ~BrokeredClientSocketFactory() override;
45
46 BrokeredClientSocketFactory(const BrokeredClientSocketFactory&) = delete;
47 BrokeredClientSocketFactory& operator=(const BrokeredClientSocketFactory&) =
48 delete;
49
50 // ClientSocketFactory:
51 std::unique_ptr<net::DatagramClientSocket> CreateDatagramClientSocket(
52 net::DatagramSocket::BindType bind_type,
53 net::NetLog* net_log,
54 const net::NetLogSource& source) override;
55 std::unique_ptr<net::TransportClientSocket> CreateTransportClientSocket(
56 const net::AddressList& addresses,
57 std::unique_ptr<net::SocketPerformanceWatcher> socket_performance_watcher,
58 net::NetworkQualityEstimator* network_quality_estimator,
59 net::NetLog* net_log,
60 const net::NetLogSource& source) override;
61 std::unique_ptr<net::SSLClientSocket> CreateSSLClientSocket(
62 net::SSLClientContext* context,
63 std::unique_ptr<net::StreamSocket> stream_socket,
64 const net::HostPortPair& host_and_port,
65 const net::SSLConfig& ssl_config) override;
Liza Burakovaf76ff822022-06-17 23:02:3266
67 // Sends an IPC to the SocketBroker to create a new TCP socket.
68 void BrokerCreateTcpSocket(
69 net::AddressFamily address_family,
70 mojom::SocketBroker::CreateTcpSocketCallback callback);
71
Liza Burakova39fb9af32023-02-23 18:42:0472 // Sends an IPC to the SocketBroker to create a new UDP socket.
73 void BrokerCreateUdpSocket(
74 net::AddressFamily address_family,
75 mojom::SocketBroker::CreateUdpSocketCallback callback);
76
Liza Burakova96f30bbc2023-05-16 15:32:3377 // Whether or not a socket for `addresses` should be brokered or not. Virtual
78 // for testing.
79 virtual bool ShouldBroker(const net::AddressList& addresses) const;
Will Harrisc96b9182022-09-09 22:35:2880
Liza Burakova96f30bbc2023-05-16 15:32:3381 private:
Liza Burakovaf76ff822022-06-17 23:02:3282 mojo::Remote<mojom::SocketBroker> socket_broker_;
Will Harrisc96b9182022-09-09 22:35:2883#if BUILDFLAG(IS_WIN)
84 BrokerHelperWin broker_helper_;
85#endif
Liza Burakovae948bde2022-04-22 19:19:5086};
87
88} // namespace network
89
90#endif // SERVICES_NETWORK_BROKERED_CLIENT_SOCKET_FACTORY_H_