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

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

Issue 959503003: Remove ServiceDiscoveryClient* from PrivetHTTPAsynchronousFactoryImpl interface (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@fixEstablish
Patch Set: Tue Feb 24 23:11:53 PST 2015 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"
11 #include "chrome/browser/local_discovery/service_discovery_shared_client.h"
11 #include "chrome/common/chrome_switches.h" 12 #include "chrome/common/chrome_switches.h"
12 13
13 namespace local_discovery { 14 namespace local_discovery {
14 15
15 namespace { 16 namespace {
16 17
17 std::string IPAddressToHostString(const net::IPAddressNumber& address) { 18 std::string IPAddressToHostString(const net::IPAddressNumber& address) {
18 std::string address_str = net::IPAddressToString(address); 19 std::string address_str = net::IPAddressToString(address);
19 20
20 // IPv6 addresses need to be surrounded by brackets. 21 // IPv6 addresses need to be surrounded by brackets.
21 if (address.size() == net::kIPv6AddressSize) { 22 if (address.size() == net::kIPv6AddressSize) {
22 address_str = base::StringPrintf("[%s]", address_str.c_str()); 23 address_str = base::StringPrintf("[%s]", address_str.c_str());
23 } 24 }
24 25
25 return address_str; 26 return address_str;
26 } 27 }
27 28
28 } // namespace 29 } // namespace
29 30
30 PrivetHTTPAsynchronousFactoryImpl::PrivetHTTPAsynchronousFactoryImpl( 31 PrivetHTTPAsynchronousFactoryImpl::PrivetHTTPAsynchronousFactoryImpl(
31 ServiceDiscoveryClient* service_discovery_client,
32 net::URLRequestContextGetter* request_context) 32 net::URLRequestContextGetter* request_context)
33 : service_discovery_client_(service_discovery_client), 33 : request_context_(request_context) {
34 request_context_(request_context) {
35 } 34 }
36 35
37 PrivetHTTPAsynchronousFactoryImpl::~PrivetHTTPAsynchronousFactoryImpl() { 36 PrivetHTTPAsynchronousFactoryImpl::~PrivetHTTPAsynchronousFactoryImpl() {
38 } 37 }
39 38
40 scoped_ptr<PrivetHTTPResolution> 39 scoped_ptr<PrivetHTTPResolution>
41 PrivetHTTPAsynchronousFactoryImpl::CreatePrivetHTTP( 40 PrivetHTTPAsynchronousFactoryImpl::CreatePrivetHTTP(
42 const std::string& name, 41 const std::string& name,
43 const net::HostPortPair& address, 42 const net::HostPortPair& address,
44 const ResultCallback& callback) { 43 const ResultCallback& callback) {
45 return scoped_ptr<PrivetHTTPResolution>( 44 return scoped_ptr<PrivetHTTPResolution>(
46 new ResolutionImpl(name, 45 new ResolutionImpl(name, address, callback, request_context_.get()));
47 address,
48 callback,
49 service_discovery_client_,
50 request_context_.get()));
51 } 46 }
52 47
53 PrivetHTTPAsynchronousFactoryImpl::ResolutionImpl::ResolutionImpl( 48 PrivetHTTPAsynchronousFactoryImpl::ResolutionImpl::ResolutionImpl(
54 const std::string& name, 49 const std::string& name,
55 const net::HostPortPair& address, 50 const net::HostPortPair& address,
56 const ResultCallback& callback, 51 const ResultCallback& callback,
57 ServiceDiscoveryClient* service_discovery_client,
58 net::URLRequestContextGetter* request_context) 52 net::URLRequestContextGetter* request_context)
59 : name_(name), 53 : name_(name),
60 hostport_(address), 54 hostport_(address),
61 callback_(callback), 55 callback_(callback),
62 request_context_(request_context) { 56 request_context_(request_context) {
57 service_discovery_client_ = ServiceDiscoverySharedClient::GetInstance();
58
63 net::AddressFamily address_family = net::ADDRESS_FAMILY_UNSPECIFIED; 59 net::AddressFamily address_family = net::ADDRESS_FAMILY_UNSPECIFIED;
64
65 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 60 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
66 switches::kPrivetIPv6Only)) { 61 switches::kPrivetIPv6Only)) {
67 address_family = net::ADDRESS_FAMILY_IPV6; 62 address_family = net::ADDRESS_FAMILY_IPV6;
68 } 63 }
69 64
70 resolver_ = service_discovery_client->CreateLocalDomainResolver( 65 resolver_ = service_discovery_client_->CreateLocalDomainResolver(
71 address.host(), 66 address.host(), address_family,
72 address_family,
73 base::Bind(&ResolutionImpl::ResolveComplete, base::Unretained(this))); 67 base::Bind(&ResolutionImpl::ResolveComplete, base::Unretained(this)));
74 } 68 }
75 69
76 PrivetHTTPAsynchronousFactoryImpl::ResolutionImpl::~ResolutionImpl() { 70 PrivetHTTPAsynchronousFactoryImpl::ResolutionImpl::~ResolutionImpl() {
77 } 71 }
78 72
79 void PrivetHTTPAsynchronousFactoryImpl::ResolutionImpl::Start() { 73 void PrivetHTTPAsynchronousFactoryImpl::ResolutionImpl::Start() {
80 resolver_->Start(); 74 resolver_->Start();
81 } 75 }
82 76
(...skipping 17 matching lines...) Expand all
100 94
101 DCHECK(!address.empty()); 95 DCHECK(!address.empty());
102 96
103 net::HostPortPair new_address = 97 net::HostPortPair new_address =
104 net::HostPortPair(IPAddressToHostString(address), hostport_.port()); 98 net::HostPortPair(IPAddressToHostString(address), hostport_.port());
105 callback_.Run(scoped_ptr<PrivetHTTPClient>( 99 callback_.Run(scoped_ptr<PrivetHTTPClient>(
106 new PrivetHTTPClientImpl(name_, new_address, request_context_.get()))); 100 new PrivetHTTPClientImpl(name_, new_address, request_context_.get())));
107 } 101 }
108 102
109 } // namespace local_discovery 103 } // namespace local_discovery
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698