privet_http_asynchronous_factory.h revision 3551c9c881056c480085172ff9840cab31610854
1// Copyright 2013 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#ifndef CHROME_BROWSER_LOCAL_DISCOVERY_PRIVET_HTTP_ASYNCHRONOUS_FACTORY_H_ 6#define CHROME_BROWSER_LOCAL_DISCOVERY_PRIVET_HTTP_ASYNCHRONOUS_FACTORY_H_ 7 8#include <string> 9 10#include "chrome/browser/local_discovery/privet_http.h" 11#include "chrome/browser/local_discovery/privet_http_impl.h" 12#include "chrome/common/local_discovery/service_discovery_client.h" 13 14namespace local_discovery { 15 16class PrivetHTTPAsynchronousFactory { 17 public: 18 typedef base::Callback<void(scoped_ptr<PrivetHTTPClient>)> ResultCallback; 19 20 class Resolution { 21 public: 22 virtual ~Resolution() {} 23 virtual void Start() = 0; 24 }; 25 26 virtual ~PrivetHTTPAsynchronousFactory() {} 27 28 virtual scoped_ptr<Resolution> CreatePrivetHTTP( 29 const std::string& name, 30 const net::HostPortPair& address, 31 const ResultCallback& callback) = 0; 32}; 33 34class PrivetHTTPAsynchronousFactoryImpl : public PrivetHTTPAsynchronousFactory { 35 public: 36 PrivetHTTPAsynchronousFactoryImpl( 37 ServiceDiscoveryClient* service_discovery_client, 38 net::URLRequestContextGetter* request_context); 39 virtual ~PrivetHTTPAsynchronousFactoryImpl(); 40 41 virtual scoped_ptr<Resolution> CreatePrivetHTTP( 42 const std::string& name, 43 const net::HostPortPair& address, 44 const ResultCallback& callback) OVERRIDE; 45 46 private: 47 class ResolutionImpl : public Resolution { 48 public: 49 ResolutionImpl(const std::string& name, 50 const net::HostPortPair& address, 51 const ResultCallback& callback, 52 ServiceDiscoveryClient* service_discovery_client, 53 net::URLRequestContextGetter* request_context); 54 virtual ~ResolutionImpl(); 55 56 virtual void Start() OVERRIDE; 57 private: 58 void ResolveComplete(bool success, const net::IPAddressNumber& address); 59 60 std::string name_; 61 scoped_ptr<LocalDomainResolver> resolver_; 62 net::HostPortPair hostport_; 63 ResultCallback callback_; 64 scoped_refptr<net::URLRequestContextGetter> request_context_; 65 }; 66 67 ServiceDiscoveryClient* service_discovery_client_; 68 scoped_refptr<net::URLRequestContextGetter> request_context_; 69}; 70 71} // namespace local_discovery 72 73#endif // CHROME_BROWSER_LOCAL_DISCOVERY_PRIVET_HTTP_ASYNCHRONOUS_FACTORY_H_ 74