OLD | NEW |
| (Empty) |
1 // Copyright 2014 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 #include "chrome/browser/local_discovery/privet_http_asynchronous_factory_impl.h
" | |
6 | |
7 #include "chrome/browser/local_discovery/endpoint_resolver.h" | |
8 #include "chrome/browser/local_discovery/privet_http_impl.h" | |
9 | |
10 namespace local_discovery { | |
11 | |
12 PrivetHTTPAsynchronousFactoryImpl::PrivetHTTPAsynchronousFactoryImpl( | |
13 net::URLRequestContextGetter* request_context) | |
14 : request_context_(request_context) { | |
15 } | |
16 | |
17 PrivetHTTPAsynchronousFactoryImpl::~PrivetHTTPAsynchronousFactoryImpl() { | |
18 } | |
19 | |
20 scoped_ptr<PrivetHTTPResolution> | |
21 PrivetHTTPAsynchronousFactoryImpl::CreatePrivetHTTP( | |
22 const std::string& service_name) { | |
23 return scoped_ptr<PrivetHTTPResolution>( | |
24 new ResolutionImpl(service_name, request_context_.get())); | |
25 } | |
26 | |
27 PrivetHTTPAsynchronousFactoryImpl::ResolutionImpl::ResolutionImpl( | |
28 const std::string& service_name, | |
29 net::URLRequestContextGetter* request_context) | |
30 : name_(service_name), | |
31 request_context_(request_context), | |
32 endpoint_resolver_(new EndpointResolver()) {} | |
33 | |
34 PrivetHTTPAsynchronousFactoryImpl::ResolutionImpl::~ResolutionImpl() { | |
35 } | |
36 | |
37 const std::string& | |
38 PrivetHTTPAsynchronousFactoryImpl::ResolutionImpl::GetName() { | |
39 return name_; | |
40 } | |
41 | |
42 void PrivetHTTPAsynchronousFactoryImpl::ResolutionImpl::Start( | |
43 const ResultCallback& callback) { | |
44 endpoint_resolver_->Start(name_, | |
45 base::Bind(&ResolutionImpl::ResolveComplete, | |
46 base::Unretained(this), callback)); | |
47 } | |
48 | |
49 void PrivetHTTPAsynchronousFactoryImpl::ResolutionImpl::Start( | |
50 const net::HostPortPair& address, | |
51 const ResultCallback& callback) { | |
52 endpoint_resolver_->Start(address, | |
53 base::Bind(&ResolutionImpl::ResolveComplete, | |
54 base::Unretained(this), callback)); | |
55 } | |
56 | |
57 void PrivetHTTPAsynchronousFactoryImpl::ResolutionImpl::ResolveComplete( | |
58 const ResultCallback& callback, | |
59 const net::IPEndPoint& endpoint) { | |
60 if (endpoint.address().empty()) | |
61 return callback.Run(scoped_ptr<PrivetHTTPClient>()); | |
62 | |
63 net::HostPortPair new_address = net::HostPortPair::FromIPEndPoint(endpoint); | |
64 callback.Run(scoped_ptr<PrivetHTTPClient>( | |
65 new PrivetHTTPClientImpl(name_, new_address, request_context_.get()))); | |
66 } | |
67 | |
68 } // namespace local_discovery | |
OLD | NEW |