Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(538)

Side by Side Diff: chrome/browser/local_discovery/privet_http_asynchronous_factory_impl.cc

Issue 948413006: Move callback and host port args into Start method (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@no_sdc
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/local_discovery/privet_http_asynchronous_factory_impl.h " 5 #include "chrome/browser/local_discovery/privet_http_asynchronous_factory_impl.h "
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "chrome/browser/local_discovery/privet_http_impl.h" 10 #include "chrome/browser/local_discovery/privet_http_impl.h"
(...skipping 20 matching lines...) Expand all
31 PrivetHTTPAsynchronousFactoryImpl::PrivetHTTPAsynchronousFactoryImpl( 31 PrivetHTTPAsynchronousFactoryImpl::PrivetHTTPAsynchronousFactoryImpl(
32 net::URLRequestContextGetter* request_context) 32 net::URLRequestContextGetter* request_context)
33 : request_context_(request_context) { 33 : request_context_(request_context) {
34 } 34 }
35 35
36 PrivetHTTPAsynchronousFactoryImpl::~PrivetHTTPAsynchronousFactoryImpl() { 36 PrivetHTTPAsynchronousFactoryImpl::~PrivetHTTPAsynchronousFactoryImpl() {
37 } 37 }
38 38
39 scoped_ptr<PrivetHTTPResolution> 39 scoped_ptr<PrivetHTTPResolution>
40 PrivetHTTPAsynchronousFactoryImpl::CreatePrivetHTTP( 40 PrivetHTTPAsynchronousFactoryImpl::CreatePrivetHTTP(
41 const std::string& name, 41 const std::string& service_name) {
42 const net::HostPortPair& address,
43 const ResultCallback& callback) {
44 return scoped_ptr<PrivetHTTPResolution>( 42 return scoped_ptr<PrivetHTTPResolution>(
45 new ResolutionImpl(name, address, callback, request_context_.get())); 43 new ResolutionImpl(service_name, request_context_.get()));
46 } 44 }
47 45
48 PrivetHTTPAsynchronousFactoryImpl::ResolutionImpl::ResolutionImpl( 46 PrivetHTTPAsynchronousFactoryImpl::ResolutionImpl::ResolutionImpl(
49 const std::string& name, 47 const std::string& service_name,
50 const net::HostPortPair& address,
51 const ResultCallback& callback,
52 net::URLRequestContextGetter* request_context) 48 net::URLRequestContextGetter* request_context)
53 : name_(name), 49 : name_(service_name), request_context_(request_context) {
54 hostport_(address),
55 callback_(callback),
56 request_context_(request_context) {
57 service_discovery_client_ = ServiceDiscoverySharedClient::GetInstance(); 50 service_discovery_client_ = ServiceDiscoverySharedClient::GetInstance();
58
59 net::AddressFamily address_family = net::ADDRESS_FAMILY_UNSPECIFIED;
60 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
61 switches::kPrivetIPv6Only)) {
62 address_family = net::ADDRESS_FAMILY_IPV6;
63 }
64
65 resolver_ = service_discovery_client_->CreateLocalDomainResolver(
66 address.host(), address_family,
67 base::Bind(&ResolutionImpl::ResolveComplete, base::Unretained(this)));
68 } 51 }
69 52
70 PrivetHTTPAsynchronousFactoryImpl::ResolutionImpl::~ResolutionImpl() { 53 PrivetHTTPAsynchronousFactoryImpl::ResolutionImpl::~ResolutionImpl() {
71 } 54 }
72 55
73 void PrivetHTTPAsynchronousFactoryImpl::ResolutionImpl::Start() {
74 #if defined(OS_MACOSX)
75 // MAC already has IP there.
76 callback_.Run(scoped_ptr<PrivetHTTPClient>(
77 new PrivetHTTPClientImpl(name_, hostport_, request_context_.get())));
78 #else
79 resolver_->Start();
80 #endif
81 }
82
83 const std::string& 56 const std::string&
84 PrivetHTTPAsynchronousFactoryImpl::ResolutionImpl::GetName() { 57 PrivetHTTPAsynchronousFactoryImpl::ResolutionImpl::GetName() {
85 return name_; 58 return name_;
86 } 59 }
87 60
88 void PrivetHTTPAsynchronousFactoryImpl::ResolutionImpl::ResolveComplete( 61 void PrivetHTTPAsynchronousFactoryImpl::ResolutionImpl::Start(
62 const net::HostPortPair& address,
63 const ResultCallback& callback) {
64 #if defined(OS_MACOSX)
65 // MAC already has IP there.
66 callback.Run(scoped_ptr<PrivetHTTPClient>(
67 new PrivetHTTPClientImpl(name_, address, request_context_.get())));
68 #else // OS_MACOSX
69 net::AddressFamily address_family = net::ADDRESS_FAMILY_UNSPECIFIED;
70 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
71 switches::kPrivetIPv6Only)) {
72 address_family = net::ADDRESS_FAMILY_IPV6;
73 }
74
75 domain_resolver_ = service_discovery_client_->CreateLocalDomainResolver(
76 address.host(), address_family,
77 base::Bind(&ResolutionImpl::DomainResolveComplete, base::Unretained(this),
78 address.port(), callback));
79 domain_resolver_->Start();
80 #endif // OS_MACOSX
81 }
82
83 void PrivetHTTPAsynchronousFactoryImpl::ResolutionImpl::DomainResolveComplete(
84 uint16 port,
85 const ResultCallback& callback,
89 bool success, 86 bool success,
90 const net::IPAddressNumber& address_ipv4, 87 const net::IPAddressNumber& address_ipv4,
91 const net::IPAddressNumber& address_ipv6) { 88 const net::IPAddressNumber& address_ipv6) {
92 if (!success) { 89 if (!success) {
93 callback_.Run(scoped_ptr<PrivetHTTPClient>()); 90 callback.Run(scoped_ptr<PrivetHTTPClient>());
94 return; 91 return;
95 } 92 }
96 93
97 net::IPAddressNumber address = address_ipv4; 94 net::IPAddressNumber address = address_ipv4;
98 if (address.empty()) 95 if (address.empty())
99 address = address_ipv6; 96 address = address_ipv6;
100 97
101 DCHECK(!address.empty()); 98 DCHECK(!address.empty());
102 99
103 net::HostPortPair new_address = 100 net::HostPortPair new_address =
104 net::HostPortPair(IPAddressToHostString(address), hostport_.port()); 101 net::HostPortPair(IPAddressToHostString(address), port);
105 callback_.Run(scoped_ptr<PrivetHTTPClient>( 102 callback.Run(scoped_ptr<PrivetHTTPClient>(
106 new PrivetHTTPClientImpl(name_, new_address, request_context_.get()))); 103 new PrivetHTTPClientImpl(name_, new_address, request_context_.get())));
107 } 104 }
108 105
109 } // namespace local_discovery 106 } // namespace local_discovery
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698