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

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: small win fix 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
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/dns_util.h" 10 #include "net/base/dns_util.h"
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 const BoundNetLog& source_net_log, 147 const BoundNetLog& source_net_log,
148 NetLog* net_log) 148 NetLog* net_log)
149 : dns_server_(dns_server), 149 : dns_server_(dns_server),
150 key_(dns_name, query_type), 150 key_(dns_name, query_type),
151 delegate_(NULL), 151 delegate_(NULL),
152 query_(new DnsQuery(dns_name, query_type, rand_int)), 152 query_(new DnsQuery(dns_name, query_type, rand_int)),
153 attempts_(0), 153 attempts_(0),
154 next_state_(STATE_NONE), 154 next_state_(STATE_NONE),
155 socket_factory_(socket_factory ? socket_factory : 155 socket_factory_(socket_factory ? socket_factory :
156 ClientSocketFactory::GetDefaultFactory()), 156 ClientSocketFactory::GetDefaultFactory()),
157 ALLOW_THIS_IN_INITIALIZER_LIST(
158 io_callback_(this, &DnsTransaction::OnIOComplete)),
159 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_DNS_TRANSACTION)) { 157 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_DNS_TRANSACTION)) {
160 DCHECK(!rand_int.is_null()); 158 DCHECK(!rand_int.is_null());
161 for (size_t i = 0; i < arraysize(kTimeoutsMs); ++i) 159 for (size_t i = 0; i < arraysize(kTimeoutsMs); ++i)
162 timeouts_ms_.push_back(base::TimeDelta::FromMilliseconds(kTimeoutsMs[i])); 160 timeouts_ms_.push_back(base::TimeDelta::FromMilliseconds(kTimeoutsMs[i]));
163 net_log_.BeginEvent( 161 net_log_.BeginEvent(
164 NetLog::TYPE_DNS_TRANSACTION, 162 NetLog::TYPE_DNS_TRANSACTION,
165 make_scoped_refptr( 163 make_scoped_refptr(
166 new DnsTransactionStartParameters(dns_server_, key_, 164 new DnsTransactionStartParameters(dns_server_, key_,
167 source_net_log.source()))); 165 source_net_log.source())));
168 } 166 }
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 if (rv < 0) 263 if (rv < 0)
266 return rv; 264 return rv;
267 next_state_ = STATE_SEND_QUERY; 265 next_state_ = STATE_SEND_QUERY;
268 return OK; 266 return OK;
269 } 267 }
270 268
271 int DnsTransaction::DoSendQuery() { 269 int DnsTransaction::DoSendQuery() {
272 next_state_ = STATE_SEND_QUERY_COMPLETE; 270 next_state_ = STATE_SEND_QUERY_COMPLETE;
273 return socket_->Write(query_->io_buffer(), 271 return socket_->Write(query_->io_buffer(),
274 query_->io_buffer()->size(), 272 query_->io_buffer()->size(),
275 &io_callback_); 273 base::Bind(&DnsTransaction::OnIOComplete,
274 base::Unretained(this)));
276 } 275 }
277 276
278 int DnsTransaction::DoSendQueryComplete(int rv) { 277 int DnsTransaction::DoSendQueryComplete(int rv) {
279 if (rv < 0) 278 if (rv < 0)
280 return rv; 279 return rv;
281 280
282 // Writing to UDP should not result in a partial datagram. 281 // Writing to UDP should not result in a partial datagram.
283 if (rv != query_->io_buffer()->size()) 282 if (rv != query_->io_buffer()->size())
284 return ERR_NAME_NOT_RESOLVED; 283 return ERR_NAME_NOT_RESOLVED;
285 284
286 next_state_ = STATE_READ_RESPONSE; 285 next_state_ = STATE_READ_RESPONSE;
287 return OK; 286 return OK;
288 } 287 }
289 288
290 int DnsTransaction::DoReadResponse() { 289 int DnsTransaction::DoReadResponse() {
291 next_state_ = STATE_READ_RESPONSE_COMPLETE; 290 next_state_ = STATE_READ_RESPONSE_COMPLETE;
292 response_.reset(new DnsResponse(query_.get())); 291 response_.reset(new DnsResponse(query_.get()));
293 return socket_->Read(response_->io_buffer(), 292 return socket_->Read(response_->io_buffer(),
294 response_->io_buffer()->size(), 293 response_->io_buffer()->size(),
295 &io_callback_); 294 base::Bind(&DnsTransaction::OnIOComplete,
295 base::Unretained(this)));
296 } 296 }
297 297
298 int DnsTransaction::DoReadResponseComplete(int rv) { 298 int DnsTransaction::DoReadResponseComplete(int rv) {
299 DCHECK_NE(ERR_IO_PENDING, rv); 299 DCHECK_NE(ERR_IO_PENDING, rv);
300 RevokeTimer(); 300 RevokeTimer();
301 if (rv < 0) 301 if (rv < 0)
302 return rv; 302 return rv;
303 303
304 DCHECK(rv); 304 DCHECK(rv);
305 // TODO(agayev): when supporting EDNS0 we may need to do multiple reads 305 // TODO(agayev): when supporting EDNS0 we may need to do multiple reads
(...skipping 23 matching lines...) Expand all
329 DoCallback(rv); 329 DoCallback(rv);
330 } 330 }
331 331
332 void DnsTransaction::set_timeouts_ms( 332 void DnsTransaction::set_timeouts_ms(
333 const std::vector<base::TimeDelta>& timeouts_ms) { 333 const std::vector<base::TimeDelta>& timeouts_ms) {
334 DCHECK_EQ(0u, attempts_); 334 DCHECK_EQ(0u, attempts_);
335 timeouts_ms_ = timeouts_ms; 335 timeouts_ms_ = timeouts_ms;
336 } 336 }
337 337
338 } // namespace net 338 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698