Web MIDI: make platform dependent initialization asynchronous
[chromium-blink-merge.git] / net / quic / quic_crypto_stream.cc
blob9005d5a39d3c396c7395f8f64be0fc8a34e1cad7
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "net/quic/quic_crypto_stream.h"
7 #include <string>
9 #include "base/strings/string_piece.h"
10 #include "net/quic/crypto/crypto_handshake.h"
11 #include "net/quic/quic_connection.h"
12 #include "net/quic/quic_session.h"
13 #include "net/quic/quic_utils.h"
15 using std::string;
16 using base::StringPiece;
18 namespace net {
20 QuicCryptoStream::QuicCryptoStream(QuicSession* session)
21 : ReliableQuicStream(kCryptoStreamId, session),
22 encryption_established_(false),
23 handshake_confirmed_(false) {
24 crypto_framer_.set_visitor(this);
25 DisableFlowControl();
28 void QuicCryptoStream::OnError(CryptoFramer* framer) {
29 DLOG(WARNING) << "Error processing crypto data: "
30 << QuicUtils::ErrorToString(framer->error());
33 void QuicCryptoStream::OnHandshakeMessage(
34 const CryptoHandshakeMessage& message) {
35 session()->OnCryptoHandshakeMessageReceived(message);
38 uint32 QuicCryptoStream::ProcessRawData(const char* data,
39 uint32 data_len) {
40 // Do not process handshake messages after the handshake is confirmed.
41 if (handshake_confirmed()) {
42 CloseConnection(QUIC_CRYPTO_MESSAGE_AFTER_HANDSHAKE_COMPLETE);
43 return 0;
45 if (!crypto_framer_.ProcessInput(StringPiece(data, data_len))) {
46 CloseConnection(crypto_framer_.error());
47 return 0;
49 return data_len;
52 QuicPriority QuicCryptoStream::EffectivePriority() const {
53 return QuicUtils::HighestPriority();
56 void QuicCryptoStream::SendHandshakeMessage(
57 const CryptoHandshakeMessage& message) {
58 session()->OnCryptoHandshakeMessageSent(message);
59 const QuicData& data = message.GetSerialized();
60 // To make reasoning about crypto frames easier, we don't combine them with
61 // any other frames in a single packet.
62 session()->connection()->Flush();
63 // TODO(wtc): check the return value.
64 WriteOrBufferData(string(data.data(), data.length()), false, NULL);
65 session()->connection()->Flush();
68 const QuicCryptoNegotiatedParameters&
69 QuicCryptoStream::crypto_negotiated_params() const {
70 return crypto_negotiated_params_;
73 } // namespace net