privet_http_asynchronous_factory.h revision 424c4d7b64af9d0d8fd9624f381f469654d5e3d2
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,
59                         const net::IPAddressNumber& address_ipv4,
60                         const net::IPAddressNumber& address_ipv6);
61
62    std::string name_;
63    scoped_ptr<LocalDomainResolver> resolver_;
64    net::HostPortPair hostport_;
65    ResultCallback callback_;
66    scoped_refptr<net::URLRequestContextGetter> request_context_;
67  };
68
69  ServiceDiscoveryClient* service_discovery_client_;
70  scoped_refptr<net::URLRequestContextGetter> request_context_;
71};
72
73}  // namespace local_discovery
74
75#endif  // CHROME_BROWSER_LOCAL_DISCOVERY_PRIVET_HTTP_ASYNCHRONOUS_FACTORY_H_
76