#include "google_apis/gcm/engine/connection_factory_impl.h"
#include <memory>
#include <string>
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/location.h"
#include "base/memory/ptr_util.h"
#include "base/metrics/histogram_functions.h"
#include "base/task/sequenced_task_runner.h"
#include "google_apis/gcm/base/gcm_features.h"
#include "google_apis/gcm/engine/connection_handler_impl.h"
#include "google_apis/gcm/monitoring/gcm_stats_recorder.h"
#include "google_apis/gcm/protocol/mcs.pb.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "net/base/net_errors.h"
#include "net/base/network_isolation_key.h"
#include "net/http/http_request_headers.h"
#include "net/http/proxy_fallback.h"
#include "net/log/net_log_source_type.h"
#include "net/proxy_resolution/proxy_info.h"
#include "net/socket/client_socket_handle.h"
#include "net/socket/client_socket_pool_manager.h"
#include "net/ssl/ssl_config_service.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
#include "services/network/public/mojom/tcp_socket.mojom.h"
#include "url/gurl.h"
#include "url/origin.h"
namespace gcm {
namespace {
const int kReadTimeoutMs = …;
const int kConnectionResetWindowSecs = …;
bool ShouldRestorePreviousBackoff(const base::TimeTicks& login_time,
const base::TimeTicks& now_ticks) { … }
}
ConnectionFactoryImpl::ConnectionFactoryImpl(
const std::vector<GURL>& mcs_endpoints,
const net::BackoffEntry::Policy& backoff_policy,
GetProxyResolvingFactoryCallback get_socket_factory_callback,
scoped_refptr<base::SequencedTaskRunner> io_task_runner,
GCMStatsRecorder* recorder,
network::NetworkConnectionTracker* network_connection_tracker)
: … { … }
ConnectionFactoryImpl::~ConnectionFactoryImpl() { … }
void ConnectionFactoryImpl::Initialize(
const BuildLoginRequestCallback& request_builder,
const ConnectionHandler::ProtoReceivedCallback& read_callback,
const ConnectionHandler::ProtoSentCallback& write_callback) { … }
ConnectionHandler* ConnectionFactoryImpl::GetConnectionHandler() const { … }
void ConnectionFactoryImpl::Connect() { … }
ConnectionEventTracker* ConnectionFactoryImpl::GetEventTrackerForTesting() { … }
void ConnectionFactoryImpl::ConnectWithBackoff() { … }
bool ConnectionFactoryImpl::IsEndpointReachable() const { … }
std::string ConnectionFactoryImpl::GetConnectionStateString() const { … }
void ConnectionFactoryImpl::SignalConnectionReset(
ConnectionResetReason reason) { … }
void ConnectionFactoryImpl::SetConnectionListener(
ConnectionListener* listener) { … }
base::TimeTicks ConnectionFactoryImpl::NextRetryAttempt() const { … }
void ConnectionFactoryImpl::OnConnectionChanged(
network::mojom::ConnectionType type) { … }
GURL ConnectionFactoryImpl::GetCurrentEndpoint() const { … }
void ConnectionFactoryImpl::ConnectImpl(bool ignore_connection_failure) { … }
void ConnectionFactoryImpl::StartConnection(bool ignore_connection_failure) { … }
void ConnectionFactoryImpl::InitHandler(
mojo::ScopedDataPipeConsumerHandle receive_stream,
mojo::ScopedDataPipeProducerHandle send_stream) { … }
std::unique_ptr<net::BackoffEntry> ConnectionFactoryImpl::CreateBackoffEntry(
const net::BackoffEntry::Policy* const policy) { … }
std::unique_ptr<ConnectionHandler>
ConnectionFactoryImpl::CreateConnectionHandler(
base::TimeDelta read_timeout,
const ConnectionHandler::ProtoReceivedCallback& read_callback,
const ConnectionHandler::ProtoSentCallback& write_callback,
const ConnectionHandler::ConnectionChangedCallback& connection_callback) { … }
base::TimeTicks ConnectionFactoryImpl::NowTicks() { … }
void ConnectionFactoryImpl::OnConnectDone(
bool ignore_connection_failure,
int result,
const std::optional<net::IPEndPoint>& local_addr,
const std::optional<net::IPEndPoint>& peer_addr,
mojo::ScopedDataPipeConsumerHandle receive_stream,
mojo::ScopedDataPipeProducerHandle send_stream) { … }
void ConnectionFactoryImpl::ConnectionHandlerCallback(int result) { … }
void ConnectionFactoryImpl::CloseSocket() { … }
}