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/debug/dump_without_crashing.h" |
9 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
10 #include "chrome/browser/local_discovery/privet_http_impl.h" | 11 #include "chrome/browser/local_discovery/privet_http_impl.h" |
11 #include "chrome/browser/local_discovery/service_discovery_shared_client.h" | 12 #include "chrome/browser/local_discovery/service_discovery_shared_client.h" |
12 #include "chrome/common/chrome_switches.h" | 13 #include "chrome/common/chrome_switches.h" |
13 #include "net/base/net_util.h" | 14 #include "net/base/net_util.h" |
14 | 15 |
15 namespace local_discovery { | 16 namespace local_discovery { |
16 | 17 |
17 namespace { | 18 namespace { |
18 | 19 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 return callback.Run(scoped_ptr<PrivetHTTPClient>()); | 76 return callback.Run(scoped_ptr<PrivetHTTPClient>()); |
76 | 77 |
77 Start(description.address, callback); | 78 Start(description.address, callback); |
78 } | 79 } |
79 | 80 |
80 void PrivetHTTPAsynchronousFactoryImpl::ResolutionImpl::Start( | 81 void PrivetHTTPAsynchronousFactoryImpl::ResolutionImpl::Start( |
81 const net::HostPortPair& address, | 82 const net::HostPortPair& address, |
82 const ResultCallback& callback) { | 83 const ResultCallback& callback) { |
83 #if defined(OS_MACOSX) | 84 #if defined(OS_MACOSX) |
84 net::IPAddressNumber ip_address; | 85 net::IPAddressNumber ip_address; |
85 DCHECK(net::ParseIPLiteralToNumber(address.host(), &ip_address)); | 86 if (!net::ParseIPLiteralToNumber(address.host(), &ip_address)) { |
86 // MAC already has IP there. | 87 NOTREACHED() << address.ToString(); |
87 callback.Run(scoped_ptr<PrivetHTTPClient>( | 88 // Unexpected, but could be a reason for crbug.com/513505 |
88 new PrivetHTTPClientImpl(name_, address, request_context_.get()))); | 89 base::debug::DumpWithoutCrashing(); |
| 90 return callback.Run(scoped_ptr<PrivetHTTPClient>()); |
| 91 } |
| 92 |
| 93 // OSX already has IP there. |
| 94 callback.Run(scoped_ptr<PrivetHTTPClient>(new PrivetHTTPClientImpl( |
| 95 name_, net::HostPortPair::FromIPEndPoint( |
| 96 net::IPEndPoint(ip_address, address.port())), |
| 97 request_context_.get()))); |
89 #else // OS_MACOSX | 98 #else // OS_MACOSX |
90 net::AddressFamily address_family = net::ADDRESS_FAMILY_UNSPECIFIED; | 99 net::AddressFamily address_family = net::ADDRESS_FAMILY_UNSPECIFIED; |
91 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 100 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
92 switches::kPrivetIPv6Only)) { | 101 switches::kPrivetIPv6Only)) { |
93 address_family = net::ADDRESS_FAMILY_IPV6; | 102 address_family = net::ADDRESS_FAMILY_IPV6; |
94 } | 103 } |
95 | 104 |
96 domain_resolver_ = service_discovery_client_->CreateLocalDomainResolver( | 105 domain_resolver_ = service_discovery_client_->CreateLocalDomainResolver( |
97 address.host(), address_family, | 106 address.host(), address_family, |
98 base::Bind(&ResolutionImpl::DomainResolveComplete, base::Unretained(this), | 107 base::Bind(&ResolutionImpl::DomainResolveComplete, base::Unretained(this), |
(...skipping 19 matching lines...) Expand all Loading... |
118 | 127 |
119 DCHECK(!address.empty()); | 128 DCHECK(!address.empty()); |
120 | 129 |
121 net::HostPortPair new_address = | 130 net::HostPortPair new_address = |
122 net::HostPortPair(IPAddressToHostString(address), port); | 131 net::HostPortPair(IPAddressToHostString(address), port); |
123 callback.Run(scoped_ptr<PrivetHTTPClient>( | 132 callback.Run(scoped_ptr<PrivetHTTPClient>( |
124 new PrivetHTTPClientImpl(name_, new_address, request_context_.get()))); | 133 new PrivetHTTPClientImpl(name_, new_address, request_context_.get()))); |
125 } | 134 } |
126 | 135 |
127 } // namespace local_discovery | 136 } // namespace local_discovery |
OLD | NEW |