1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
|
// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_BROWSER_NETWORK_SERVICE_CLIENT_H_
#define CONTENT_BROWSER_NETWORK_SERVICE_CLIENT_H_
#include <memory>
#include <string>
#include <vector>
#include "base/memory/memory_pressure_listener.h"
#include "base/unguessable_token.h"
#include "build/build_config.h"
#include "content/browser/network/socket_broker_impl.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/receiver_set.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "net/cert/cert_database.h"
#include "services/network/public/mojom/network_change_manager.mojom.h"
#include "services/network/public/mojom/network_service.mojom.h"
#include "services/network/public/mojom/url_loader_network_service_observer.mojom.h"
#include "url/gurl.h"
#if BUILDFLAG(IS_ANDROID)
#include "base/android/application_status_listener.h"
#endif
namespace content {
class WebRtcConnectionsObserver;
class NetworkServiceClient
: public network::mojom::URLLoaderNetworkServiceObserver,
#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_LINUX)
public net::NetworkChangeNotifier::ConnectionTypeObserver,
public net::NetworkChangeNotifier::MaxBandwidthObserver,
public net::NetworkChangeNotifier::IPAddressObserver,
#endif
public net::CertDatabase::Observer {
public:
NetworkServiceClient();
NetworkServiceClient(const NetworkServiceClient&) = delete;
NetworkServiceClient& operator=(const NetworkServiceClient&) = delete;
~NetworkServiceClient() override;
mojo::PendingRemote<network::mojom::URLLoaderNetworkServiceObserver>
BindURLLoaderNetworkServiceObserver();
// Called when SetParams() is called on the associated network service.
void OnNetworkServiceInitialized(network::mojom::NetworkService* service);
// net::CertDatabase::Observer implementation:
void OnTrustStoreChanged() override;
void OnClientCertStoreChanged() override;
void OnMemoryPressure(
base::MemoryPressureListener::MemoryPressureLevel memory_presure_level);
// Called when there is a change in the count of media connections that
// require low network latency.
void OnPeerToPeerConnectionsCountChange(uint32_t count);
#if BUILDFLAG(IS_ANDROID)
void OnApplicationStateChange(base::android::ApplicationState state);
#endif
#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_LINUX)
// net::NetworkChangeNotifier::ConnectionTypeObserver implementation:
void OnConnectionTypeChanged(
net::NetworkChangeNotifier::ConnectionType type) override;
// net::NetworkChangeNotifier::MaxBandwidthObserver implementation:
void OnMaxBandwidthChanged(
double max_bandwidth_mbps,
net::NetworkChangeNotifier::ConnectionType type) override;
// net::NetworkChangeNotifier::IPAddressObserver implementation:
void OnIPAddressChanged() override;
#endif // BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_LINUX)
#if BUILDFLAG(IS_WIN)
// Called when the network service sandbox is enabled.
mojo::PendingRemote<network::mojom::SocketBroker> BindSocketBroker();
#endif
private:
// network::mojom::URLLoaderNetworkServiceObserver overrides.
void OnSSLCertificateError(const GURL& url,
int net_error,
const net::SSLInfo& ssl_info,
bool fatal,
OnSSLCertificateErrorCallback response) override;
void OnCertificateRequested(
const std::optional<base::UnguessableToken>& window_id,
const scoped_refptr<net::SSLCertRequestInfo>& cert_info,
mojo::PendingRemote<network::mojom::ClientCertificateResponder>
cert_responder) override;
void OnAuthRequired(
const std::optional<base::UnguessableToken>& window_id,
int32_t request_id,
const GURL& url,
bool first_auth_attempt,
const net::AuthChallengeInfo& auth_info,
const scoped_refptr<net::HttpResponseHeaders>& head_headers,
mojo::PendingRemote<network::mojom::AuthChallengeResponder>
auth_challenge_responder) override;
void OnPrivateNetworkAccessPermissionRequired(
const GURL& url,
const net::IPAddress& ip_address,
const std::optional<std::string>& private_network_device_id,
const std::optional<std::string>& private_network_device_name,
OnPrivateNetworkAccessPermissionRequiredCallback callback) override;
void OnLocalNetworkAccessPermissionRequired(
OnLocalNetworkAccessPermissionRequiredCallback callback) override;
void OnClearSiteData(
const GURL& url,
const std::string& header_value,
int load_flags,
const std::optional<net::CookiePartitionKey>& cookie_partition_key,
bool partitioned_state_allowed_only,
OnClearSiteDataCallback callback) override;
void OnLoadingStateUpdate(network::mojom::LoadInfoPtr info,
OnLoadingStateUpdateCallback callback) override;
void OnDataUseUpdate(int32_t network_traffic_annotation_id_hash,
int64_t recv_bytes,
int64_t sent_bytes) override;
void OnSharedStorageHeaderReceived(
const url::Origin& request_origin,
std::vector<network::mojom::SharedStorageModifierMethodWithOptionsPtr>
methods_with_options,
const std::optional<std::string>& with_lock,
OnSharedStorageHeaderReceivedCallback callback) override;
void OnAdAuctionEventRecordHeaderReceived(
network::AdAuctionEventRecord event_record,
const std::optional<url::Origin>& top_frame_origin) override;
void Clone(
mojo::PendingReceiver<network::mojom::URLLoaderNetworkServiceObserver>
listener) override;
void OnWebSocketConnectedToPrivateNetwork(
network::mojom::IPAddressSpace ip_address_space) override;
void OnUrlLoaderConnectedToPrivateNetwork(
const GURL& request_url,
network::mojom::IPAddressSpace response_address_space,
network::mojom::IPAddressSpace client_address_space,
network::mojom::IPAddressSpace target_address_space) override;
std::unique_ptr<base::MemoryPressureListener> memory_pressure_listener_;
std::unique_ptr<WebRtcConnectionsObserver> webrtc_connections_observer_;
#if BUILDFLAG(IS_ANDROID)
std::unique_ptr<base::android::ApplicationStatusListener>
app_status_listener_;
#endif
#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_LINUX)
mojo::Remote<network::mojom::NetworkChangeManager> network_change_manager_;
#endif // BUILDFLAG(IS_ANDROID)
#if BUILDFLAG(IS_WIN)
SocketBrokerImpl socket_broker_;
#endif // BUILDFLAG(IS_WIN)
mojo::ReceiverSet<network::mojom::URLLoaderNetworkServiceObserver>
url_loader_network_service_observers_;
};
} // namespace content
#endif // CONTENT_BROWSER_NETWORK_SERVICE_CLIENT_H_
|