| 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/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "base/synchronization/lock.h" | 10 #include "base/synchronization/lock.h" |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 std::move(session_helper), | 95 std::move(session_helper), |
| 96 std::move(alarm_factory), | 96 std::move(alarm_factory), |
| 97 response_cache), | 97 response_cache), |
| 98 session_factory_(nullptr), | 98 session_factory_(nullptr), |
| 99 stream_factory_(nullptr), | 99 stream_factory_(nullptr), |
| 100 crypto_stream_factory_(nullptr) {} | 100 crypto_stream_factory_(nullptr) {} |
| 101 | 101 |
| 102 QuicServerSessionBase* CreateQuicSession( | 102 QuicServerSessionBase* CreateQuicSession( |
| 103 QuicConnectionId id, | 103 QuicConnectionId id, |
| 104 const QuicSocketAddress& client) override { | 104 const QuicSocketAddress& client) override { |
| 105 base::AutoLock lock(factory_lock_); | 105 QuicReaderMutexLock lock(&factory_lock_); |
| 106 if (session_factory_ == nullptr && stream_factory_ == nullptr && | 106 if (session_factory_ == nullptr && stream_factory_ == nullptr && |
| 107 crypto_stream_factory_ == nullptr) { | 107 crypto_stream_factory_ == nullptr) { |
| 108 return QuicSimpleDispatcher::CreateQuicSession(id, client); | 108 return QuicSimpleDispatcher::CreateQuicSession(id, client); |
| 109 } | 109 } |
| 110 QuicConnection* connection = new QuicConnection( | 110 QuicConnection* connection = new QuicConnection( |
| 111 id, client, helper(), alarm_factory(), CreatePerConnectionWriter(), | 111 id, client, helper(), alarm_factory(), CreatePerConnectionWriter(), |
| 112 /* owns_writer= */ true, Perspective::IS_SERVER, | 112 /* owns_writer= */ true, Perspective::IS_SERVER, |
| 113 GetSupportedVersions()); | 113 GetSupportedVersions()); |
| 114 | 114 |
| 115 QuicServerSessionBase* session = nullptr; | 115 QuicServerSessionBase* session = nullptr; |
| 116 if (stream_factory_ != nullptr || crypto_stream_factory_ != nullptr) { | 116 if (stream_factory_ != nullptr || crypto_stream_factory_ != nullptr) { |
| 117 session = new CustomStreamSession( | 117 session = new CustomStreamSession( |
| 118 config(), connection, this, session_helper(), crypto_config(), | 118 config(), connection, this, session_helper(), crypto_config(), |
| 119 compressed_certs_cache(), stream_factory_, crypto_stream_factory_, | 119 compressed_certs_cache(), stream_factory_, crypto_stream_factory_, |
| 120 response_cache()); | 120 response_cache()); |
| 121 } else { | 121 } else { |
| 122 session = session_factory_->CreateSession( | 122 session = session_factory_->CreateSession( |
| 123 config(), connection, this, session_helper(), crypto_config(), | 123 config(), connection, this, session_helper(), crypto_config(), |
| 124 compressed_certs_cache(), response_cache()); | 124 compressed_certs_cache(), response_cache()); |
| 125 } | 125 } |
| 126 session->Initialize(); | 126 session->Initialize(); |
| 127 return session; | 127 return session; |
| 128 } | 128 } |
| 129 | 129 |
| 130 void SetSessionFactory(QuicTestServer::SessionFactory* factory) { | 130 void SetSessionFactory(QuicTestServer::SessionFactory* factory) { |
| 131 base::AutoLock lock(factory_lock_); | 131 QuicWriterMutexLock lock(&factory_lock_); |
| 132 DCHECK(session_factory_ == nullptr); | 132 DCHECK(session_factory_ == nullptr); |
| 133 DCHECK(stream_factory_ == nullptr); | 133 DCHECK(stream_factory_ == nullptr); |
| 134 DCHECK(crypto_stream_factory_ == nullptr); | 134 DCHECK(crypto_stream_factory_ == nullptr); |
| 135 session_factory_ = factory; | 135 session_factory_ = factory; |
| 136 } | 136 } |
| 137 | 137 |
| 138 void SetStreamFactory(QuicTestServer::StreamFactory* factory) { | 138 void SetStreamFactory(QuicTestServer::StreamFactory* factory) { |
| 139 base::AutoLock lock(factory_lock_); | 139 QuicWriterMutexLock lock(&factory_lock_); |
| 140 DCHECK(session_factory_ == nullptr); | 140 DCHECK(session_factory_ == nullptr); |
| 141 DCHECK(stream_factory_ == nullptr); | 141 DCHECK(stream_factory_ == nullptr); |
| 142 stream_factory_ = factory; | 142 stream_factory_ = factory; |
| 143 } | 143 } |
| 144 | 144 |
| 145 void SetCryptoStreamFactory(QuicTestServer::CryptoStreamFactory* factory) { | 145 void SetCryptoStreamFactory(QuicTestServer::CryptoStreamFactory* factory) { |
| 146 base::AutoLock lock(factory_lock_); | 146 QuicWriterMutexLock lock(&factory_lock_); |
| 147 DCHECK(session_factory_ == nullptr); | 147 DCHECK(session_factory_ == nullptr); |
| 148 DCHECK(crypto_stream_factory_ == nullptr); | 148 DCHECK(crypto_stream_factory_ == nullptr); |
| 149 crypto_stream_factory_ = factory; | 149 crypto_stream_factory_ = factory; |
| 150 } | 150 } |
| 151 | 151 |
| 152 private: | 152 private: |
| 153 base::Lock factory_lock_; | 153 QuicMutex factory_lock_; |
| 154 QuicTestServer::SessionFactory* session_factory_; // Not owned. | 154 QuicTestServer::SessionFactory* session_factory_; // Not owned. |
| 155 QuicTestServer::StreamFactory* stream_factory_; // Not owned. | 155 QuicTestServer::StreamFactory* stream_factory_; // Not owned. |
| 156 QuicTestServer::CryptoStreamFactory* crypto_stream_factory_; // Not owned. | 156 QuicTestServer::CryptoStreamFactory* crypto_stream_factory_; // Not owned. |
| 157 }; | 157 }; |
| 158 | 158 |
| 159 QuicTestServer::QuicTestServer(std::unique_ptr<ProofSource> proof_source, | 159 QuicTestServer::QuicTestServer(std::unique_ptr<ProofSource> proof_source, |
| 160 QuicHttpResponseCache* response_cache) | 160 QuicHttpResponseCache* response_cache) |
| 161 : QuicServer(std::move(proof_source), response_cache) {} | 161 : QuicServer(std::move(proof_source), response_cache) {} |
| 162 | 162 |
| 163 QuicTestServer::QuicTestServer(std::unique_ptr<ProofSource> proof_source, | 163 QuicTestServer::QuicTestServer(std::unique_ptr<ProofSource> proof_source, |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 compressed_certs_cache, | 214 compressed_certs_cache, |
| 215 response_cache) {} | 215 response_cache) {} |
| 216 | 216 |
| 217 void ImmediateGoAwaySession::OnStreamFrame(const QuicStreamFrame& frame) { | 217 void ImmediateGoAwaySession::OnStreamFrame(const QuicStreamFrame& frame) { |
| 218 SendGoAway(QUIC_PEER_GOING_AWAY, ""); | 218 SendGoAway(QUIC_PEER_GOING_AWAY, ""); |
| 219 QuicSimpleServerSession::OnStreamFrame(frame); | 219 QuicSimpleServerSession::OnStreamFrame(frame); |
| 220 } | 220 } |
| 221 | 221 |
| 222 } // namespace test | 222 } // namespace test |
| 223 } // namespace net | 223 } // namespace net |
| OLD | NEW |