Index: chrome/browser/local_discovery/privet_http_asynchronous_factory.cc |
diff --git a/chrome/browser/local_discovery/privet_http_asynchronous_factory.cc b/chrome/browser/local_discovery/privet_http_asynchronous_factory.cc |
index 8bcbe52e95da1ee67ccea6ba5d449cf8e30827a0..506ef3c815f90a00eb3a0c5e8269453c05c0ada5 100644 |
--- a/chrome/browser/local_discovery/privet_http_asynchronous_factory.cc |
+++ b/chrome/browser/local_discovery/privet_http_asynchronous_factory.cc |
@@ -4,152 +4,28 @@ |
#include "chrome/browser/local_discovery/privet_http_asynchronous_factory.h" |
-#include "base/bind.h" |
-#include "base/command_line.h" |
-#include "base/strings/stringprintf.h" |
-#include "chrome/browser/local_discovery/privet_http.h" |
-#include "chrome/browser/local_discovery/privet_http_impl.h" |
-#include "chrome/common/chrome_switches.h" |
-#include "chrome/common/local_discovery/service_discovery_client.h" |
+#if defined(OS_MACOSX) |
+#include "chrome/browser/local_discovery/privet_http_asynchronous_factory_mac.h" |
+#else |
+#include "chrome/browser/local_discovery/privet_http_asynchronous_factory_impl.h" |
+#endif |
namespace local_discovery { |
-namespace { |
- |
-std::string IPAddressToHostString(const net::IPAddressNumber& address) { |
- std::string address_str = net::IPAddressToString(address); |
- |
- // IPv6 addresses need to be surrounded by brackets. |
- if (address.size() == net::kIPv6AddressSize) { |
- address_str = base::StringPrintf("[%s]", address_str.c_str()); |
- } |
- |
- return address_str; |
-} |
- |
-} // namespace |
- |
-class PrivetHTTPAsynchronousFactoryImpl : public PrivetHTTPAsynchronousFactory { |
- public: |
- PrivetHTTPAsynchronousFactoryImpl( |
- ServiceDiscoveryClient* service_discovery_client, |
- net::URLRequestContextGetter* request_context); |
- virtual ~PrivetHTTPAsynchronousFactoryImpl(); |
- |
- virtual scoped_ptr<PrivetHTTPResolution> CreatePrivetHTTP( |
- const std::string& name, |
- const net::HostPortPair& address, |
- const ResultCallback& callback) OVERRIDE; |
- |
- private: |
- class ResolutionImpl : public PrivetHTTPResolution { |
- public: |
- ResolutionImpl(const std::string& name, |
- const net::HostPortPair& address, |
- const ResultCallback& callback, |
- ServiceDiscoveryClient* service_discovery_client, |
- net::URLRequestContextGetter* request_context); |
- virtual ~ResolutionImpl(); |
- |
- virtual void Start() OVERRIDE; |
- virtual const std::string& GetName() OVERRIDE; |
- private: |
- void ResolveComplete(bool success, |
- const net::IPAddressNumber& address_ipv4, |
- const net::IPAddressNumber& address_ipv6); |
- |
- std::string name_; |
- scoped_ptr<LocalDomainResolver> resolver_; |
- net::HostPortPair hostport_; |
- ResultCallback callback_; |
- scoped_refptr<net::URLRequestContextGetter> request_context_; |
- }; |
- |
- ServiceDiscoveryClient* service_discovery_client_; |
- scoped_refptr<net::URLRequestContextGetter> request_context_; |
-}; |
- |
-PrivetHTTPAsynchronousFactoryImpl::PrivetHTTPAsynchronousFactoryImpl( |
- ServiceDiscoveryClient* service_discovery_client, |
- net::URLRequestContextGetter* request_context) |
- : service_discovery_client_(service_discovery_client), |
- request_context_(request_context) { |
-} |
- |
-PrivetHTTPAsynchronousFactoryImpl::~PrivetHTTPAsynchronousFactoryImpl() { |
-} |
- |
// static |
scoped_ptr<PrivetHTTPAsynchronousFactory> |
PrivetHTTPAsynchronousFactory::CreateInstance( |
ServiceDiscoveryClient* service_discovery_client, |
net::URLRequestContextGetter* request_context) { |
+#if defined(OS_MACOSX) |
+ return make_scoped_ptr<PrivetHTTPAsynchronousFactory>( |
+ new PrivetHTTPAsynchronousFactoryMac(request_context)); |
+ |
+#else |
return make_scoped_ptr<PrivetHTTPAsynchronousFactory>( |
new PrivetHTTPAsynchronousFactoryImpl(service_discovery_client, |
request_context)); |
-} |
- |
-scoped_ptr<PrivetHTTPResolution> |
- PrivetHTTPAsynchronousFactoryImpl::CreatePrivetHTTP( |
- const std::string& name, |
- const net::HostPortPair& address, |
- const ResultCallback& callback) { |
- return scoped_ptr<PrivetHTTPResolution>( |
- new ResolutionImpl(name, address, callback, service_discovery_client_, |
- request_context_.get())); |
-} |
- |
-PrivetHTTPAsynchronousFactoryImpl::ResolutionImpl::ResolutionImpl( |
- const std::string& name, |
- const net::HostPortPair& address, |
- const ResultCallback& callback, |
- ServiceDiscoveryClient* service_discovery_client, |
- net::URLRequestContextGetter* request_context) |
- : name_(name), hostport_(address), callback_(callback), |
- request_context_(request_context) { |
- net::AddressFamily address_family = net::ADDRESS_FAMILY_UNSPECIFIED; |
- |
- if (CommandLine::ForCurrentProcess()->HasSwitch( |
- switches::kPrivetIPv6Only)) { |
- address_family = net::ADDRESS_FAMILY_IPV6; |
- } |
- |
- resolver_ = service_discovery_client->CreateLocalDomainResolver( |
- address.host(), address_family, |
- base::Bind(&ResolutionImpl::ResolveComplete, base::Unretained(this))); |
-} |
- |
-PrivetHTTPAsynchronousFactoryImpl::ResolutionImpl::~ResolutionImpl() { |
-} |
- |
-void PrivetHTTPAsynchronousFactoryImpl::ResolutionImpl::Start() { |
- resolver_->Start(); |
-} |
- |
-const std::string& |
-PrivetHTTPAsynchronousFactoryImpl::ResolutionImpl::GetName() { |
- return name_; |
-} |
- |
-void PrivetHTTPAsynchronousFactoryImpl::ResolutionImpl::ResolveComplete( |
- 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()); |
- |
- net::HostPortPair new_address = net::HostPortPair( |
- IPAddressToHostString(address), hostport_.port()); |
- callback_.Run(scoped_ptr<PrivetHTTPClient>( |
- new PrivetHTTPClientImpl(name_, new_address, request_context_.get()))); |
+#endif |
} |
} // namespace local_discovery |