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

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

Issue 23475049: Replace includes with forward declarations. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 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.h"
6
5 #include "base/bind.h" 7 #include "base/bind.h"
6 #include "base/command_line.h" 8 #include "base/command_line.h"
7 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
8 #include "chrome/browser/local_discovery/privet_http_asynchronous_factory.h" 10 #include "chrome/browser/local_discovery/privet_http.h"
9 #include "chrome/browser/local_discovery/privet_http_impl.h" 11 #include "chrome/browser/local_discovery/privet_http_impl.h"
10 #include "chrome/common/chrome_switches.h" 12 #include "chrome/common/chrome_switches.h"
13 #include "chrome/common/local_discovery/service_discovery_client.h"
11 14
12 namespace local_discovery { 15 namespace local_discovery {
13 16
14 namespace { 17 namespace {
15 18
16 std::string IPAddressToHostString(const net::IPAddressNumber& address) { 19 std::string IPAddressToHostString(const net::IPAddressNumber& address) {
17 std::string address_str = net::IPAddressToString(address); 20 std::string address_str = net::IPAddressToString(address);
18 21
19 // IPv6 addresses need to be surrounded by brackets. 22 // IPv6 addresses need to be surrounded by brackets.
20 if (address.size() == net::kIPv6AddressSize) { 23 if (address.size() == net::kIPv6AddressSize) {
21 address_str = base::StringPrintf("[%s]", address_str.c_str()); 24 address_str = base::StringPrintf("[%s]", address_str.c_str());
22 } 25 }
23 26
24 return address_str; 27 return address_str;
25 } 28 }
26 29
27 } // namespace 30 } // namespace
28 31
32 class PrivetHTTPAsynchronousFactoryImpl : public PrivetHTTPAsynchronousFactory {
33 public:
34 PrivetHTTPAsynchronousFactoryImpl(
35 ServiceDiscoveryClient* service_discovery_client,
36 net::URLRequestContextGetter* request_context);
37 virtual ~PrivetHTTPAsynchronousFactoryImpl();
38
39 virtual scoped_ptr<PrivetHTTPResolution> CreatePrivetHTTP(
40 const std::string& name,
41 const net::HostPortPair& address,
42 const ResultCallback& callback) OVERRIDE;
43
44 private:
45 class ResolutionImpl : public PrivetHTTPResolution {
46 public:
47 ResolutionImpl(const std::string& name,
48 const net::HostPortPair& address,
49 const ResultCallback& callback,
50 ServiceDiscoveryClient* service_discovery_client,
51 net::URLRequestContextGetter* request_context);
52 virtual ~ResolutionImpl();
53
54 virtual void Start() OVERRIDE;
55 private:
56 void ResolveComplete(bool success,
57 const net::IPAddressNumber& address_ipv4,
58 const net::IPAddressNumber& address_ipv6);
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
29 PrivetHTTPAsynchronousFactoryImpl::PrivetHTTPAsynchronousFactoryImpl( 71 PrivetHTTPAsynchronousFactoryImpl::PrivetHTTPAsynchronousFactoryImpl(
30 ServiceDiscoveryClient* service_discovery_client, 72 ServiceDiscoveryClient* service_discovery_client,
31 net::URLRequestContextGetter* request_context) 73 net::URLRequestContextGetter* request_context)
32 : service_discovery_client_(service_discovery_client), 74 : service_discovery_client_(service_discovery_client),
33 request_context_(request_context) { 75 request_context_(request_context) {
34 } 76 }
35 77
36 PrivetHTTPAsynchronousFactoryImpl::~PrivetHTTPAsynchronousFactoryImpl() { 78 PrivetHTTPAsynchronousFactoryImpl::~PrivetHTTPAsynchronousFactoryImpl() {
37 } 79 }
38 80
39 scoped_ptr<PrivetHTTPAsynchronousFactory::Resolution> 81 // static
40 PrivetHTTPAsynchronousFactoryImpl::CreatePrivetHTTP( 82 scoped_ptr<PrivetHTTPAsynchronousFactory>
41 const std::string& name, 83 PrivetHTTPAsynchronousFactory::CreateInstance(
42 const net::HostPortPair& address, 84 ServiceDiscoveryClient* service_discovery_client,
43 const ResultCallback& callback) { 85 net::URLRequestContextGetter* request_context) {
44 return scoped_ptr<Resolution>(new ResolutionImpl(name, address, callback, 86 return make_scoped_ptr<PrivetHTTPAsynchronousFactory>(
Noam Samuel 2013/09/16 17:40:07 What's the difference between make_scoped_ptr and
Vitaly Buka (NO REVIEWS) 2013/09/16 17:43:27 No. I just wrote this way.
45 service_discovery_client_, 87 new PrivetHTTPAsynchronousFactoryImpl(service_discovery_client,
46 request_context_.get())); 88 request_context));
89 }
90
91 scoped_ptr<PrivetHTTPResolution>
92 PrivetHTTPAsynchronousFactoryImpl::CreatePrivetHTTP(
93 const std::string& name,
94 const net::HostPortPair& address,
95 const ResultCallback& callback) {
96 return scoped_ptr<PrivetHTTPResolution>(
97 new ResolutionImpl(name, address, callback, service_discovery_client_,
98 request_context_.get()));
47 } 99 }
48 100
49 PrivetHTTPAsynchronousFactoryImpl::ResolutionImpl::ResolutionImpl( 101 PrivetHTTPAsynchronousFactoryImpl::ResolutionImpl::ResolutionImpl(
50 const std::string& name, 102 const std::string& name,
51 const net::HostPortPair& address, 103 const net::HostPortPair& address,
52 const ResultCallback& callback, 104 const ResultCallback& callback,
53 ServiceDiscoveryClient* service_discovery_client, 105 ServiceDiscoveryClient* service_discovery_client,
54 net::URLRequestContextGetter* request_context) 106 net::URLRequestContextGetter* request_context)
55 : name_(name), hostport_(address), callback_(callback), 107 : name_(name), hostport_(address), callback_(callback),
56 request_context_(request_context) { 108 request_context_(request_context) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 140
89 DCHECK(!address.empty()); 141 DCHECK(!address.empty());
90 142
91 net::HostPortPair new_address = net::HostPortPair( 143 net::HostPortPair new_address = net::HostPortPair(
92 IPAddressToHostString(address), hostport_.port()); 144 IPAddressToHostString(address), hostport_.port());
93 callback_.Run(scoped_ptr<PrivetHTTPClient>( 145 callback_.Run(scoped_ptr<PrivetHTTPClient>(
94 new PrivetHTTPClientImpl(name_, new_address, request_context_.get()))); 146 new PrivetHTTPClientImpl(name_, new_address, request_context_.get())));
95 } 147 }
96 148
97 } // namespace local_discovery 149 } // namespace local_discovery
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698