blob: 25fcab0a909d2ac6e079dda1476353e419b78118 [file] [log] [blame]
// Copyright (c) 2012 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.
#include "net/tools/quic/quic_simple_client.h"
#include <utility>
#include "base/run_loop.h"
#include "base/threading/thread_task_runner_handle.h"
#include "net/base/net_errors.h"
#include "net/http/http_request_info.h"
#include "net/http/http_response_info.h"
#include "net/log/net_log_source.h"
#include "net/log/net_log_with_source.h"
#include "net/quic/quic_chromium_alarm_factory.h"
#include "net/quic/quic_chromium_connection_helper.h"
#include "net/quic/quic_chromium_packet_reader.h"
#include "net/quic/quic_chromium_packet_writer.h"
#include "net/socket/udp_client_socket.h"
#include "net/spdy/spdy_http_utils.h"
#include "net/third_party/quiche/src/quic/core/crypto/quic_random.h"
#include "net/third_party/quiche/src/quic/core/http/spdy_utils.h"
#include "net/third_party/quiche/src/quic/core/quic_connection.h"
#include "net/third_party/quiche/src/quic/core/quic_packets.h"
#include "net/third_party/quiche/src/quic/core/quic_server_id.h"
#include "net/third_party/quiche/src/quic/platform/api/quic_flags.h"
#include "net/third_party/quiche/src/quic/platform/api/quic_ptr_util.h"
#include "net/third_party/quiche/src/quic/tools/quic_simple_client_session.h"
#include "net/third_party/quiche/src/spdy/core/spdy_header_block.h"
using std::string;
namespace net {
QuicSimpleClient::QuicSimpleClient(
quic::QuicSocketAddress server_address,
const quic::QuicServerId& server_id,
const quic::ParsedQuicVersionVector& supported_versions,
const quic::QuicConfig& config,
std::unique_ptr<quic::ProofVerifier> proof_verifier)
: quic::QuicSpdyClientBase(
server_id,
supported_versions,
config,
CreateQuicConnectionHelper(),
CreateQuicAlarmFactory(),
quic::QuicWrapUnique(
new QuicClientMessageLooplNetworkHelper(&clock_, this)),
std::move(proof_verifier),
nullptr),
initialized_(false) {
set_server_address(server_address);
}
QuicSimpleClient::~QuicSimpleClient() {
if (connected()) {
session()->connection()->CloseConnection(
quic::QUIC_PEER_GOING_AWAY, "Shutting down",
quic::ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET);
}
}
std::unique_ptr<quic::QuicSession> QuicSimpleClient::CreateQuicClientSession(
const quic::ParsedQuicVersionVector& supported_versions,
quic::QuicConnection* connection) {
return std::make_unique<quic::QuicSimpleClientSession>(
*config(), supported_versions, connection, server_id(), crypto_config(),
push_promise_index(), drop_response_body());
}
QuicChromiumConnectionHelper* QuicSimpleClient::CreateQuicConnectionHelper() {
return new QuicChromiumConnectionHelper(&clock_,
quic::QuicRandom::GetInstance());
}
QuicChromiumAlarmFactory* QuicSimpleClient::CreateQuicAlarmFactory() {
return new QuicChromiumAlarmFactory(base::ThreadTaskRunnerHandle::Get().get(),
&clock_);
}
} // namespace net