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

Side by Side Diff: jingle/notifier/communicator/xmpp_connection_generator.cc

Issue 8549004: base::Bind: Convert HostResolver::Resolve. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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
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 // XmppConnectionGenerator does the following algorithm: 5 // XmppConnectionGenerator does the following algorithm:
6 // proxy = ResolveProxyInformation(connection_options) 6 // proxy = ResolveProxyInformation(connection_options)
7 // for server in server_list 7 // for server in server_list
8 // get dns_addresses for server 8 // get dns_addresses for server
9 // connection_list = (dns_addresses X connection methods X proxy).shuffle() 9 // connection_list = (dns_addresses X connection methods X proxy).shuffle()
10 // for connection in connection_list 10 // for connection in connection_list
11 // yield connection 11 // yield connection
12 12
13 #include "jingle/notifier/communicator/xmpp_connection_generator.h" 13 #include "jingle/notifier/communicator/xmpp_connection_generator.h"
14 14
15 #if defined(OS_WIN) 15 #if defined(OS_WIN)
16 #include <winsock2.h> 16 #include <winsock2.h>
17 #elif defined(OS_POSIX) 17 #elif defined(OS_POSIX)
18 #include <arpa/inet.h> 18 #include <arpa/inet.h>
19 #endif 19 #endif
20 20
21 #include <vector> 21 #include <vector>
22 22
23 #include "base/bind.h"
23 #include "base/callback.h" 24 #include "base/callback.h"
24 #include "base/compiler_specific.h" 25 #include "base/compiler_specific.h"
25 #include "base/logging.h" 26 #include "base/logging.h"
26 #include "jingle/notifier/base/server_information.h" 27 #include "jingle/notifier/base/server_information.h"
27 #include "jingle/notifier/communicator/connection_options.h" 28 #include "jingle/notifier/communicator/connection_options.h"
28 #include "jingle/notifier/communicator/connection_settings.h" 29 #include "jingle/notifier/communicator/connection_settings.h"
29 #include "net/base/net_errors.h" 30 #include "net/base/net_errors.h"
30 #include "net/base/sys_addrinfo.h" 31 #include "net/base/sys_addrinfo.h"
31 #include "talk/base/httpcommon-inl.h" 32 #include "talk/base/httpcommon-inl.h"
32 #include "talk/base/task.h" 33 #include "talk/base/task.h"
33 #include "talk/base/thread.h" 34 #include "talk/base/thread.h"
34 #include "talk/xmpp/prexmppauth.h" 35 #include "talk/xmpp/prexmppauth.h"
35 #include "talk/xmpp/xmppclientsettings.h" 36 #include "talk/xmpp/xmppclientsettings.h"
36 #include "talk/xmpp/xmppengine.h" 37 #include "talk/xmpp/xmppengine.h"
37 38
38 namespace notifier { 39 namespace notifier {
39 40
40 XmppConnectionGenerator::XmppConnectionGenerator( 41 XmppConnectionGenerator::XmppConnectionGenerator(
41 Delegate* delegate, 42 Delegate* delegate,
42 net::HostResolver* host_resolver, 43 net::HostResolver* host_resolver,
43 const ConnectionOptions* options, 44 const ConnectionOptions* options,
44 bool try_ssltcp_first, 45 bool try_ssltcp_first,
45 const ServerList& servers) 46 const ServerList& servers)
46 : delegate_(delegate), 47 : delegate_(delegate),
47 host_resolver_(host_resolver), 48 host_resolver_(host_resolver),
48 resolve_callback_(
49 ALLOW_THIS_IN_INITIALIZER_LIST(
50 NewCallback(this,
51 &XmppConnectionGenerator::OnServerDNSResolved))),
52 settings_list_(new ConnectionSettingsList()), 49 settings_list_(new ConnectionSettingsList()),
53 settings_index_(0), 50 settings_index_(0),
54 servers_(servers), 51 servers_(servers),
55 current_server_(servers_.end()), 52 current_server_(servers_.end()),
56 try_ssltcp_first_(try_ssltcp_first), 53 try_ssltcp_first_(try_ssltcp_first),
57 successfully_resolved_dns_(false), 54 successfully_resolved_dns_(false),
58 first_dns_error_(0), 55 first_dns_error_(0),
59 should_resolve_dns_(true), 56 should_resolve_dns_(true),
60 options_(options) { 57 options_(options) {
61 DCHECK(delegate_); 58 DCHECK(delegate_);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 successfully_resolved_dns_, first_dns_error_); 116 successfully_resolved_dns_, first_dns_error_);
120 return; 117 return;
121 } 118 }
122 119
123 if (should_resolve_dns_) { 120 if (should_resolve_dns_) {
124 // Resolve the server. 121 // Resolve the server.
125 const net::HostPortPair& server = current_server_->server; 122 const net::HostPortPair& server = current_server_->server;
126 net::HostResolver::RequestInfo request_info(server); 123 net::HostResolver::RequestInfo request_info(server);
127 int status = 124 int status =
128 host_resolver_.Resolve( 125 host_resolver_.Resolve(
129 request_info, &address_list_, resolve_callback_.get(), 126 request_info, &address_list_,
127 base::Bind(&XmppConnectionGenerator::OnServerDNSResolved,
128 base::Unretained(this)),
130 bound_net_log_); 129 bound_net_log_);
131 if (status == net::ERR_IO_PENDING) { 130 if (status == net::ERR_IO_PENDING) // OnServerDNSResolved will be called.
132 // resolve_callback_ will call us when it's called.
133 return; 131 return;
134 } 132
135 HandleServerDNSResolved(status); 133 HandleServerDNSResolved(status);
136 } else { 134 } else {
137 // We are not resolving DNS here (DNS will be resolved by a lower layer). 135 // We are not resolving DNS here (DNS will be resolved by a lower layer).
138 // Generate settings using an empty IP list (which will just use the 136 // Generate settings using an empty IP list (which will just use the
139 // host name for the current server). 137 // host name for the current server).
140 std::vector<uint32> ip_list; 138 std::vector<uint32> ip_list;
141 GenerateSettingsForIPList(ip_list); 139 GenerateSettingsForIPList(ip_list);
142 } 140 }
143 } 141 }
144 } 142 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 settings_list_->ClearPermutations(); 187 settings_list_->ClearPermutations();
190 settings_list_->AddPermutations( 188 settings_list_->AddPermutations(
191 current_server_->server.host(), 189 current_server_->server.host(),
192 ip_list, 190 ip_list,
193 current_server_->server.port(), 191 current_server_->server.port(),
194 current_server_->special_port_magic, 192 current_server_->special_port_magic,
195 try_ssltcp_first_); 193 try_ssltcp_first_);
196 } 194 }
197 195
198 } // namespace notifier 196 } // namespace notifier
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698