| OLD | NEW |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/tools/quic/test_tools/quic_test_server.h" | 5 #include "net/tools/quic/test_tools/quic_test_server.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "base/synchronization/lock.h" | 9 #include "base/synchronization/lock.h" |
| 10 #include "base/thread_task_runner_handle.h" | 10 #include "base/thread_task_runner_handle.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 namespace net { | 26 namespace net { |
| 27 namespace test { | 27 namespace test { |
| 28 | 28 |
| 29 class CustomStreamSession : public QuicSimpleServerSession { | 29 class CustomStreamSession : public QuicSimpleServerSession { |
| 30 public: | 30 public: |
| 31 CustomStreamSession( | 31 CustomStreamSession( |
| 32 const QuicConfig& config, | 32 const QuicConfig& config, |
| 33 QuicConnection* connection, | 33 QuicConnection* connection, |
| 34 QuicServerSessionVisitor* visitor, | 34 QuicServerSessionVisitor* visitor, |
| 35 const QuicCryptoServerConfig* crypto_config, | 35 const QuicCryptoServerConfig* crypto_config, |
| 36 QuicCompressedCertsCache* compressed_certs_cache, |
| 36 QuicTestServer::StreamFactory* factory, | 37 QuicTestServer::StreamFactory* factory, |
| 37 QuicTestServer::CryptoStreamFactory* crypto_stream_factory) | 38 QuicTestServer::CryptoStreamFactory* crypto_stream_factory) |
| 38 : QuicSimpleServerSession(config, connection, visitor, crypto_config), | 39 : QuicSimpleServerSession(config, |
| 40 connection, |
| 41 visitor, |
| 42 crypto_config, |
| 43 compressed_certs_cache), |
| 39 stream_factory_(factory), | 44 stream_factory_(factory), |
| 40 crypto_stream_factory_(crypto_stream_factory) {} | 45 crypto_stream_factory_(crypto_stream_factory) {} |
| 41 | 46 |
| 42 QuicSpdyStream* CreateIncomingDynamicStream(QuicStreamId id) override { | 47 QuicSpdyStream* CreateIncomingDynamicStream(QuicStreamId id) override { |
| 43 if (!ShouldCreateIncomingDynamicStream(id)) { | 48 if (!ShouldCreateIncomingDynamicStream(id)) { |
| 44 return nullptr; | 49 return nullptr; |
| 45 } | 50 } |
| 46 if (stream_factory_) { | 51 if (stream_factory_) { |
| 47 QuicSpdyStream* stream = stream_factory_->CreateStream(id, this); | 52 QuicSpdyStream* stream = stream_factory_->CreateStream(id, this); |
| 48 ActivateStream(stream); | 53 ActivateStream(stream); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 if (session_factory_ == nullptr && stream_factory_ == nullptr && | 86 if (session_factory_ == nullptr && stream_factory_ == nullptr && |
| 82 crypto_stream_factory_ == nullptr) { | 87 crypto_stream_factory_ == nullptr) { |
| 83 return QuicDispatcher::CreateQuicSession(id, client); | 88 return QuicDispatcher::CreateQuicSession(id, client); |
| 84 } | 89 } |
| 85 QuicConnection* connection = new QuicConnection( | 90 QuicConnection* connection = new QuicConnection( |
| 86 id, client, helper(), CreatePerConnectionWriter(), | 91 id, client, helper(), CreatePerConnectionWriter(), |
| 87 /* owns_writer= */ true, Perspective::IS_SERVER, supported_versions()); | 92 /* owns_writer= */ true, Perspective::IS_SERVER, supported_versions()); |
| 88 | 93 |
| 89 QuicServerSessionBase* session = nullptr; | 94 QuicServerSessionBase* session = nullptr; |
| 90 if (stream_factory_ != nullptr || crypto_stream_factory_ != nullptr) { | 95 if (stream_factory_ != nullptr || crypto_stream_factory_ != nullptr) { |
| 91 session = | 96 session = new CustomStreamSession( |
| 92 new CustomStreamSession(config(), connection, this, crypto_config(), | 97 config(), connection, this, crypto_config(), compressed_certs_cache(), |
| 93 stream_factory_, crypto_stream_factory_); | 98 stream_factory_, crypto_stream_factory_); |
| 94 } else { | 99 } else { |
| 95 session = session_factory_->CreateSession(config(), connection, this, | 100 session = session_factory_->CreateSession(config(), connection, this, |
| 96 crypto_config()); | 101 crypto_config(), |
| 102 compressed_certs_cache()); |
| 97 } | 103 } |
| 98 session->Initialize(); | 104 session->Initialize(); |
| 99 return session; | 105 return session; |
| 100 } | 106 } |
| 101 | 107 |
| 102 void SetSessionFactory(QuicTestServer::SessionFactory* factory) { | 108 void SetSessionFactory(QuicTestServer::SessionFactory* factory) { |
| 103 base::AutoLock lock(factory_lock_); | 109 base::AutoLock lock(factory_lock_); |
| 104 DCHECK(session_factory_ == nullptr); | 110 DCHECK(session_factory_ == nullptr); |
| 105 DCHECK(stream_factory_ == nullptr); | 111 DCHECK(stream_factory_ == nullptr); |
| 106 DCHECK(crypto_stream_factory_ == nullptr); | 112 DCHECK(crypto_stream_factory_ == nullptr); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 static_cast<QuicTestDispatcher*>(dispatcher()) | 164 static_cast<QuicTestDispatcher*>(dispatcher()) |
| 159 ->SetCryptoStreamFactory(factory); | 165 ->SetCryptoStreamFactory(factory); |
| 160 } | 166 } |
| 161 | 167 |
| 162 /////////////////////////// TEST SESSIONS /////////////////////////////// | 168 /////////////////////////// TEST SESSIONS /////////////////////////////// |
| 163 | 169 |
| 164 ImmediateGoAwaySession::ImmediateGoAwaySession( | 170 ImmediateGoAwaySession::ImmediateGoAwaySession( |
| 165 const QuicConfig& config, | 171 const QuicConfig& config, |
| 166 QuicConnection* connection, | 172 QuicConnection* connection, |
| 167 QuicServerSessionVisitor* visitor, | 173 QuicServerSessionVisitor* visitor, |
| 168 const QuicCryptoServerConfig* crypto_config) | 174 const QuicCryptoServerConfig* crypto_config, |
| 169 : QuicSimpleServerSession(config, connection, visitor, crypto_config) { | 175 QuicCompressedCertsCache* compressed_certs_cache) |
| 176 : QuicSimpleServerSession(config, |
| 177 connection, |
| 178 visitor, |
| 179 crypto_config, |
| 180 compressed_certs_cache) { |
| 170 SendGoAway(QUIC_PEER_GOING_AWAY, ""); | 181 SendGoAway(QUIC_PEER_GOING_AWAY, ""); |
| 171 } | 182 } |
| 172 | 183 |
| 173 } // namespace test | 184 } // namespace test |
| 174 } // namespace net | 185 } // namespace net |
| OLD | NEW |