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

Side by Side Diff: content/browser/renderer_host/p2p/socket_dispatcher_host.cc

Issue 8549004: base::Bind: Convert HostResolver::Resolve. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase. Created 9 years, 1 month 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
« no previous file with comments | « chrome/browser/net/predictor.cc ('k') | content/browser/renderer_host/pepper_message_filter.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "content/browser/renderer_host/p2p/socket_dispatcher_host.h" 5 #include "content/browser/renderer_host/p2p/socket_dispatcher_host.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "content/browser/renderer_host/p2p/socket_host.h" 9 #include "content/browser/renderer_host/p2p/socket_host.h"
10 #include "content/browser/resource_context.h" 10 #include "content/browser/resource_context.h"
(...skipping 10 matching lines...) Expand all
21 namespace content { 21 namespace content {
22 22
23 class P2PSocketDispatcherHost::DnsRequest { 23 class P2PSocketDispatcherHost::DnsRequest {
24 public: 24 public:
25 typedef base::Callback<void(const net::IPAddressNumber&)> DoneCallback; 25 typedef base::Callback<void(const net::IPAddressNumber&)> DoneCallback;
26 26
27 DnsRequest(int32 routing_id, int32 request_id, 27 DnsRequest(int32 routing_id, int32 request_id,
28 net::HostResolver* host_resolver) 28 net::HostResolver* host_resolver)
29 : routing_id_(routing_id), 29 : routing_id_(routing_id),
30 request_id_(request_id), 30 request_id_(request_id),
31 resolver_(host_resolver), 31 resolver_(host_resolver) {
32 ALLOW_THIS_IN_INITIALIZER_LIST(completion_callback_(
33 this, &P2PSocketDispatcherHost::DnsRequest::OnDone)) {
34 } 32 }
35 33
36 void Resolve(const std::string& host_name, 34 void Resolve(const std::string& host_name,
37 const DoneCallback& done_callback) { 35 const DoneCallback& done_callback) {
38 DCHECK(!done_callback.is_null()); 36 DCHECK(!done_callback.is_null());
39 37
40 host_name_ = host_name; 38 host_name_ = host_name;
41 done_callback_ = done_callback; 39 done_callback_ = done_callback;
42 40
43 // Return an error if it's an empty string. 41 // Return an error if it's an empty string.
44 if (host_name_.empty()) { 42 if (host_name_.empty()) {
45 done_callback_.Run(net::IPAddressNumber()); 43 done_callback_.Run(net::IPAddressNumber());
46 return; 44 return;
47 } 45 }
48 46
49 // Add period at the end to make sure that we only resolve 47 // Add period at the end to make sure that we only resolve
50 // fully-qualified names. 48 // fully-qualified names.
51 if (host_name_.at(host_name_.size() - 1) != '.') 49 if (host_name_.at(host_name_.size() - 1) != '.')
52 host_name_ = host_name_ + '.'; 50 host_name_ = host_name_ + '.';
53 51
54 net::HostResolver::RequestInfo info(net::HostPortPair(host_name_, 0)); 52 net::HostResolver::RequestInfo info(net::HostPortPair(host_name_, 0));
55 int result = resolver_.Resolve(info, &addresses_, &completion_callback_, 53 int result = resolver_.Resolve(
56 net::BoundNetLog()); 54 info, &addresses_,
55 base::Bind(&P2PSocketDispatcherHost::DnsRequest::OnDone,
56 base::Unretained(this)),
57 net::BoundNetLog());
57 if (result != net::ERR_IO_PENDING) 58 if (result != net::ERR_IO_PENDING)
58 OnDone(result); 59 OnDone(result);
59 } 60 }
60 61
61 int32 routing_id() { return routing_id_; } 62 int32 routing_id() { return routing_id_; }
62 int32 request_id() { return request_id_; } 63 int32 request_id() { return request_id_; }
63 64
64 private: 65 private:
65 void OnDone(int result) { 66 void OnDone(int result) {
66 if (result != net::OK) { 67 if (result != net::OK) {
(...skipping 22 matching lines...) Expand all
89 } 90 }
90 91
91 int32 routing_id_; 92 int32 routing_id_;
92 int32 request_id_; 93 int32 request_id_;
93 net::AddressList addresses_; 94 net::AddressList addresses_;
94 95
95 std::string host_name_; 96 std::string host_name_;
96 net::SingleRequestHostResolver resolver_; 97 net::SingleRequestHostResolver resolver_;
97 98
98 DoneCallback done_callback_; 99 DoneCallback done_callback_;
99
100 net::OldCompletionCallbackImpl<DnsRequest> completion_callback_;
101 }; 100 };
102 101
103 P2PSocketDispatcherHost::P2PSocketDispatcherHost( 102 P2PSocketDispatcherHost::P2PSocketDispatcherHost(
104 const content::ResourceContext* resource_context) 103 const content::ResourceContext* resource_context)
105 : resource_context_(resource_context), 104 : resource_context_(resource_context),
106 monitoring_networks_(false) { 105 monitoring_networks_(false) {
107 } 106 }
108 107
109 P2PSocketDispatcherHost::~P2PSocketDispatcherHost() { 108 P2PSocketDispatcherHost::~P2PSocketDispatcherHost() {
110 DCHECK(sockets_.empty()); 109 DCHECK(sockets_.empty());
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 ExtendedSocketId(msg.routing_id(), socket_id)); 279 ExtendedSocketId(msg.routing_id(), socket_id));
281 if (it != sockets_.end()) { 280 if (it != sockets_.end()) {
282 delete it->second; 281 delete it->second;
283 sockets_.erase(it); 282 sockets_.erase(it);
284 } else { 283 } else {
285 LOG(ERROR) << "Received P2PHostMsg_DestroySocket for invalid socket_id."; 284 LOG(ERROR) << "Received P2PHostMsg_DestroySocket for invalid socket_id.";
286 } 285 }
287 } 286 }
288 287
289 } // namespace content 288 } // namespace content
OLDNEW
« no previous file with comments | « chrome/browser/net/predictor.cc ('k') | content/browser/renderer_host/pepper_message_filter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698