MD Downloads: center "Open downloads folder" when there's no downloads
[chromium-blink-merge.git] / remoting / protocol / quic_channel.h
blob64c346a93fd66c6d7b0c07fbac804cc9f6337afb
1 // Copyright 2015 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 #ifndef REMOTING_PROTOCOL_QUIC_CHANNEL_H_
6 #define REMOTING_PROTOCOL_QUIC_CHANNEL_H_
8 #include "net/quic/p2p/quic_p2p_stream.h"
9 #include "remoting/base/compound_buffer.h"
10 #include "remoting/protocol/p2p_stream_socket.h"
12 namespace net {
13 class DrainableIOBuffer;
14 } // namespace net
16 namespace remoting {
17 namespace protocol {
19 // QuicChannel implements P2PStreamSocket interface for a QuicP2PStream.
20 class QuicChannel : public net::QuicP2PStream::Delegate,
21 public P2PStreamSocket {
22 public:
23 QuicChannel(net::QuicP2PStream* stream,
24 const base::Closure& on_destroyed_callback);
25 ~QuicChannel() override;
27 const std::string& name() { return name_; }
29 // P2PStreamSocket interface.
30 int Read(const scoped_refptr<net::IOBuffer>& buffer,
31 int buffer_len,
32 const net::CompletionCallback& callback) override;
33 int Write(const scoped_refptr<net::IOBuffer>& buffer,
34 int buffer_len,
35 const net::CompletionCallback& callback) override;
37 protected:
38 void SetName(const std::string& name);
40 // Owned by QuicSession.
41 net::QuicP2PStream* stream_;
43 private:
44 // net::QuicP2PStream::Delegate interface.
45 void OnDataReceived(const char* data, int length) override;
46 void OnClose(net::QuicErrorCode error) override;
48 base::Closure on_destroyed_callback_;
50 std::string name_;
52 CompoundBuffer data_received_;
54 net::CompletionCallback read_callback_;
55 scoped_refptr<net::IOBuffer> read_buffer_;
56 int read_buffer_size_ = 0;
58 int error_ = 0;
60 DISALLOW_COPY_AND_ASSIGN(QuicChannel);
63 // Client side of a channel. Sends the |name| specified in the constructor to
64 // the peer.
65 class QuicClientChannel : public QuicChannel {
66 public:
67 QuicClientChannel(net::QuicP2PStream* stream,
68 const base::Closure& on_destroyed_callback,
69 const std::string& name);
70 ~QuicClientChannel() override;
72 private:
73 DISALLOW_COPY_AND_ASSIGN(QuicClientChannel);
76 // Host side of a channel. Receives name from the peer after ReceiveName is
77 // called. Read() can be called only after the name is received.
78 class QuicServerChannel : public QuicChannel {
79 public:
80 QuicServerChannel(net::QuicP2PStream* stream,
81 const base::Closure& on_destroyed_callback);
82 ~QuicServerChannel() override;
84 // Must be called after the constructor to receive channel name.
85 // |name_received_callback| must use QuicChannel::name() to get the name.
86 // Empty name() indicates failure to receive it.
87 void ReceiveName(const base::Closure& name_received_callback);
89 private:
90 void OnNameSizeReadResult(int result);
91 void ReadNameLoop(int result);
92 void OnNameReadResult(int result);
94 base::Closure name_received_callback_;
95 uint8_t name_length_ = 0;
96 scoped_refptr<net::DrainableIOBuffer> name_read_buffer_;
98 DISALLOW_COPY_AND_ASSIGN(QuicServerChannel);
101 } // namespace protocol
102 } // namespace remoting
104 #endif // REMOTING_PROTOCOL_QUIC_CHANNEL_H_