Commit 47f1b8cd authored by vitalybuka's avatar vitalybuka Committed by Commit bot

Added PrivetHTTPResolution::Start for service name only

Host:port can be resolved from service name.
Still old method is useful when client already know them.

BUG=461504

Review URL: https://codereview.chromium.org/948283005

Cr-Commit-Position: refs/heads/master@{#318157}
parent 44452c40
......@@ -25,6 +25,8 @@ class PrivetHTTPResolution {
virtual ~PrivetHTTPResolution() {}
virtual void Start(const ResultCallback& callback) = 0;
virtual void Start(const net::HostPortPair& address,
const ResultCallback& callback) = 0;
......
......@@ -58,6 +58,24 @@ PrivetHTTPAsynchronousFactoryImpl::ResolutionImpl::GetName() {
return name_;
}
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);
}
void PrivetHTTPAsynchronousFactoryImpl::ResolutionImpl::Start(
const net::HostPortPair& address,
const ResultCallback& callback) {
......
......@@ -29,12 +29,18 @@ class PrivetHTTPAsynchronousFactoryImpl : public PrivetHTTPAsynchronousFactory {
net::URLRequestContextGetter* request_context);
~ResolutionImpl() override;
void Start(const ResultCallback& callback) override;
void Start(const net::HostPortPair& address,
const ResultCallback& callback) override;
const std::string& GetName() override;
private:
void ServiceResolveComplete(const ResultCallback& callback,
ServiceResolver::RequestStatus result,
const ServiceDescription& description);
void DomainResolveComplete(uint16 port,
const ResultCallback& callback,
bool success,
......@@ -44,6 +50,7 @@ class PrivetHTTPAsynchronousFactoryImpl : public PrivetHTTPAsynchronousFactory {
std::string name_;
scoped_refptr<net::URLRequestContextGetter> request_context_;
scoped_refptr<ServiceDiscoverySharedClient> service_discovery_client_;
scoped_ptr<ServiceResolver> service_resolver_;
scoped_ptr<LocalDomainResolver> domain_resolver_;
};
......
......@@ -53,6 +53,10 @@ class MockPrivetHttpFactory : public PrivetHTTPAsynchronousFactory {
name_, net::HostPortPair("1.2.3.4", 8080), request_context_.get())));
}
void Start(const ResultCallback& callback) override {
Start(net::HostPortPair(), callback);
}
const std::string& GetName() override { return name_; }
private:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment