OLD | NEW |
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 | 14 |
14 namespace local_discovery { | 15 namespace local_discovery { |
15 | 16 |
16 namespace { | 17 namespace { |
17 | 18 |
18 std::string IPAddressToHostString(const net::IPAddressNumber& address) { | 19 std::string IPAddressToHostString(const net::IPAddressNumber& address) { |
19 std::string address_str = net::IPAddressToString(address); | 20 std::string address_str = net::IPAddressToString(address); |
20 | 21 |
21 // IPv6 addresses need to be surrounded by brackets. | 22 // IPv6 addresses need to be surrounded by brackets. |
22 if (address.size() == net::kIPv6AddressSize) { | 23 if (address.size() == net::kIPv6AddressSize) { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 | 56 |
56 const std::string& | 57 const std::string& |
57 PrivetHTTPAsynchronousFactoryImpl::ResolutionImpl::GetName() { | 58 PrivetHTTPAsynchronousFactoryImpl::ResolutionImpl::GetName() { |
58 return name_; | 59 return name_; |
59 } | 60 } |
60 | 61 |
61 void PrivetHTTPAsynchronousFactoryImpl::ResolutionImpl::Start( | 62 void PrivetHTTPAsynchronousFactoryImpl::ResolutionImpl::Start( |
62 const net::HostPortPair& address, | 63 const net::HostPortPair& address, |
63 const ResultCallback& callback) { | 64 const ResultCallback& callback) { |
64 #if defined(OS_MACOSX) | 65 #if defined(OS_MACOSX) |
| 66 net::IPAddressNumber ip_address; |
| 67 DCHECK(net::ParseIPLiteralToNumber(address.host(), &ip_address)); |
65 // MAC already has IP there. | 68 // MAC already has IP there. |
66 callback.Run(scoped_ptr<PrivetHTTPClient>( | 69 callback.Run(scoped_ptr<PrivetHTTPClient>( |
67 new PrivetHTTPClientImpl(name_, address, request_context_.get()))); | 70 new PrivetHTTPClientImpl(name_, address, request_context_.get()))); |
68 #else // OS_MACOSX | 71 #else // OS_MACOSX |
69 net::AddressFamily address_family = net::ADDRESS_FAMILY_UNSPECIFIED; | 72 net::AddressFamily address_family = net::ADDRESS_FAMILY_UNSPECIFIED; |
70 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 73 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
71 switches::kPrivetIPv6Only)) { | 74 switches::kPrivetIPv6Only)) { |
72 address_family = net::ADDRESS_FAMILY_IPV6; | 75 address_family = net::ADDRESS_FAMILY_IPV6; |
73 } | 76 } |
74 | 77 |
(...skipping 22 matching lines...) Expand all Loading... |
97 | 100 |
98 DCHECK(!address.empty()); | 101 DCHECK(!address.empty()); |
99 | 102 |
100 net::HostPortPair new_address = | 103 net::HostPortPair new_address = |
101 net::HostPortPair(IPAddressToHostString(address), port); | 104 net::HostPortPair(IPAddressToHostString(address), port); |
102 callback.Run(scoped_ptr<PrivetHTTPClient>( | 105 callback.Run(scoped_ptr<PrivetHTTPClient>( |
103 new PrivetHTTPClientImpl(name_, new_address, request_context_.get()))); | 106 new PrivetHTTPClientImpl(name_, new_address, request_context_.get()))); |
104 } | 107 } |
105 | 108 |
106 } // namespace local_discovery | 109 } // namespace local_discovery |
OLD | NEW |