- add sources.
[platform/framework/web/crosswalk.git] / src / net / quic / quic_reliable_client_stream.h
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 "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/reliable_quic_stream.h"
16
17 namespace net {
18
19 class QuicClientSession;
20
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 ReliableQuicStream {
24  public:
25   // Delegate handles protocol specific behavior of a quic stream.
26   class NET_EXPORT_PRIVATE Delegate {
27    public:
28     Delegate() {}
29
30     // Called when stream is ready to send data.
31     // Returns network error code. OK when it successfully sent data.
32     // ERR_IO_PENDING when performing operation asynchronously.
33     virtual int OnSendData() = 0;
34
35     // Called when data has been sent. |status| indicates network error
36     // or number of bytes that has been sent. On return, |eof| is set to true
37     // if no more data is available to send.
38     // Returns network error code. OK when it successfully sent data.
39     virtual int OnSendDataComplete(int status, bool* eof) = 0;
40
41     // Called when data is received.
42     // Returns network error code. OK when it successfully receives data.
43     virtual int OnDataReceived(const char* data, int length) = 0;
44
45     // Called when the stream is closed by the peer.
46     virtual void OnClose(QuicErrorCode error) = 0;
47
48     // Called when the stream is closed because of an error.
49     virtual void OnError(int error) = 0;
50
51     // Returns true if sending of headers has completed.
52     virtual bool HasSendHeadersComplete() = 0;
53
54    protected:
55     virtual ~Delegate() {}
56
57    private:
58     DISALLOW_COPY_AND_ASSIGN(Delegate);
59   };
60
61   QuicReliableClientStream(QuicStreamId id,
62                            QuicSession* session,
63                            const BoundNetLog& net_log);
64
65   virtual ~QuicReliableClientStream();
66
67   // ReliableQuicStream
68   virtual uint32 ProcessData(const char* data, uint32 data_len) OVERRIDE;
69   virtual void TerminateFromPeer(bool half_close) OVERRIDE;
70   virtual void OnCanWrite() OVERRIDE;
71   virtual QuicPriority EffectivePriority() const OVERRIDE;
72
73   // While the server's set_priority shouldn't be called externally, the creator
74   // of client-side streams should be able to set the priority.
75   using ReliableQuicStream::set_priority;
76
77   int WriteStreamData(base::StringPiece data,
78                       bool fin,
79                       const CompletionCallback& callback);
80   // Set new |delegate|. |delegate| must not be NULL.
81   // If this stream has already received data, OnDataReceived() will be
82   // called on the delegate.
83   void SetDelegate(Delegate* delegate);
84   Delegate* GetDelegate() { return delegate_; }
85   void OnError(int error);
86
87   const BoundNetLog& net_log() const { return net_log_; }
88
89  private:
90   BoundNetLog net_log_;
91   Delegate* delegate_;
92
93   CompletionCallback callback_;
94
95   DISALLOW_COPY_AND_ASSIGN(QuicReliableClientStream);
96 };
97
98 }  // namespace net
99
100 #endif  // NET_QUIC_QUIC_RELIABLE_CLIENT_STREAM_H_