Skip to content

Commit

Permalink
Add a default QuicCryptoClientStreamFactory
Browse files Browse the repository at this point in the history
so that QuicChromiumClientSession does not have to special-case when no
CryptoStreamFactory is available.

Review URL: https://codereview.chromium.org/1563643002

Cr-Commit-Position: refs/heads/master@{#367715}
  • Loading branch information
rch-chromium-org authored and Commit bot committed Jan 6, 2016
1 parent 907d1b7 commit 1f83eaf
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 9 deletions.
3 changes: 2 additions & 1 deletion net/http/http_network_session.cc
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ HttpNetworkSession::Params::Params()
quic_random(NULL),
quic_max_packet_length(kDefaultMaxPacketSize),
enable_user_alternate_protocol_ports(false),
quic_crypto_client_stream_factory(NULL),
quic_crypto_client_stream_factory(
QuicCryptoClientStreamFactory::GetDefaultFactory()),
quic_max_recent_disabled_reasons(kQuicMaxRecentDisabledReasons),
quic_threshold_public_resets_post_handshake(0),
quic_threshold_timeouts_streams_open(0),
Expand Down
1 change: 1 addition & 0 deletions net/net.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +1024,7 @@
'quic/network_connection.h',
'quic/quic_crypto_client_stream.cc',
'quic/quic_crypto_client_stream.h',
'quic/quic_crypto_client_stream_factory.cc',
'quic/quic_crypto_client_stream_factory.h',
'quic/quic_crypto_server_stream.cc',
'quic/quic_crypto_server_stream.h',
Expand Down
11 changes: 4 additions & 7 deletions net/quic/quic_chromium_client_session.cc
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,10 @@ QuicChromiumClientSession::QuicChromiumClientSession(
disabled_reason_(QUIC_DISABLED_NOT),
weak_factory_(this) {
crypto_stream_.reset(
crypto_client_stream_factory
? crypto_client_stream_factory->CreateQuicCryptoClientStream(
server_id, this, crypto_config)
: new QuicCryptoClientStream(
server_id, this,
new ProofVerifyContextChromium(cert_verify_flags, net_log_),
crypto_config));
crypto_client_stream_factory->CreateQuicCryptoClientStream(
server_id, this, make_scoped_ptr(new ProofVerifyContextChromium(
cert_verify_flags, net_log_)),
crypto_config));
connection->set_debug_visitor(logger_.get());
net_log_.BeginEvent(NetLog::TYPE_QUIC_SESSION,
base::Bind(NetLogQuicClientSessionCallback, &server_id,
Expand Down
3 changes: 2 additions & 1 deletion net/quic/quic_chromium_client_session_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "net/quic/crypto/quic_decrypter.h"
#include "net/quic/crypto/quic_encrypter.h"
#include "net/quic/crypto/quic_server_info.h"
#include "net/quic/quic_crypto_client_stream_factory.h"
#include "net/quic/quic_flags.h"
#include "net/quic/quic_packet_reader.h"
#include "net/quic/quic_protocol.h"
Expand Down Expand Up @@ -56,7 +57,7 @@ class QuicChromiumClientSessionTest
connection_,
GetSocket(),
/*stream_factory=*/nullptr,
/*crypto_client_stream_factory=*/nullptr,
QuicCryptoClientStreamFactory::GetDefaultFactory(),
&clock_,
&transport_security_state_,
make_scoped_ptr((QuicServerInfo*)nullptr),
Expand Down
39 changes: 39 additions & 0 deletions net/quic/quic_crypto_client_stream_factory.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright (c) 2016 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/quic/quic_crypto_client_stream_factory.h"

#include "base/lazy_instance.h"
#include "net/quic/crypto/proof_verifier_chromium.h"
#include "net/quic/quic_chromium_client_session.h"
#include "net/quic/quic_crypto_client_stream.h"

namespace net {

namespace {

class DefaultCryptoStreamFactory : public QuicCryptoClientStreamFactory {
public:
QuicCryptoClientStream* CreateQuicCryptoClientStream(
const QuicServerId& server_id,
QuicChromiumClientSession* session,
scoped_ptr<ProofVerifyContext> proof_verify_context,
QuicCryptoClientConfig* crypto_config) override {
return new QuicCryptoClientStream(
server_id, session, proof_verify_context.release(), crypto_config);
}
};

static base::LazyInstance<DefaultCryptoStreamFactory>::Leaky
g_default_crypto_stream_factory = LAZY_INSTANCE_INITIALIZER;

} // namespace

// static
QuicCryptoClientStreamFactory*
QuicCryptoClientStreamFactory::GetDefaultFactory() {
return g_default_crypto_stream_factory.Pointer();
}

} // namespace net
6 changes: 6 additions & 0 deletions net/quic/quic_crypto_client_stream_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@

#include <string>

#include "base/memory/scoped_ptr.h"
#include "net/base/net_export.h"

namespace net {

class ProofVerifyContext;
class QuicChromiumClientSession;
class QuicCryptoClientConfig;
class QuicCryptoClientStream;
class QuicServerId;

Expand All @@ -24,7 +27,10 @@ class NET_EXPORT QuicCryptoClientStreamFactory {
virtual QuicCryptoClientStream* CreateQuicCryptoClientStream(
const QuicServerId& server_id,
QuicChromiumClientSession* session,
scoped_ptr<ProofVerifyContext> proof_verify_context,
QuicCryptoClientConfig* crypto_config) = 0;

static QuicCryptoClientStreamFactory* GetDefaultFactory();
};

} // namespace net
Expand Down
1 change: 1 addition & 0 deletions net/quic/test_tools/mock_crypto_client_stream_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ QuicCryptoClientStream*
MockCryptoClientStreamFactory::CreateQuicCryptoClientStream(
const QuicServerId& server_id,
QuicChromiumClientSession* session,
scoped_ptr<ProofVerifyContext> /*proof_verify_context*/,
QuicCryptoClientConfig* crypto_config) {
const ProofVerifyDetails* proof_verify_details = nullptr;
if (!proof_verify_details_queue_.empty()) {
Expand Down
1 change: 1 addition & 0 deletions net/quic/test_tools/mock_crypto_client_stream_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class MockCryptoClientStreamFactory : public QuicCryptoClientStreamFactory {
QuicCryptoClientStream* CreateQuicCryptoClientStream(
const QuicServerId& server_id,
QuicChromiumClientSession* session,
scoped_ptr<ProofVerifyContext> proof_verify_context,
QuicCryptoClientConfig* crypto_config) override;

void set_handshake_mode(
Expand Down

0 comments on commit 1f83eaf

Please sign in to comment.