OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 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 #ifndef NET_SPDY_SPDY_WEBSOCKET_STREAM_H_ |
| 6 #define NET_SPDY_SPDY_WEBSOCKET_STREAM_H_ |
| 7 #pragma once |
| 8 |
| 9 #include "base/linked_ptr.h" |
| 10 #include "base/ref_counted.h" |
| 11 #include "base/time.h" |
| 12 #include "net/base/completion_callback.h" |
| 13 #include "net/base/request_priority.h" |
| 14 #include "net/spdy/spdy_framer.h" |
| 15 #include "net/spdy/spdy_stream.h" |
| 16 |
| 17 class GURL; |
| 18 |
| 19 namespace net { |
| 20 |
| 21 class SpdyWebSocketStream; |
| 22 |
| 23 // The SpdyWebSocketStream is a WebSocket-specific type of stream known to |
| 24 // a SpdySession. |
| 25 class SpdyWebSocketStreamDelegate { |
| 26 public: |
| 27 virtual void OnCreatedSpdyStream( |
| 28 SpdyWebSocketStream* spdy_websocket_stream, int result) = 0; |
| 29 virtual void OnSentSpdyHeaders( |
| 30 SpdyWebSocketStream* spdy_websocket_stream) = 0; |
| 31 virtual int OnReceivedSpdyResponseHeader( |
| 32 SpdyWebSocketStream* spdy_websocket_stream, |
| 33 const spdy::SpdyHeaderBlock& headers, |
| 34 int status) = 0; |
| 35 virtual void OnSentSpdyData( |
| 36 SpdyWebSocketStream* spdy_websocket_stream, int amount_sent) = 0; |
| 37 virtual void OnReceivedSpdyData( |
| 38 SpdyWebSocketStream* spdy_websocket_stream, |
| 39 const char* data, int length) = 0; |
| 40 virtual void OnCloseSpdyStream( |
| 41 SpdyWebSocketStream* spdy_websocket_stream) = 0; |
| 42 }; |
| 43 |
| 44 class SpdyWebSocketStream : public SpdyStream::Delegate { |
| 45 public: |
| 46 SpdyWebSocketStream(SpdySession* spdy_session, |
| 47 SpdyWebSocketStreamDelegate* delegate); |
| 48 virtual ~SpdyWebSocketStream(); |
| 49 |
| 50 // Initializes SPDY stream for the WebSocket. |
| 51 // It might create SPDY stream asynchronously. In this case, this method |
| 52 // returns ERR_IO_PENDING. |
| 53 // In any case, delegate's OnCreatedSpdyStream will be called with result |
| 54 // that indicates SPDY stream is created or not. |
| 55 int InitializeStream(const GURL& url, |
| 56 RequestPriority request_priority, |
| 57 const BoundNetLog& stream_net_log); |
| 58 |
| 59 void SendRequest(linked_ptr<spdy::SpdyHeaderBlock> headers); |
| 60 void SendData(const char* data, int length); |
| 61 void Close(); |
| 62 |
| 63 // SpdyStream::Delegate |
| 64 virtual bool OnSendHeadersComplete(int status); |
| 65 virtual int OnSendBody(); |
| 66 virtual bool OnSendBodyComplete(int status); |
| 67 virtual bool IsFinishedSendingBody(); |
| 68 virtual int OnResponseReceived(const spdy::SpdyHeaderBlock& response, |
| 69 base::Time response_time, |
| 70 int status); |
| 71 virtual void OnDataReceived(const char* data, int length); |
| 72 virtual void OnDataSent(int length); |
| 73 virtual void OnClose(int status); |
| 74 |
| 75 spdy::SpdyStreamId stream_id() const { |
| 76 if (!stream_) |
| 77 return 0; |
| 78 return stream_->stream_id(); |
| 79 } |
| 80 |
| 81 private: |
| 82 void OnIOCompleted(int status); |
| 83 void OnSpdyStreamCreated(int status); |
| 84 |
| 85 scoped_refptr<SpdyStream> stream_; |
| 86 scoped_refptr<SpdySession> spdy_session_; |
| 87 SpdyWebSocketStreamDelegate* delegate_; |
| 88 |
| 89 CompletionCallbackImpl<SpdyWebSocketStream> io_callback_; |
| 90 |
| 91 DISALLOW_COPY_AND_ASSIGN(SpdyWebSocketStream); |
| 92 }; |
| 93 |
| 94 } // namespace net |
| 95 |
| 96 #endif // NET_SPDY_SPDY_WEBSOCKET_STREAM_H_ |
OLD | NEW |