| 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 // This file contains some protocol structures for use with SPDY 3 and HTTP 2 | 5 // This file contains some protocol structures for use with SPDY 3 and HTTP 2 |
| 6 // The SPDY 3 spec can be found at: | 6 // The SPDY 3 spec can be found at: |
| 7 // http://dev.chromium.org/spdy/spdy-protocol/spdy-protocol-draft3 | 7 // http://dev.chromium.org/spdy/spdy-protocol/spdy-protocol-draft3 |
| 8 | 8 |
| 9 #ifndef NET_SPDY_SPDY_PROTOCOL_H_ | 9 #ifndef NET_SPDY_SPDY_PROTOCOL_H_ |
| 10 #define NET_SPDY_SPDY_PROTOCOL_H_ | 10 #define NET_SPDY_SPDY_PROTOCOL_H_ |
| (...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 515 | 515 |
| 516 // Initial window size for a stream in bytes. | 516 // Initial window size for a stream in bytes. |
| 517 static int32_t GetInitialStreamWindowSize(SpdyMajorVersion version); | 517 static int32_t GetInitialStreamWindowSize(SpdyMajorVersion version); |
| 518 | 518 |
| 519 // Initial window size for a session in bytes. | 519 // Initial window size for a session in bytes. |
| 520 static int32_t GetInitialSessionWindowSize(SpdyMajorVersion version); | 520 static int32_t GetInitialSessionWindowSize(SpdyMajorVersion version); |
| 521 | 521 |
| 522 static std::string GetVersionString(SpdyMajorVersion version); | 522 static std::string GetVersionString(SpdyMajorVersion version); |
| 523 }; | 523 }; |
| 524 | 524 |
| 525 class SpdyFrame; | |
| 526 typedef SpdyFrame SpdySerializedFrame; | |
| 527 | |
| 528 class SpdyFrameVisitor; | 525 class SpdyFrameVisitor; |
| 529 | 526 |
| 530 // Intermediate representation for SPDY frames. | 527 // Intermediate representation for SPDY frames. |
| 531 // TODO(hkhalil): Rename this class to SpdyFrame when the existing SpdyFrame is | |
| 532 // gone. | |
| 533 class NET_EXPORT_PRIVATE SpdyFrameIR { | 528 class NET_EXPORT_PRIVATE SpdyFrameIR { |
| 534 public: | 529 public: |
| 535 virtual ~SpdyFrameIR() {} | 530 virtual ~SpdyFrameIR() {} |
| 536 | 531 |
| 537 virtual void Visit(SpdyFrameVisitor* visitor) const = 0; | 532 virtual void Visit(SpdyFrameVisitor* visitor) const = 0; |
| 538 | 533 |
| 539 protected: | 534 protected: |
| 540 SpdyFrameIR() {} | 535 SpdyFrameIR() {} |
| 541 | 536 |
| 542 private: | 537 private: |
| (...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 980 | 975 |
| 981 void Visit(SpdyFrameVisitor* visitor) const override; | 976 void Visit(SpdyFrameVisitor* visitor) const override; |
| 982 | 977 |
| 983 private: | 978 private: |
| 984 SpdyStreamId parent_stream_id_; | 979 SpdyStreamId parent_stream_id_; |
| 985 uint8_t weight_; | 980 uint8_t weight_; |
| 986 bool exclusive_; | 981 bool exclusive_; |
| 987 DISALLOW_COPY_AND_ASSIGN(SpdyPriorityIR); | 982 DISALLOW_COPY_AND_ASSIGN(SpdyPriorityIR); |
| 988 }; | 983 }; |
| 989 | 984 |
| 990 // ------------------------------------------------------------------------- | 985 class SpdySerializedFrame { |
| 991 // Wrapper classes for various SPDY frames. | 986 public: |
| 987 SpdySerializedFrame() |
| 988 : frame_(const_cast<char*>("")), size_(0), owns_buffer_(false) {} |
| 992 | 989 |
| 993 // All Spdy Frame types derive from this SpdyFrame class. | 990 // Create a valid SpdySerializedFrame using a pre-created buffer. |
| 994 class SpdyFrame { | 991 // If |owns_buffer| is true, this class takes ownership of the buffer and will |
| 995 public: | 992 // delete it on cleanup. The buffer must have been created using new char[]. |
| 996 // Create a SpdyFrame using a pre-created buffer. | |
| 997 // If |owns_buffer| is true, this class takes ownership of the buffer | |
| 998 // and will delete it on cleanup. The buffer must have been created using | |
| 999 // new char[]. | |
| 1000 // If |owns_buffer| is false, the caller retains ownership of the buffer and | 993 // If |owns_buffer| is false, the caller retains ownership of the buffer and |
| 1001 // is responsible for making sure the buffer outlives this frame. In other | 994 // is responsible for making sure the buffer outlives this frame. In other |
| 1002 // words, this class does NOT create a copy of the buffer. | 995 // words, this class does NOT create a copy of the buffer. |
| 1003 SpdyFrame(char* data, size_t size, bool owns_buffer) | 996 SpdySerializedFrame(char* data, size_t size, bool owns_buffer) |
| 1004 : frame_(data), | 997 : frame_(data), size_(size), owns_buffer_(owns_buffer) {} |
| 1005 size_(size), | 998 |
| 1006 owns_buffer_(owns_buffer) { | 999 SpdySerializedFrame(SpdySerializedFrame&& other) |
| 1007 DCHECK(frame_); | 1000 : frame_(other.frame_), |
| 1001 size_(other.size_), |
| 1002 owns_buffer_(other.owns_buffer_) { |
| 1003 // |other| is no longer responsible for the buffer. |
| 1004 other.owns_buffer_ = false; |
| 1008 } | 1005 } |
| 1009 | 1006 |
| 1010 ~SpdyFrame() { | 1007 SpdySerializedFrame& operator=(SpdySerializedFrame&& other) { |
| 1008 // Free buffer if necessary. |
| 1011 if (owns_buffer_) { | 1009 if (owns_buffer_) { |
| 1012 delete [] frame_; | 1010 delete[] frame_; |
| 1013 } | 1011 } |
| 1014 frame_ = NULL; | 1012 // Take over |other|. |
| 1013 frame_ = other.frame_; |
| 1014 size_ = other.size_; |
| 1015 owns_buffer_ = other.owns_buffer_; |
| 1016 // |other| is no longer responsible for the buffer. |
| 1017 other.owns_buffer_ = false; |
| 1018 return *this; |
| 1015 } | 1019 } |
| 1016 | 1020 |
| 1017 // Provides access to the frame bytes, which is a buffer containing | 1021 ~SpdySerializedFrame() { |
| 1018 // the frame packed as expected for sending over the wire. | 1022 if (owns_buffer_) { |
| 1023 delete[] frame_; |
| 1024 } |
| 1025 } |
| 1026 |
| 1027 // Provides access to the frame bytes, which is a buffer containing the frame |
| 1028 // packed as expected for sending over the wire. |
| 1019 char* data() const { return frame_; } | 1029 char* data() const { return frame_; } |
| 1020 | 1030 |
| 1021 // Returns the actual size of the underlying buffer. | 1031 // Returns the actual size of the underlying buffer. |
| 1022 size_t size() const { return size_; } | 1032 size_t size() const { return size_; } |
| 1023 | 1033 |
| 1024 protected: | 1034 protected: |
| 1025 char* frame_; | 1035 char* frame_; |
| 1026 | 1036 |
| 1027 private: | 1037 private: |
| 1028 size_t size_; | 1038 size_t size_; |
| 1029 bool owns_buffer_; | 1039 bool owns_buffer_; |
| 1030 DISALLOW_COPY_AND_ASSIGN(SpdyFrame); | 1040 DISALLOW_COPY_AND_ASSIGN(SpdySerializedFrame); |
| 1031 }; | 1041 }; |
| 1032 | 1042 |
| 1033 // This interface is for classes that want to process SpdyFrameIRs without | 1043 // This interface is for classes that want to process SpdyFrameIRs without |
| 1034 // having to know what type they are. An instance of this interface can be | 1044 // having to know what type they are. An instance of this interface can be |
| 1035 // passed to a SpdyFrameIR's Visit method, and the appropriate type-specific | 1045 // passed to a SpdyFrameIR's Visit method, and the appropriate type-specific |
| 1036 // method of this class will be called. | 1046 // method of this class will be called. |
| 1037 class SpdyFrameVisitor { | 1047 class SpdyFrameVisitor { |
| 1038 public: | 1048 public: |
| 1039 virtual void VisitSynStream(const SpdySynStreamIR& syn_stream) = 0; | 1049 virtual void VisitSynStream(const SpdySynStreamIR& syn_stream) = 0; |
| 1040 virtual void VisitSynReply(const SpdySynReplyIR& syn_reply) = 0; | 1050 virtual void VisitSynReply(const SpdySynReplyIR& syn_reply) = 0; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1055 SpdyFrameVisitor() {} | 1065 SpdyFrameVisitor() {} |
| 1056 virtual ~SpdyFrameVisitor() {} | 1066 virtual ~SpdyFrameVisitor() {} |
| 1057 | 1067 |
| 1058 private: | 1068 private: |
| 1059 DISALLOW_COPY_AND_ASSIGN(SpdyFrameVisitor); | 1069 DISALLOW_COPY_AND_ASSIGN(SpdyFrameVisitor); |
| 1060 }; | 1070 }; |
| 1061 | 1071 |
| 1062 } // namespace net | 1072 } // namespace net |
| 1063 | 1073 |
| 1064 #endif // NET_SPDY_SPDY_PROTOCOL_H_ | 1074 #endif // NET_SPDY_SPDY_PROTOCOL_H_ |
| OLD | NEW |