Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(402)

Side by Side Diff: net/spdy/spdy_protocol.cc

Issue 202073003: Introduce new SpdyConstants class (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/spdy/spdy_protocol.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "net/spdy/spdy_protocol.h" 5 #include "net/spdy/spdy_protocol.h"
6 6
7 namespace net { 7 namespace net {
8 8
9 SpdyFrameWithNameValueBlockIR::SpdyFrameWithNameValueBlockIR( 9 SpdyFrameWithNameValueBlockIR::SpdyFrameWithNameValueBlockIR(
10 SpdyStreamId stream_id) : SpdyFrameWithFinIR(stream_id) {} 10 SpdyStreamId stream_id) : SpdyFrameWithFinIR(stream_id) {}
11 11
12 SpdyFrameWithNameValueBlockIR::~SpdyFrameWithNameValueBlockIR() {} 12 SpdyFrameWithNameValueBlockIR::~SpdyFrameWithNameValueBlockIR() {}
13 13
14 SpdyDataIR::SpdyDataIR(SpdyStreamId stream_id, const base::StringPiece& data) 14 SpdyDataIR::SpdyDataIR(SpdyStreamId stream_id, const base::StringPiece& data)
15 : SpdyFrameWithFinIR(stream_id), 15 : SpdyFrameWithFinIR(stream_id),
16 pad_low_(false), 16 pad_low_(false),
17 pad_high_(false), 17 pad_high_(false),
18 padding_payload_len_(0) { 18 padding_payload_len_(0) {
19 SetDataDeep(data); 19 SetDataDeep(data);
20 } 20 }
21 21
22 SpdyDataIR::SpdyDataIR(SpdyStreamId stream_id) 22 SpdyDataIR::SpdyDataIR(SpdyStreamId stream_id)
23 : SpdyFrameWithFinIR(stream_id), 23 : SpdyFrameWithFinIR(stream_id),
24 pad_low_(false), 24 pad_low_(false),
25 pad_high_(false), 25 pad_high_(false),
26 padding_payload_len_(0) {} 26 padding_payload_len_(0) {}
27 27
28 SpdyDataIR::~SpdyDataIR() {} 28 SpdyDataIR::~SpdyDataIR() {}
29 29
30 bool SpdyConstants::IsValidFrameType(SpdyMajorVersion version,
31 int frame_type_field) {
32 switch (version) {
33 case SPDY2:
34 case SPDY3:
35 // SYN_STREAM is the first valid frame.
36 if (frame_type_field < SerializeFrameType(version, SYN_STREAM)) {
37 return false;
38 }
39
40 // WINDOW_UPDATE is the last valid frame.
41 if (frame_type_field > SerializeFrameType(version, WINDOW_UPDATE)) {
42 return false;
43 }
44
45 // The valid range is non-contiguous.
46 if (frame_type_field == NOOP) {
47 return false;
48 }
49
50 return true;
51 case SPDY4:
52 // DATA is the first valid frame.
53 if (frame_type_field < SerializeFrameType(version, DATA)) {
54 return false;
55 }
56
57 // BLOCKED is the last valid frame.
58 if (frame_type_field > SerializeFrameType(version, BLOCKED)) {
59 return false;
60 }
61
62 return true;
63 }
64 }
65
66 SpdyFrameType SpdyConstants::ParseFrameType(SpdyMajorVersion version,
67 int frame_type_field) {
68 switch (version) {
69 case SPDY2:
70 case SPDY3:
71 switch (frame_type_field) {
72 case 1:
73 return SYN_STREAM;
74 case 2:
75 return SYN_REPLY;
76 case 3:
77 return RST_STREAM;
78 case 4:
79 return SETTINGS;
80 case 6:
81 return PING;
82 case 7:
83 return GOAWAY;
84 case 8:
85 return HEADERS;
86 case 9:
87 return WINDOW_UPDATE;
88 default:
89 return DATA;
90 }
91 case SPDY4:
92 switch (frame_type_field) {
93 case 0:
94 return DATA;
95 case 1:
96 return HEADERS;
97 // TODO(hkhalil): Add PRIORITY.
98 case 3:
99 return RST_STREAM;
100 case 4:
101 return SETTINGS;
102 case 5:
103 return PUSH_PROMISE;
104 case 6:
105 return PING;
106 case 7:
107 return GOAWAY;
108 case 8:
109 return WINDOW_UPDATE;
110 case 9:
111 return CONTINUATION;
112 case 10:
113 return BLOCKED;
114 default:
115 return DATA;
116 }
117 }
118 return DATA;
119 }
120
121 int SpdyConstants::SerializeFrameType(SpdyMajorVersion version,
122 SpdyFrameType frame_type) {
123 switch (version) {
124 case SPDY2:
125 case SPDY3:
126 switch (frame_type) {
127 case SYN_STREAM:
128 return 1;
129 case SYN_REPLY:
130 return 2;
131 case RST_STREAM:
132 return 3;
133 case SETTINGS:
134 return 4;
135 case PING:
136 return 6;
137 case GOAWAY:
138 return 7;
139 case HEADERS:
140 return 8;
141 case WINDOW_UPDATE:
142 return 9;
143 default:
144 return -1;
145 }
146 case SPDY4:
147 switch (frame_type) {
148 case DATA:
149 return 0;
150 case HEADERS:
151 return 1;
152 // TODO(hkhalil): Add PRIORITY.
153 case RST_STREAM:
154 return 3;
155 case SETTINGS:
156 return 4;
157 case PUSH_PROMISE:
158 return 5;
159 case PING:
160 return 6;
161 case GOAWAY:
162 return 7;
163 case WINDOW_UPDATE:
164 return 8;
165 case CONTINUATION:
166 return 9;
167 case BLOCKED:
168 return 10;
169 default:
170 return -1;
171 }
172 }
173 }
174
30 void SpdyDataIR::Visit(SpdyFrameVisitor* visitor) const { 175 void SpdyDataIR::Visit(SpdyFrameVisitor* visitor) const {
31 return visitor->VisitData(*this); 176 return visitor->VisitData(*this);
32 } 177 }
33 178
34 void SpdySynStreamIR::Visit(SpdyFrameVisitor* visitor) const { 179 void SpdySynStreamIR::Visit(SpdyFrameVisitor* visitor) const {
35 return visitor->VisitSynStream(*this); 180 return visitor->VisitSynStream(*this);
36 } 181 }
37 182
38 void SpdySynReplyIR::Visit(SpdyFrameVisitor* visitor) const { 183 void SpdySynReplyIR::Visit(SpdyFrameVisitor* visitor) const {
39 return visitor->VisitSynReply(*this); 184 return visitor->VisitSynReply(*this);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 244
100 void SpdyPushPromiseIR::Visit(SpdyFrameVisitor* visitor) const { 245 void SpdyPushPromiseIR::Visit(SpdyFrameVisitor* visitor) const {
101 return visitor->VisitPushPromise(*this); 246 return visitor->VisitPushPromise(*this);
102 } 247 }
103 248
104 void SpdyContinuationIR::Visit(SpdyFrameVisitor* visitor) const { 249 void SpdyContinuationIR::Visit(SpdyFrameVisitor* visitor) const {
105 return visitor->VisitContinuation(*this); 250 return visitor->VisitContinuation(*this);
106 } 251 }
107 252
108 } // namespace net 253 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_protocol.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698