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

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

Issue 10185007: [net] Change order of RequestPriority to natural: higher > lower (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased. Responded to review Created 8 years, 8 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
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_http_utils.h" 5 #include "net/spdy/spdy_http_utils.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/string_number_conversions.h" 9 #include "base/string_number_conversions.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 (*headers)[":version"] = kHttpProtocolVersion; 118 (*headers)[":version"] = kHttpProtocolVersion;
119 (*headers)[":method"] = info.method; 119 (*headers)[":method"] = info.method;
120 (*headers)[":host"] = GetHostAndOptionalPort(info.url); 120 (*headers)[":host"] = GetHostAndOptionalPort(info.url);
121 (*headers)[":scheme"] = info.url.scheme(); 121 (*headers)[":scheme"] = info.url.scheme();
122 (*headers)[":path"] = HttpUtil::PathForRequest(info.url); 122 (*headers)[":path"] = HttpUtil::PathForRequest(info.url);
123 headers->erase("host"); // this is kinda insane, spdy 3 spec. 123 headers->erase("host"); // this is kinda insane, spdy 3 spec.
124 } 124 }
125 125
126 } 126 }
127 127
128 COMPILE_ASSERT(HIGHEST - LOWEST < 4 &&
129 HIGHEST - MINIMUM_PRIORITY < 5,
130 request_priority_incompatible_with_spdy);
szym 2012/04/24 18:15:25 Please, take a look at this assert and the mapping
Ryan Hamilton 2012/04/24 18:45:35 NICE! Love this assert.
131
128 SpdyPriority ConvertRequestPriorityToSpdyPriority( 132 SpdyPriority ConvertRequestPriorityToSpdyPriority(
129 const RequestPriority priority, 133 const RequestPriority priority,
130 int protocol_version) { 134 int protocol_version) {
131 DCHECK(HIGHEST <= priority && priority < NUM_PRIORITIES); 135 DCHECK_GE(priority, MINIMUM_PRIORITY);
136 DCHECK_LT(priority, NUM_PRIORITIES);
132 if (protocol_version == 2) { 137 if (protocol_version == 2) {
133 // SPDY 2 only has 2 bits of priority, but we have 5 RequestPriorities. 138 // SPDY 2 only has 2 bits of priority, but we have 5 RequestPriorities.
134 if (priority < LOWEST) { 139 // Map IDLE => 3, LOWEST => 2, LOW => 2, MEDIUM => 1, HIGHEST => 0.
135 return priority; 140 if (priority > LOWEST) {
141 return static_cast<SpdyPriority>(HIGHEST - priority);
136 } else { 142 } else {
137 DCHECK_GE(4, priority); 143 return static_cast<SpdyPriority>(HIGHEST - priority - 1);
138 return priority - 1;
139 } 144 }
140 } else { 145 } else { // only valid
141 DCHECK_GE(7, priority); 146 return static_cast<SpdyPriority>(HIGHEST - priority);
142 return priority;
143 } 147 }
144 } 148 }
145 149
146 GURL GetUrlFromHeaderBlock(const SpdyHeaderBlock& headers, 150 GURL GetUrlFromHeaderBlock(const SpdyHeaderBlock& headers,
147 int protocol_version, 151 int protocol_version,
148 bool pushed) { 152 bool pushed) {
149 // SPDY 2 server push urls are specified in a single "url" header. 153 // SPDY 2 server push urls are specified in a single "url" header.
150 if (pushed && protocol_version == 2) { 154 if (pushed && protocol_version == 2) {
151 std::string url; 155 std::string url;
152 SpdyHeaderBlock::const_iterator it; 156 SpdyHeaderBlock::const_iterator it;
(...skipping 20 matching lines...) Expand all
173 it = headers.find(path_header); 177 it = headers.find(path_header);
174 if (it != headers.end()) 178 if (it != headers.end())
175 path = it->second; 179 path = it->second;
176 180
177 std::string url = (scheme.empty() || host_port.empty() || path.empty()) 181 std::string url = (scheme.empty() || host_port.empty() || path.empty())
178 ? "" : scheme + "://" + host_port + path; 182 ? "" : scheme + "://" + host_port + path;
179 return GURL(url); 183 return GURL(url);
180 } 184 }
181 185
182 } // namespace net 186 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698