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

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

Issue 2619493005: Harmonize SpdyFrameType enum values with wire values. (Closed)
Patch Set: Rebase. Created 3 years, 11 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
« 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 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "net/spdy/spdy_bug_tracker.h" 8 #include "net/spdy/spdy_bug_tracker.h"
9 9
10 namespace net { 10 namespace net {
(...skipping 28 matching lines...) Expand all
39 return static_cast<int>(kSteps * (7.f - priority)) + 1; 39 return static_cast<int>(kSteps * (7.f - priority)) + 1;
40 } 40 }
41 41
42 SpdyPriority Http2WeightToSpdy3Priority(int weight) { 42 SpdyPriority Http2WeightToSpdy3Priority(int weight) {
43 weight = ClampHttp2Weight(weight); 43 weight = ClampHttp2Weight(weight);
44 const float kSteps = 255.9f / 7.f; 44 const float kSteps = 255.9f / 7.f;
45 return static_cast<SpdyPriority>(7.f - (weight - 1) / kSteps); 45 return static_cast<SpdyPriority>(7.f - (weight - 1) / kSteps);
46 } 46 }
47 47
48 bool IsValidFrameType(int frame_type_field) { 48 bool IsValidFrameType(int frame_type_field) {
49 // Check for recognized extensions. 49 return frame_type_field >= MIN_FRAME_TYPE &&
50 if (frame_type_field == SerializeFrameType(ALTSVC) || 50 frame_type_field <= MAX_FRAME_TYPE;
51 frame_type_field == SerializeFrameType(BLOCKED)) {
52 return true;
53 }
54
55 // DATA is the first valid frame.
56 if (frame_type_field < SerializeFrameType(DATA)) {
57 return false;
58 }
59
60 // CONTINUATION is the last valid frame.
61 if (frame_type_field > SerializeFrameType(CONTINUATION)) {
62 return false;
63 }
64
65 return true;
66 } 51 }
67 52
68 SpdyFrameType ParseFrameType(int frame_type_field) { 53 SpdyFrameType ParseFrameType(int frame_type_field) {
69 switch (frame_type_field) { 54 SPDY_BUG_IF(!IsValidFrameType(frame_type_field)) << "Invalid frame type.";
70 case 0: 55 return static_cast<SpdyFrameType>(frame_type_field);
71 return DATA;
72 case 1:
73 return HEADERS;
74 case 2:
75 return PRIORITY;
76 case 3:
77 return RST_STREAM;
78 case 4:
79 return SETTINGS;
80 case 5:
81 return PUSH_PROMISE;
82 case 6:
83 return PING;
84 case 7:
85 return GOAWAY;
86 case 8:
87 return WINDOW_UPDATE;
88 case 9:
89 return CONTINUATION;
90 case 10:
91 return ALTSVC;
92 case 11:
93 return BLOCKED;
94 }
95 SPDY_BUG << "Unhandled frame type " << frame_type_field;
96 return DATA;
97 } 56 }
98 57
99 int SerializeFrameType(SpdyFrameType frame_type) { 58 int SerializeFrameType(SpdyFrameType frame_type) {
100 switch (frame_type) { 59 switch (frame_type) {
101 case DATA: 60 case DATA:
102 return kDataFrameType; 61 return kDataFrameType;
103 case HEADERS: 62 case HEADERS:
104 return 1; 63 return 1;
105 case PRIORITY: 64 case PRIORITY:
106 return 2; 65 return 2;
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 465
507 void SpdyAltSvcIR::Visit(SpdyFrameVisitor* visitor) const { 466 void SpdyAltSvcIR::Visit(SpdyFrameVisitor* visitor) const {
508 return visitor->VisitAltSvc(*this); 467 return visitor->VisitAltSvc(*this);
509 } 468 }
510 469
511 void SpdyPriorityIR::Visit(SpdyFrameVisitor* visitor) const { 470 void SpdyPriorityIR::Visit(SpdyFrameVisitor* visitor) const {
512 return visitor->VisitPriority(*this); 471 return visitor->VisitPriority(*this);
513 } 472 }
514 473
515 } // namespace net 474 } // 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