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

Side by Side Diff: net/dns/dns_transaction.cc

Issue 8824006: Migrate net/socket/socket.h, net/socket/stream_socket.h to base::Bind(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 9 years 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 | « net/dns/dns_transaction.h ('k') | net/ftp/ftp_network_transaction.h » ('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 "net/dns/dns_transaction.h" 5 #include "net/dns/dns_transaction.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/rand_util.h" 8 #include "base/rand_util.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "net/base/io_buffer.h" 10 #include "net/base/io_buffer.h"
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 const base::StringPiece& qname, 92 const base::StringPiece& qname,
93 uint16 qtype, 93 uint16 qtype,
94 const ResultCallback& callback, 94 const ResultCallback& callback,
95 const BoundNetLog& source_net_log) 95 const BoundNetLog& source_net_log)
96 : session_(session), 96 : session_(session),
97 dns_server_(session->NextServer()), 97 dns_server_(session->NextServer()),
98 query_(new DnsQuery(session->NextId(), qname, qtype)), 98 query_(new DnsQuery(session->NextId(), qname, qtype)),
99 callback_(callback), 99 callback_(callback),
100 attempts_(0), 100 attempts_(0),
101 next_state_(STATE_NONE), 101 next_state_(STATE_NONE),
102 ALLOW_THIS_IN_INITIALIZER_LIST(
103 io_callback_(this, &DnsTransaction::OnIOComplete)),
104 net_log_(BoundNetLog::Make(session->net_log(), 102 net_log_(BoundNetLog::Make(session->net_log(),
105 NetLog::SOURCE_DNS_TRANSACTION)) { 103 NetLog::SOURCE_DNS_TRANSACTION)) {
106 net_log_.BeginEvent( 104 net_log_.BeginEvent(
107 NetLog::TYPE_DNS_TRANSACTION, 105 NetLog::TYPE_DNS_TRANSACTION,
108 make_scoped_refptr( 106 make_scoped_refptr(
109 new DnsTransactionStartParameters(dns_server_, 107 new DnsTransactionStartParameters(dns_server_,
110 qname, 108 qname,
111 qtype, 109 qtype,
112 source_net_log.source()))); 110 source_net_log.source())));
113 } 111 }
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 if (rv < 0) 197 if (rv < 0)
200 return rv; 198 return rv;
201 next_state_ = STATE_SEND_QUERY; 199 next_state_ = STATE_SEND_QUERY;
202 return OK; 200 return OK;
203 } 201 }
204 202
205 int DnsTransaction::DoSendQuery() { 203 int DnsTransaction::DoSendQuery() {
206 next_state_ = STATE_SEND_QUERY_COMPLETE; 204 next_state_ = STATE_SEND_QUERY_COMPLETE;
207 return socket_->Write(query_->io_buffer(), 205 return socket_->Write(query_->io_buffer(),
208 query_->io_buffer()->size(), 206 query_->io_buffer()->size(),
209 &io_callback_); 207 base::Bind(&DnsTransaction::OnIOComplete,
208 base::Unretained(this)));
210 } 209 }
211 210
212 int DnsTransaction::DoSendQueryComplete(int rv) { 211 int DnsTransaction::DoSendQueryComplete(int rv) {
213 if (rv < 0) 212 if (rv < 0)
214 return rv; 213 return rv;
215 214
216 // Writing to UDP should not result in a partial datagram. 215 // Writing to UDP should not result in a partial datagram.
217 if (rv != query_->io_buffer()->size()) 216 if (rv != query_->io_buffer()->size())
218 return ERR_MSG_TOO_BIG; 217 return ERR_MSG_TOO_BIG;
219 218
220 next_state_ = STATE_READ_RESPONSE; 219 next_state_ = STATE_READ_RESPONSE;
221 return OK; 220 return OK;
222 } 221 }
223 222
224 int DnsTransaction::DoReadResponse() { 223 int DnsTransaction::DoReadResponse() {
225 next_state_ = STATE_READ_RESPONSE_COMPLETE; 224 next_state_ = STATE_READ_RESPONSE_COMPLETE;
226 response_.reset(new DnsResponse()); 225 response_.reset(new DnsResponse());
227 return socket_->Read(response_->io_buffer(), 226 return socket_->Read(response_->io_buffer(),
228 response_->io_buffer()->size(), 227 response_->io_buffer()->size(),
229 &io_callback_); 228 base::Bind(&DnsTransaction::OnIOComplete,
229 base::Unretained(this)));
230 } 230 }
231 231
232 int DnsTransaction::DoReadResponseComplete(int rv) { 232 int DnsTransaction::DoReadResponseComplete(int rv) {
233 DCHECK_NE(ERR_IO_PENDING, rv); 233 DCHECK_NE(ERR_IO_PENDING, rv);
234 RevokeTimer(); 234 RevokeTimer();
235 if (rv < 0) 235 if (rv < 0)
236 return rv; 236 return rv;
237 237
238 DCHECK(rv); 238 DCHECK(rv);
239 if (!response_->InitParse(rv, *query_)) 239 if (!response_->InitParse(rv, *query_))
(...skipping 29 matching lines...) Expand all
269 return; 269 return;
270 } 270 }
271 next_state_ = STATE_CONNECT; 271 next_state_ = STATE_CONNECT;
272 query_.reset(query_->CloneWithNewId(session_->NextId())); 272 query_.reset(query_->CloneWithNewId(session_->NextId()));
273 int rv = DoLoop(OK); 273 int rv = DoLoop(OK);
274 if (rv != ERR_IO_PENDING) 274 if (rv != ERR_IO_PENDING)
275 DoCallback(rv); 275 DoCallback(rv);
276 } 276 }
277 277
278 } // namespace net 278 } // namespace net
OLDNEW
« no previous file with comments | « net/dns/dns_transaction.h ('k') | net/ftp/ftp_network_transaction.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698