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

Side by Side Diff: net/base/host_port_pair.cc

Issue 6488010: Propagate the remote socket address to URLRequest and to ViewHostMsg_FrameNavigate. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address eroman's comments Created 9 years, 10 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) 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/base/host_port_pair.h" 5 #include "net/base/host_port_pair.h"
6 6
7 #include "base/string_util.h" 7 #include "base/string_util.h"
8 #include "base/stringprintf.h" 8 #include "base/stringprintf.h"
9 #include "googleurl/src/gurl.h" 9 #include "googleurl/src/gurl.h"
10 #include "net/base/net_util.h"
11 #include "net/base/sys_addrinfo.h"
10 12
11 namespace net { 13 namespace net {
12 14
13 HostPortPair::HostPortPair() : port_(0) {} 15 HostPortPair::HostPortPair() : port_(0) {}
14 HostPortPair::HostPortPair(const std::string& in_host, uint16 in_port) 16 HostPortPair::HostPortPair(const std::string& in_host, uint16 in_port)
15 : host_(in_host), port_(in_port) {} 17 : host_(in_host), port_(in_port) {}
16 18
17 // static 19 // static
18 HostPortPair HostPortPair::FromURL(const GURL& url) { 20 HostPortPair HostPortPair::FromURL(const GURL& url) {
19 return HostPortPair(url.HostNoBrackets(), url.EffectiveIntPort()); 21 return HostPortPair(url.HostNoBrackets(), url.EffectiveIntPort());
20 } 22 }
21 23
24 // static
25 HostPortPair HostPortPair::FromAddrInfo(const struct addrinfo* ai) {
26 return HostPortPair(NetAddressToString(ai),
27 GetPortFromSockaddr(ai->ai_addr, ai->ai_addrlen));
28 }
29
22 std::string HostPortPair::ToString() const { 30 std::string HostPortPair::ToString() const {
23 return base::StringPrintf("%s:%u", HostForURL().c_str(), port_); 31 return base::StringPrintf("%s:%u", HostForURL().c_str(), port_);
24 } 32 }
25 33
26 std::string HostPortPair::HostForURL() const { 34 std::string HostPortPair::HostForURL() const {
27 // Check to see if the host is an IPv6 address. If so, added brackets. 35 // Check to see if the host is an IPv6 address. If so, added brackets.
28 if (host_.find(':') != std::string::npos) { 36 if (host_.find(':') != std::string::npos) {
29 DCHECK_NE(host_[0], '['); 37 DCHECK_NE(host_[0], '[');
30 return base::StringPrintf("[%s]", host_.c_str()); 38 return base::StringPrintf("[%s]", host_.c_str());
31 } 39 }
32 40
33 return host_; 41 return host_;
34 } 42 }
35 43
36 } // namespace net 44 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698