| Index: chrome/browser/local_discovery/privet_http_asynchronous_factory_impl.cc
|
| diff --git a/chrome/browser/local_discovery/privet_http_asynchronous_factory_impl.cc b/chrome/browser/local_discovery/privet_http_asynchronous_factory_impl.cc
|
| index a5267d719c7851b8b1d61cfecca93eedd99c7db2..684b60676b5ad123dadd5ea2e34861eea5a3fdad 100644
|
| --- a/chrome/browser/local_discovery/privet_http_asynchronous_factory_impl.cc
|
| +++ b/chrome/browser/local_discovery/privet_http_asynchronous_factory_impl.cc
|
| @@ -4,14 +4,8 @@
|
|
|
| #include "chrome/browser/local_discovery/privet_http_asynchronous_factory_impl.h"
|
|
|
| -#include "base/bind.h"
|
| -#include "base/command_line.h"
|
| -#include "base/debug/dump_without_crashing.h"
|
| -#include "base/strings/stringprintf.h"
|
| +#include "chrome/browser/local_discovery/endpoint_resolver.h"
|
| #include "chrome/browser/local_discovery/privet_http_impl.h"
|
| -#include "chrome/browser/local_discovery/service_discovery_shared_client.h"
|
| -#include "chrome/common/chrome_switches.h"
|
| -#include "net/base/net_util.h"
|
|
|
| namespace local_discovery {
|
|
|
| @@ -33,9 +27,9 @@ PrivetHTTPAsynchronousFactoryImpl::CreatePrivetHTTP(
|
| PrivetHTTPAsynchronousFactoryImpl::ResolutionImpl::ResolutionImpl(
|
| const std::string& service_name,
|
| net::URLRequestContextGetter* request_context)
|
| - : name_(service_name), request_context_(request_context) {
|
| - service_discovery_client_ = ServiceDiscoverySharedClient::GetInstance();
|
| -}
|
| + : name_(service_name),
|
| + request_context_(request_context),
|
| + endpoint_resolver_(new EndpointResolver()) {}
|
|
|
| PrivetHTTPAsynchronousFactoryImpl::ResolutionImpl::~ResolutionImpl() {
|
| }
|
| @@ -47,73 +41,26 @@ PrivetHTTPAsynchronousFactoryImpl::ResolutionImpl::GetName() {
|
|
|
| void PrivetHTTPAsynchronousFactoryImpl::ResolutionImpl::Start(
|
| const ResultCallback& callback) {
|
| - service_resolver_ = service_discovery_client_->CreateServiceResolver(
|
| - name_, base::Bind(&ResolutionImpl::ServiceResolveComplete,
|
| - base::Unretained(this), callback));
|
| - service_resolver_->StartResolving();
|
| -}
|
| -
|
| -void PrivetHTTPAsynchronousFactoryImpl::ResolutionImpl::ServiceResolveComplete(
|
| - const ResultCallback& callback,
|
| - ServiceResolver::RequestStatus result,
|
| - const ServiceDescription& description) {
|
| - if (result != ServiceResolver::STATUS_SUCCESS)
|
| - return callback.Run(scoped_ptr<PrivetHTTPClient>());
|
| -
|
| - Start(description.address, callback);
|
| + endpoint_resolver_->Start(name_,
|
| + base::Bind(&ResolutionImpl::ResolveComplete,
|
| + base::Unretained(this), callback));
|
| }
|
|
|
| void PrivetHTTPAsynchronousFactoryImpl::ResolutionImpl::Start(
|
| const net::HostPortPair& address,
|
| const ResultCallback& callback) {
|
| -#if defined(OS_MACOSX)
|
| - net::IPAddressNumber ip_address;
|
| - if (!net::ParseIPLiteralToNumber(address.host(), &ip_address)) {
|
| - NOTREACHED() << address.ToString();
|
| - // Unexpected, but could be a reason for crbug.com/513505
|
| - base::debug::DumpWithoutCrashing();
|
| - return callback.Run(scoped_ptr<PrivetHTTPClient>());
|
| - }
|
| -
|
| - // OSX already has IP there.
|
| - callback.Run(scoped_ptr<PrivetHTTPClient>(new PrivetHTTPClientImpl(
|
| - name_, net::HostPortPair::FromIPEndPoint(
|
| - net::IPEndPoint(ip_address, address.port())),
|
| - request_context_.get())));
|
| -#else // OS_MACOSX
|
| - net::AddressFamily address_family = net::ADDRESS_FAMILY_UNSPECIFIED;
|
| - if (base::CommandLine::ForCurrentProcess()->HasSwitch(
|
| - switches::kPrivetIPv6Only)) {
|
| - address_family = net::ADDRESS_FAMILY_IPV6;
|
| - }
|
| -
|
| - domain_resolver_ = service_discovery_client_->CreateLocalDomainResolver(
|
| - address.host(), address_family,
|
| - base::Bind(&ResolutionImpl::DomainResolveComplete, base::Unretained(this),
|
| - address.port(), callback));
|
| - domain_resolver_->Start();
|
| -#endif // OS_MACOSX
|
| + endpoint_resolver_->Start(address,
|
| + base::Bind(&ResolutionImpl::ResolveComplete,
|
| + base::Unretained(this), callback));
|
| }
|
|
|
| -void PrivetHTTPAsynchronousFactoryImpl::ResolutionImpl::DomainResolveComplete(
|
| - uint16 port,
|
| +void PrivetHTTPAsynchronousFactoryImpl::ResolutionImpl::ResolveComplete(
|
| const ResultCallback& callback,
|
| - bool success,
|
| - const net::IPAddressNumber& address_ipv4,
|
| - const net::IPAddressNumber& address_ipv6) {
|
| - if (!success) {
|
| - callback.Run(scoped_ptr<PrivetHTTPClient>());
|
| - return;
|
| - }
|
| -
|
| - net::IPAddressNumber address = address_ipv4;
|
| - if (address.empty())
|
| - address = address_ipv6;
|
| -
|
| - DCHECK(!address.empty());
|
| + const net::IPEndPoint& endpoint) {
|
| + if (endpoint.address().empty())
|
| + return callback.Run(scoped_ptr<PrivetHTTPClient>());
|
|
|
| - net::HostPortPair new_address =
|
| - net::HostPortPair::FromIPEndPoint(net::IPEndPoint(address, port));
|
| + net::HostPortPair new_address = net::HostPortPair::FromIPEndPoint(endpoint);
|
| callback.Run(scoped_ptr<PrivetHTTPClient>(
|
| new PrivetHTTPClientImpl(name_, new_address, request_context_.get())));
|
| }
|
|
|