| OLD | NEW |
| (Empty) |
| 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. | |
| 4 // | |
| 5 // NOTE: This code is not shared between Google and Chrome. | |
| 6 | |
| 7 #ifndef NET_QUIC_QUIC_RELIABLE_CLIENT_STREAM_H_ | |
| 8 #define NET_QUIC_QUIC_RELIABLE_CLIENT_STREAM_H_ | |
| 9 | |
| 10 #include <stddef.h> | |
| 11 | |
| 12 #include "base/macros.h" | |
| 13 #include "net/base/ip_endpoint.h" | |
| 14 #include "net/base/upload_data_stream.h" | |
| 15 #include "net/http/http_request_info.h" | |
| 16 #include "net/http/http_response_info.h" | |
| 17 #include "net/http/http_stream.h" | |
| 18 #include "net/quic/quic_spdy_stream.h" | |
| 19 | |
| 20 namespace net { | |
| 21 | |
| 22 class QuicSpdySession; | |
| 23 | |
| 24 // A client-initiated ReliableQuicStream. Instances of this class | |
| 25 // are owned by the QuicClientSession which created them. | |
| 26 class NET_EXPORT_PRIVATE QuicReliableClientStream : public QuicSpdyStream { | |
| 27 public: | |
| 28 // Delegate handles protocol specific behavior of a quic stream. | |
| 29 class NET_EXPORT_PRIVATE Delegate { | |
| 30 public: | |
| 31 Delegate() {} | |
| 32 | |
| 33 // Called when headers are available. | |
| 34 virtual void OnHeadersAvailable(const SpdyHeaderBlock& headers, | |
| 35 size_t frame_len) = 0; | |
| 36 | |
| 37 // Called when data is available to be read. | |
| 38 virtual void OnDataAvailable() = 0; | |
| 39 | |
| 40 // Called when the stream is closed by the peer. | |
| 41 virtual void OnClose(QuicErrorCode error) = 0; | |
| 42 | |
| 43 // Called when the stream is closed because of an error. | |
| 44 virtual void OnError(int error) = 0; | |
| 45 | |
| 46 // Returns true if sending of headers has completed. | |
| 47 virtual bool HasSendHeadersComplete() = 0; | |
| 48 | |
| 49 protected: | |
| 50 virtual ~Delegate() {} | |
| 51 | |
| 52 private: | |
| 53 DISALLOW_COPY_AND_ASSIGN(Delegate); | |
| 54 }; | |
| 55 | |
| 56 QuicReliableClientStream(QuicStreamId id, | |
| 57 QuicSpdySession* session, | |
| 58 const BoundNetLog& net_log); | |
| 59 | |
| 60 ~QuicReliableClientStream() override; | |
| 61 | |
| 62 // QuicSpdyStream | |
| 63 void OnStreamHeadersComplete(bool fin, size_t frame_len) override; | |
| 64 void OnDataAvailable() override; | |
| 65 void OnClose() override; | |
| 66 void OnCanWrite() override; | |
| 67 SpdyPriority Priority() const override; | |
| 68 | |
| 69 // While the server's set_priority shouldn't be called externally, the creator | |
| 70 // of client-side streams should be able to set the priority. | |
| 71 using QuicSpdyStream::SetPriority; | |
| 72 | |
| 73 int WriteStreamData(base::StringPiece data, | |
| 74 bool fin, | |
| 75 const CompletionCallback& callback); | |
| 76 // Set new |delegate|. |delegate| must not be NULL. | |
| 77 // If this stream has already received data, OnDataReceived() will be | |
| 78 // called on the delegate. | |
| 79 void SetDelegate(Delegate* delegate); | |
| 80 Delegate* GetDelegate() { return delegate_; } | |
| 81 void OnError(int error); | |
| 82 | |
| 83 // Reads at most |buf_len| bytes into |buf|. Returns the number of bytes read. | |
| 84 int Read(IOBuffer* buf, int buf_len); | |
| 85 | |
| 86 // Returns true if the stream can possible write data. (The socket may | |
| 87 // turn out to be write blocked, of course). If the stream can not write, | |
| 88 // this method returns false, and |callback| will be invoked when | |
| 89 // it becomes writable. | |
| 90 bool CanWrite(const CompletionCallback& callback); | |
| 91 | |
| 92 const BoundNetLog& net_log() const { return net_log_; } | |
| 93 | |
| 94 using QuicSpdyStream::HasBufferedData; | |
| 95 | |
| 96 private: | |
| 97 void NotifyDelegateOfHeadersCompleteLater(size_t frame_len); | |
| 98 void NotifyDelegateOfHeadersComplete(size_t frame_len); | |
| 99 void NotifyDelegateOfDataAvailableLater(); | |
| 100 void NotifyDelegateOfDataAvailable(); | |
| 101 | |
| 102 BoundNetLog net_log_; | |
| 103 Delegate* delegate_; | |
| 104 | |
| 105 bool headers_delivered_; | |
| 106 | |
| 107 CompletionCallback callback_; | |
| 108 | |
| 109 base::WeakPtrFactory<QuicReliableClientStream> weak_factory_; | |
| 110 | |
| 111 DISALLOW_COPY_AND_ASSIGN(QuicReliableClientStream); | |
| 112 }; | |
| 113 | |
| 114 } // namespace net | |
| 115 | |
| 116 #endif // NET_QUIC_QUIC_RELIABLE_CLIENT_STREAM_H_ | |
| OLD | NEW |