| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef NET_SPDY_BUFFERED_SPDY_FRAMER_H_ | 5 #ifndef NET_SPDY_BUFFERED_SPDY_FRAMER_H_ |
| 6 #define NET_SPDY_BUFFERED_SPDY_FRAMER_H_ | 6 #define NET_SPDY_BUFFERED_SPDY_FRAMER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 | 44 |
| 45 // Called after a RST_STREAM frame is received. | 45 // Called after a RST_STREAM frame is received. |
| 46 virtual void OnRstStream(const spdy::SpdyRstStreamControlFrame& frame) = 0; | 46 virtual void OnRstStream(const spdy::SpdyRstStreamControlFrame& frame) = 0; |
| 47 | 47 |
| 48 // Called after a GOAWAY frame is received. | 48 // Called after a GOAWAY frame is received. |
| 49 virtual void OnGoAway(const spdy::SpdyGoAwayControlFrame& frame) = 0; | 49 virtual void OnGoAway(const spdy::SpdyGoAwayControlFrame& frame) = 0; |
| 50 | 50 |
| 51 // Called after a PING frame is received. | 51 // Called after a PING frame is received. |
| 52 virtual void OnPing(const spdy::SpdyPingControlFrame& frame) = 0; | 52 virtual void OnPing(const spdy::SpdyPingControlFrame& frame) = 0; |
| 53 | 53 |
| 54 // Called after a SETTINGS frame is received. | |
| 55 virtual void OnSettings(const spdy::SpdySettingsControlFrame& frame) = 0; | |
| 56 | |
| 57 // Called after a WINDOW_UPDATE frame is received. | 54 // Called after a WINDOW_UPDATE frame is received. |
| 58 virtual void OnWindowUpdate( | 55 virtual void OnWindowUpdate( |
| 59 const spdy::SpdyWindowUpdateControlFrame& frame) = 0; | 56 const spdy::SpdyWindowUpdateControlFrame& frame) = 0; |
| 60 | 57 |
| 61 // Called when data is received. | 58 // Called when data is received. |
| 62 // |stream_id| The stream receiving data. | 59 // |stream_id| The stream receiving data. |
| 63 // |data| A buffer containing the data received. | 60 // |data| A buffer containing the data received. |
| 64 // |len| The length of the data buffer. | 61 // |len| The length of the data buffer. |
| 65 // When the other side has finished sending data on this stream, | 62 // When the other side has finished sending data on this stream, |
| 66 // this method will be called with a zero-length buffer. | 63 // this method will be called with a zero-length buffer. |
| 67 virtual void OnStreamFrameData(SpdyStreamId stream_id, | 64 virtual void OnStreamFrameData(SpdyStreamId stream_id, |
| 68 const char* data, | 65 const char* data, |
| 69 size_t len) = 0; | 66 size_t len) = 0; |
| 70 | 67 |
| 68 // Called when an individual setting within a SETTINGS frame has been parsed |
| 69 // and validated. |
| 70 virtual void OnSetting(SpdySettingsIds id, uint8 flags, uint32 value) = 0; |
| 71 |
| 71 private: | 72 private: |
| 72 DISALLOW_COPY_AND_ASSIGN(BufferedSpdyFramerVisitorInterface); | 73 DISALLOW_COPY_AND_ASSIGN(BufferedSpdyFramerVisitorInterface); |
| 73 }; | 74 }; |
| 74 | 75 |
| 75 class NET_EXPORT_PRIVATE BufferedSpdyFramer | 76 class NET_EXPORT_PRIVATE BufferedSpdyFramer |
| 76 : public SpdyFramerVisitorInterface { | 77 : public SpdyFramerVisitorInterface { |
| 77 public: | 78 public: |
| 78 explicit BufferedSpdyFramer(int version); | 79 explicit BufferedSpdyFramer(int version); |
| 79 virtual ~BufferedSpdyFramer(); | 80 virtual ~BufferedSpdyFramer(); |
| 80 | 81 |
| 81 // Sets callbacks to be called from the buffered spdy framer. A visitor must | 82 // Sets callbacks to be called from the buffered spdy framer. A visitor must |
| 82 // be set, or else the framer will likely crash. It is acceptable for the | 83 // be set, or else the framer will likely crash. It is acceptable for the |
| 83 // visitor to do nothing. If this is called multiple times, only the last | 84 // visitor to do nothing. If this is called multiple times, only the last |
| 84 // visitor will be used. | 85 // visitor will be used. |
| 85 void set_visitor(BufferedSpdyFramerVisitorInterface* visitor); | 86 void set_visitor(BufferedSpdyFramerVisitorInterface* visitor); |
| 86 | 87 |
| 87 // SpdyFramerVisitorInterface | 88 // SpdyFramerVisitorInterface |
| 88 virtual void OnError(spdy::SpdyFramer* spdy_framer) OVERRIDE; | 89 virtual void OnError(spdy::SpdyFramer* spdy_framer) OVERRIDE; |
| 89 virtual void OnControl(const SpdyControlFrame* frame) OVERRIDE; | 90 virtual void OnControl(const SpdyControlFrame* frame) OVERRIDE; |
| 90 virtual bool OnCredentialFrameData(const char* frame_data, | 91 virtual bool OnCredentialFrameData(const char* frame_data, |
| 91 size_t len) OVERRIDE; | 92 size_t len) OVERRIDE; |
| 92 virtual bool OnControlFrameHeaderData(SpdyStreamId stream_id, | 93 virtual bool OnControlFrameHeaderData(SpdyStreamId stream_id, |
| 93 const char* header_data, | 94 const char* header_data, |
| 94 size_t len) OVERRIDE; | 95 size_t len) OVERRIDE; |
| 95 virtual void OnStreamFrameData(SpdyStreamId stream_id, | 96 virtual void OnStreamFrameData(SpdyStreamId stream_id, |
| 96 const char* data, | 97 const char* data, |
| 97 size_t len) OVERRIDE; | 98 size_t len) OVERRIDE; |
| 99 virtual void OnSetting( |
| 100 SpdySettingsIds id, uint8 flags, uint32 value) OVERRIDE; |
| 98 virtual void OnDataFrameHeader(const SpdyDataFrame* frame) OVERRIDE; | 101 virtual void OnDataFrameHeader(const SpdyDataFrame* frame) OVERRIDE; |
| 99 | 102 |
| 100 // SpdyFramer methods. | 103 // SpdyFramer methods. |
| 101 size_t ProcessInput(const char* data, size_t len); | 104 size_t ProcessInput(const char* data, size_t len); |
| 102 int protocol_version(); | 105 int protocol_version(); |
| 103 void Reset(); | 106 void Reset(); |
| 104 SpdyFramer::SpdyError error_code() const; | 107 SpdyFramer::SpdyError error_code() const; |
| 105 SpdyFramer::SpdyState state() const; | 108 SpdyFramer::SpdyState state() const; |
| 106 bool MessageFullyRead(); | 109 bool MessageFullyRead(); |
| 107 bool HasError(); | 110 bool HasError(); |
| 108 bool ParseHeaderBlock(const SpdyFrame* frame, SpdyHeaderBlock* block); | |
| 109 SpdySynStreamControlFrame* CreateSynStream(SpdyStreamId stream_id, | 111 SpdySynStreamControlFrame* CreateSynStream(SpdyStreamId stream_id, |
| 110 SpdyStreamId associated_stream_id, | 112 SpdyStreamId associated_stream_id, |
| 111 int priority, | 113 int priority, |
| 112 SpdyControlFlags flags, | 114 SpdyControlFlags flags, |
| 113 bool compressed, | 115 bool compressed, |
| 114 const SpdyHeaderBlock* headers); | 116 const SpdyHeaderBlock* headers); |
| 115 SpdySynReplyControlFrame* CreateSynReply(SpdyStreamId stream_id, | 117 SpdySynReplyControlFrame* CreateSynReply(SpdyStreamId stream_id, |
| 116 SpdyControlFlags flags, | 118 SpdyControlFlags flags, |
| 117 bool compressed, | 119 bool compressed, |
| 118 const SpdyHeaderBlock* headers); | 120 const SpdyHeaderBlock* headers); |
| 119 SpdyRstStreamControlFrame* CreateRstStream(SpdyStreamId stream_id, | 121 SpdyRstStreamControlFrame* CreateRstStream(SpdyStreamId stream_id, |
| 120 SpdyStatusCodes status) const; | 122 SpdyStatusCodes status) const; |
| 121 SpdySettingsControlFrame* CreateSettings(const SpdySettings& values) const; | 123 SpdySettingsControlFrame* CreateSettings(const SpdySettings& values) const; |
| 122 SpdyPingControlFrame* CreatePingFrame(uint32 unique_id) const; | 124 SpdyPingControlFrame* CreatePingFrame(uint32 unique_id) const; |
| 123 SpdyGoAwayControlFrame* CreateGoAway( | 125 SpdyGoAwayControlFrame* CreateGoAway( |
| 124 SpdyStreamId last_accepted_stream_id) const; | 126 SpdyStreamId last_accepted_stream_id) const; |
| 125 SpdyHeadersControlFrame* CreateHeaders(SpdyStreamId stream_id, | 127 SpdyHeadersControlFrame* CreateHeaders(SpdyStreamId stream_id, |
| 126 SpdyControlFlags flags, | 128 SpdyControlFlags flags, |
| 127 bool compressed, | 129 bool compressed, |
| 128 const SpdyHeaderBlock* headers); | 130 const SpdyHeaderBlock* headers); |
| 129 SpdyWindowUpdateControlFrame* CreateWindowUpdate( | 131 SpdyWindowUpdateControlFrame* CreateWindowUpdate( |
| 130 SpdyStreamId stream_id, | 132 SpdyStreamId stream_id, |
| 131 uint32 delta_window_size) const; | 133 uint32 delta_window_size) const; |
| 132 SpdyCredentialControlFrame* CreateCredentialFrame( | 134 SpdyCredentialControlFrame* CreateCredentialFrame( |
| 133 const spdy::SpdyCredential& credential) const; | 135 const spdy::SpdyCredential& credential) const; |
| 134 SpdyDataFrame* CreateDataFrame(SpdyStreamId stream_id, | 136 SpdyDataFrame* CreateDataFrame(SpdyStreamId stream_id, |
| 135 const char* data, | 137 const char* data, |
| 136 uint32 len, | 138 uint32 len, |
| 137 SpdyDataFlags flags); | 139 SpdyDataFlags flags); |
| 140 SpdyPriority GetHighestPriority() const; |
| 138 SpdyFrame* CompressFrame(const SpdyFrame& frame); | 141 SpdyFrame* CompressFrame(const SpdyFrame& frame); |
| 139 bool IsCompressible(const SpdyFrame& frame) const; | 142 bool IsCompressible(const SpdyFrame& frame) const; |
| 140 | 143 |
| 141 int frames_received() const { return frames_received_; } | 144 int frames_received() const { return frames_received_; } |
| 142 | 145 |
| 143 private: | 146 private: |
| 144 // The size of the header_buffer_. | 147 // The size of the header_buffer_. |
| 145 enum { kHeaderBufferSize = 32 * 1024 }; | 148 enum { kHeaderBufferSize = 32 * 1024 }; |
| 146 | 149 |
| 147 void InitHeaderStreaming(const SpdyControlFrame* frame); | 150 void InitHeaderStreaming(const SpdyControlFrame* frame); |
| 148 | 151 |
| 149 SpdyFramer spdy_framer_; | 152 SpdyFramer spdy_framer_; |
| 150 BufferedSpdyFramerVisitorInterface* visitor_; | 153 BufferedSpdyFramerVisitorInterface* visitor_; |
| 151 | 154 |
| 152 // Header block streaming state: | 155 // Header block streaming state: |
| 153 char header_buffer_[kHeaderBufferSize]; | 156 char header_buffer_[kHeaderBufferSize]; |
| 154 size_t header_buffer_used_; | 157 size_t header_buffer_used_; |
| 155 bool header_buffer_valid_; | 158 bool header_buffer_valid_; |
| 156 SpdyStreamId header_stream_id_; | 159 SpdyStreamId header_stream_id_; |
| 157 scoped_ptr<SpdyFrame> control_frame_; | 160 scoped_ptr<SpdyFrame> control_frame_; |
| 158 int frames_received_; | 161 int frames_received_; |
| 159 | 162 |
| 160 DISALLOW_COPY_AND_ASSIGN(BufferedSpdyFramer); | 163 DISALLOW_COPY_AND_ASSIGN(BufferedSpdyFramer); |
| 161 }; | 164 }; |
| 162 | 165 |
| 163 } // namespace spdy | 166 } // namespace spdy |
| 164 | 167 |
| 165 #endif // NET_SPDY_BUFFERED_SPDY_FRAMER_H_ | 168 #endif // NET_SPDY_BUFFERED_SPDY_FRAMER_H_ |
| OLD | NEW |