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

Side by Side Diff: net/http/http_alternate_protocols.cc

Issue 3195015: Add option to simulate alternate protocol always being present.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 10 years, 4 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/http/http_alternate_protocols.h ('k') | net/http/http_alternate_protocols_unittest.cc » ('j') | 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/http/http_alternate_protocols.h" 5 #include "net/http/http_alternate_protocols.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/stl_util-inl.h" 8 #include "base/stl_util-inl.h"
9 9
10 namespace net { 10 namespace net {
11 11
12 const char HttpAlternateProtocols::kHeader[] = "Alternate-Protocol"; 12 const char HttpAlternateProtocols::kHeader[] = "Alternate-Protocol";
13 const char* const HttpAlternateProtocols::kProtocolStrings[] = { 13 const char* const HttpAlternateProtocols::kProtocolStrings[] = {
14 "npn-spdy/1", 14 "npn-spdy/1",
15 "npn-spdy/2", 15 "npn-spdy/2",
16 }; 16 };
17 17
18 // static
19 HttpAlternateProtocols::PortProtocolPair*
20 HttpAlternateProtocols::forced_alternate_protocol_ = NULL;
21
18 HttpAlternateProtocols::HttpAlternateProtocols() {} 22 HttpAlternateProtocols::HttpAlternateProtocols() {}
19 HttpAlternateProtocols::~HttpAlternateProtocols() {} 23 HttpAlternateProtocols::~HttpAlternateProtocols() {}
20 24
21 bool HttpAlternateProtocols::HasAlternateProtocolFor( 25 bool HttpAlternateProtocols::HasAlternateProtocolFor(
22 const HostPortPair& http_host_port_pair) const { 26 const HostPortPair& http_host_port_pair) const {
23 return ContainsKey(protocol_map_, http_host_port_pair); 27 return ContainsKey(protocol_map_, http_host_port_pair) ||
28 forced_alternate_protocol_;
24 } 29 }
25 30
26 bool HttpAlternateProtocols::HasAlternateProtocolFor( 31 bool HttpAlternateProtocols::HasAlternateProtocolFor(
27 const std::string& host, uint16 port) const { 32 const std::string& host, uint16 port) const {
28 HostPortPair http_host_port_pair(host, port); 33 HostPortPair http_host_port_pair(host, port);
29 return HasAlternateProtocolFor(http_host_port_pair); 34 return HasAlternateProtocolFor(http_host_port_pair);
30 } 35 }
31 36
32 HttpAlternateProtocols::PortProtocolPair 37 HttpAlternateProtocols::PortProtocolPair
33 HttpAlternateProtocols::GetAlternateProtocolFor( 38 HttpAlternateProtocols::GetAlternateProtocolFor(
34 const HostPortPair& http_host_port_pair) const { 39 const HostPortPair& http_host_port_pair) const {
35 DCHECK(ContainsKey(protocol_map_, http_host_port_pair)); 40 DCHECK(HasAlternateProtocolFor(http_host_port_pair));
36 return protocol_map_.find(http_host_port_pair)->second; 41
42 // First check the map.
43 ProtocolMap::const_iterator it = protocol_map_.find(http_host_port_pair);
44 if (it != protocol_map_.end())
45 return it->second;
46
47 // We must be forcing an alternate.
48 DCHECK(forced_alternate_protocol_);
49 return *forced_alternate_protocol_;
37 } 50 }
38 51
39 HttpAlternateProtocols::PortProtocolPair 52 HttpAlternateProtocols::PortProtocolPair
40 HttpAlternateProtocols::GetAlternateProtocolFor( 53 HttpAlternateProtocols::GetAlternateProtocolFor(
41 const std::string& host, uint16 port) const { 54 const std::string& host, uint16 port) const {
42 HostPortPair http_host_port_pair(host, port); 55 HostPortPair http_host_port_pair(host, port);
43 return GetAlternateProtocolFor(http_host_port_pair); 56 return GetAlternateProtocolFor(http_host_port_pair);
44 } 57 }
45 58
46 void HttpAlternateProtocols::SetAlternateProtocolFor( 59 void HttpAlternateProtocols::SetAlternateProtocolFor(
(...skipping 29 matching lines...) Expand all
76 } 89 }
77 90
78 protocol_map_[http_host_port_pair] = alternate; 91 protocol_map_[http_host_port_pair] = alternate;
79 } 92 }
80 93
81 void HttpAlternateProtocols::MarkBrokenAlternateProtocolFor( 94 void HttpAlternateProtocols::MarkBrokenAlternateProtocolFor(
82 const HostPortPair& http_host_port_pair) { 95 const HostPortPair& http_host_port_pair) {
83 protocol_map_[http_host_port_pair].protocol = BROKEN; 96 protocol_map_[http_host_port_pair].protocol = BROKEN;
84 } 97 }
85 98
99 // static
100 void HttpAlternateProtocols::ForceAlternateProtocol(
101 const PortProtocolPair& pair) {
102 // Note: we're going to leak this.
willchan no longer on Chromium 2010/08/22 16:27:33 Call delete forced_alternate_protocol_ here, in ca
103 forced_alternate_protocol_ = new PortProtocolPair(pair);
104 }
105
106 // static
107 void HttpAlternateProtocols::DisableForcedAlternateProtocol() {
108 delete forced_alternate_protocol_;
109 forced_alternate_protocol_ = NULL;
110 }
111
86 } // namespace net 112 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_alternate_protocols.h ('k') | net/http/http_alternate_protocols_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698