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

Side by Side Diff: chrome/browser/local_discovery/privet_http_asynchronous_factory_impl.cc

Issue 1440063002: Use net::HostPortPair::HostForURL to fix IPv6 in URLs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@context4
Patch Set: Created 5 years, 1 month 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 | « no previous file | chrome/browser/local_discovery/privet_http_impl.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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "chrome/browser/local_discovery/privet_http_asynchronous_factory_impl.h " 5 #include "chrome/browser/local_discovery/privet_http_asynchronous_factory_impl.h "
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "chrome/browser/local_discovery/privet_http_impl.h" 10 #include "chrome/browser/local_discovery/privet_http_impl.h"
11 #include "chrome/browser/local_discovery/service_discovery_shared_client.h" 11 #include "chrome/browser/local_discovery/service_discovery_shared_client.h"
12 #include "chrome/common/chrome_switches.h" 12 #include "chrome/common/chrome_switches.h"
13 #include "net/base/net_util.h" 13 #include "net/base/net_util.h"
14 14
15 namespace local_discovery { 15 namespace local_discovery {
16 16
17 namespace {
18
19 std::string IPAddressToHostString(const net::IPAddressNumber& address) {
20 std::string address_str = net::IPAddressToString(address);
21
22 // IPv6 addresses need to be surrounded by brackets.
23 if (address.size() == net::kIPv6AddressSize) {
24 address_str = base::StringPrintf("[%s]", address_str.c_str());
25 }
26
27 return address_str;
28 }
29
30 } // namespace
31
32 PrivetHTTPAsynchronousFactoryImpl::PrivetHTTPAsynchronousFactoryImpl( 17 PrivetHTTPAsynchronousFactoryImpl::PrivetHTTPAsynchronousFactoryImpl(
33 net::URLRequestContextGetter* request_context) 18 net::URLRequestContextGetter* request_context)
34 : request_context_(request_context) { 19 : request_context_(request_context) {
35 } 20 }
36 21
37 PrivetHTTPAsynchronousFactoryImpl::~PrivetHTTPAsynchronousFactoryImpl() { 22 PrivetHTTPAsynchronousFactoryImpl::~PrivetHTTPAsynchronousFactoryImpl() {
38 } 23 }
39 24
40 scoped_ptr<PrivetHTTPResolution> 25 scoped_ptr<PrivetHTTPResolution>
41 PrivetHTTPAsynchronousFactoryImpl::CreatePrivetHTTP( 26 PrivetHTTPAsynchronousFactoryImpl::CreatePrivetHTTP(
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 return; 97 return;
113 } 98 }
114 99
115 net::IPAddressNumber address = address_ipv4; 100 net::IPAddressNumber address = address_ipv4;
116 if (address.empty()) 101 if (address.empty())
117 address = address_ipv6; 102 address = address_ipv6;
118 103
119 DCHECK(!address.empty()); 104 DCHECK(!address.empty());
120 105
121 net::HostPortPair new_address = 106 net::HostPortPair new_address =
122 net::HostPortPair(IPAddressToHostString(address), port); 107 net::HostPortPair::FromIPEndPoint(net::IPEndPoint(address, port));
123 callback.Run(scoped_ptr<PrivetHTTPClient>( 108 callback.Run(scoped_ptr<PrivetHTTPClient>(
124 new PrivetHTTPClientImpl(name_, new_address, request_context_.get()))); 109 new PrivetHTTPClientImpl(name_, new_address, request_context_.get())));
125 } 110 }
126 111
127 } // namespace local_discovery 112 } // namespace local_discovery
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/local_discovery/privet_http_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698