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 // NOTE: This code is not shared between Google and Chrome.
7 #ifndef NET_QUIC_QUIC_RELIABLE_CLIENT_STREAM_H_
8 #define NET_QUIC_QUIC_RELIABLE_CLIENT_STREAM_H_
10 #include "net/base/ip_endpoint.h"
11 #include "net/base/upload_data_stream.h"
12 #include "net/http/http_request_info.h"
13 #include "net/http/http_response_info.h"
14 #include "net/http/http_stream.h"
15 #include "net/quic/quic_data_stream.h"
19 class QuicSpdySession
;
21 // A client-initiated ReliableQuicStream. Instances of this class
22 // are owned by the QuicClientSession which created them.
23 class NET_EXPORT_PRIVATE QuicReliableClientStream
: public QuicDataStream
{
25 // Delegate handles protocol specific behavior of a quic stream.
26 class NET_EXPORT_PRIVATE Delegate
{
30 // Called when headers are available.
31 virtual void OnHeadersAvailable(StringPiece headers
) = 0;
33 // Called when data is received.
34 // Returns network error code. OK when it successfully receives data.
35 virtual int OnDataReceived(const char* data
, int length
) = 0;
37 // Called when the stream is closed by the peer.
38 virtual void OnClose(QuicErrorCode error
) = 0;
40 // Called when the stream is closed because of an error.
41 virtual void OnError(int error
) = 0;
43 // Returns true if sending of headers has completed.
44 virtual bool HasSendHeadersComplete() = 0;
47 virtual ~Delegate() {}
50 DISALLOW_COPY_AND_ASSIGN(Delegate
);
53 QuicReliableClientStream(QuicStreamId id
,
54 QuicSpdySession
* session
,
55 const BoundNetLog
& net_log
);
57 ~QuicReliableClientStream() override
;
60 void OnStreamHeadersComplete(bool fin
, size_t frame_len
) override
;
61 uint32
ProcessData(const char* data
, uint32 data_len
) override
;
62 void OnClose() override
;
63 void OnCanWrite() override
;
64 QuicPriority
EffectivePriority() const override
;
66 // While the server's set_priority shouldn't be called externally, the creator
67 // of client-side streams should be able to set the priority.
68 using QuicDataStream::set_priority
;
70 int WriteStreamData(base::StringPiece data
,
72 const CompletionCallback
& callback
);
73 // Set new |delegate|. |delegate| must not be NULL.
74 // If this stream has already received data, OnDataReceived() will be
75 // called on the delegate.
76 void SetDelegate(Delegate
* delegate
);
77 Delegate
* GetDelegate() { return delegate_
; }
78 void OnError(int error
);
80 // Returns true if the stream can possible write data. (The socket may
81 // turn out to be write blocked, of course). If the stream can not write,
82 // this method returns false, and |callback| will be invoked when
83 // it becomes writable.
84 bool CanWrite(const CompletionCallback
& callback
);
86 const BoundNetLog
& net_log() const { return net_log_
; }
88 using QuicDataStream::HasBufferedData
;
94 CompletionCallback callback_
;
96 DISALLOW_COPY_AND_ASSIGN(QuicReliableClientStream
);
101 #endif // NET_QUIC_QUIC_RELIABLE_CLIENT_STREAM_H_