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

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

Issue 15829004: Update net/ to use scoped_refptr<T>::get() rather than implicit "operator T*" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: license twerk Created 7 years, 6 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
« no previous file with comments | « net/dns/dns_query.h ('k') | net/dns/host_resolver_impl.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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <deque> 7 #include <deque>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 } 387 }
388 return rv; 388 return rv;
389 } 389 }
390 390
391 int DoConnectComplete(int rv) { 391 int DoConnectComplete(int rv) {
392 DCHECK_NE(ERR_IO_PENDING, rv); 392 DCHECK_NE(ERR_IO_PENDING, rv);
393 if (rv < 0) 393 if (rv < 0)
394 return rv; 394 return rv;
395 395
396 WriteBigEndian<uint16>(length_buffer_->data(), query_->io_buffer()->size()); 396 WriteBigEndian<uint16>(length_buffer_->data(), query_->io_buffer()->size());
397 buffer_ = new DrainableIOBuffer(length_buffer_, length_buffer_->size()); 397 buffer_ =
398 new DrainableIOBuffer(length_buffer_.get(), length_buffer_->size());
398 next_state_ = STATE_SEND_LENGTH; 399 next_state_ = STATE_SEND_LENGTH;
399 return OK; 400 return OK;
400 } 401 }
401 402
402 int DoSendLength(int rv) { 403 int DoSendLength(int rv) {
403 DCHECK_NE(ERR_IO_PENDING, rv); 404 DCHECK_NE(ERR_IO_PENDING, rv);
404 if (rv < 0) 405 if (rv < 0)
405 return rv; 406 return rv;
406 407
407 buffer_->DidConsume(rv); 408 buffer_->DidConsume(rv);
408 if (buffer_->BytesRemaining() > 0) { 409 if (buffer_->BytesRemaining() > 0) {
409 next_state_ = STATE_SEND_LENGTH; 410 next_state_ = STATE_SEND_LENGTH;
410 return socket_->Write(buffer_, 411 return socket_->Write(
411 buffer_->BytesRemaining(), 412 buffer_.get(),
412 base::Bind(&DnsTCPAttempt::OnIOComplete, 413 buffer_->BytesRemaining(),
413 base::Unretained(this))); 414 base::Bind(&DnsTCPAttempt::OnIOComplete, base::Unretained(this)));
414 } 415 }
415 buffer_ = new DrainableIOBuffer(query_->io_buffer(), 416 buffer_ = new DrainableIOBuffer(query_->io_buffer(),
416 query_->io_buffer()->size()); 417 query_->io_buffer()->size());
417 next_state_ = STATE_SEND_QUERY; 418 next_state_ = STATE_SEND_QUERY;
418 return OK; 419 return OK;
419 } 420 }
420 421
421 int DoSendQuery(int rv) { 422 int DoSendQuery(int rv) {
422 DCHECK_NE(ERR_IO_PENDING, rv); 423 DCHECK_NE(ERR_IO_PENDING, rv);
423 if (rv < 0) 424 if (rv < 0)
424 return rv; 425 return rv;
425 426
426 buffer_->DidConsume(rv); 427 buffer_->DidConsume(rv);
427 if (buffer_->BytesRemaining() > 0) { 428 if (buffer_->BytesRemaining() > 0) {
428 next_state_ = STATE_SEND_QUERY; 429 next_state_ = STATE_SEND_QUERY;
429 return socket_->Write(buffer_, 430 return socket_->Write(
430 buffer_->BytesRemaining(), 431 buffer_.get(),
431 base::Bind(&DnsTCPAttempt::OnIOComplete, 432 buffer_->BytesRemaining(),
432 base::Unretained(this))); 433 base::Bind(&DnsTCPAttempt::OnIOComplete, base::Unretained(this)));
433 } 434 }
434 buffer_ = new DrainableIOBuffer(length_buffer_, length_buffer_->size()); 435 buffer_ =
436 new DrainableIOBuffer(length_buffer_.get(), length_buffer_->size());
435 next_state_ = STATE_READ_LENGTH; 437 next_state_ = STATE_READ_LENGTH;
436 return OK; 438 return OK;
437 } 439 }
438 440
439 int DoReadLength(int rv) { 441 int DoReadLength(int rv) {
440 DCHECK_NE(ERR_IO_PENDING, rv); 442 DCHECK_NE(ERR_IO_PENDING, rv);
441 if (rv < 0) 443 if (rv < 0)
442 return rv; 444 return rv;
443 445
444 buffer_->DidConsume(rv); 446 buffer_->DidConsume(rv);
445 if (buffer_->BytesRemaining() > 0) { 447 if (buffer_->BytesRemaining() > 0) {
446 next_state_ = STATE_READ_LENGTH; 448 next_state_ = STATE_READ_LENGTH;
447 return socket_->Read(buffer_, 449 return socket_->Read(
448 buffer_->BytesRemaining(), 450 buffer_.get(),
449 base::Bind(&DnsTCPAttempt::OnIOComplete, 451 buffer_->BytesRemaining(),
450 base::Unretained(this))); 452 base::Bind(&DnsTCPAttempt::OnIOComplete, base::Unretained(this)));
451 } 453 }
452 ReadBigEndian<uint16>(length_buffer_->data(), &response_length_); 454 ReadBigEndian<uint16>(length_buffer_->data(), &response_length_);
453 // Check if advertised response is too short. (Optimization only.) 455 // Check if advertised response is too short. (Optimization only.)
454 if (response_length_ < query_->io_buffer()->size()) 456 if (response_length_ < query_->io_buffer()->size())
455 return ERR_DNS_MALFORMED_RESPONSE; 457 return ERR_DNS_MALFORMED_RESPONSE;
456 // Allocate more space so that DnsResponse::InitParse sanity check passes. 458 // Allocate more space so that DnsResponse::InitParse sanity check passes.
457 response_.reset(new DnsResponse(response_length_ + 1)); 459 response_.reset(new DnsResponse(response_length_ + 1));
458 buffer_ = new DrainableIOBuffer(response_->io_buffer(), response_length_); 460 buffer_ = new DrainableIOBuffer(response_->io_buffer(), response_length_);
459 next_state_ = STATE_READ_RESPONSE; 461 next_state_ = STATE_READ_RESPONSE;
460 return OK; 462 return OK;
461 } 463 }
462 464
463 int DoReadResponse(int rv) { 465 int DoReadResponse(int rv) {
464 DCHECK_NE(ERR_IO_PENDING, rv); 466 DCHECK_NE(ERR_IO_PENDING, rv);
465 if (rv < 0) 467 if (rv < 0)
466 return rv; 468 return rv;
467 469
468 buffer_->DidConsume(rv); 470 buffer_->DidConsume(rv);
469 if (buffer_->BytesRemaining() > 0) { 471 if (buffer_->BytesRemaining() > 0) {
470 next_state_ = STATE_READ_RESPONSE; 472 next_state_ = STATE_READ_RESPONSE;
471 return socket_->Read(buffer_, 473 return socket_->Read(
472 buffer_->BytesRemaining(), 474 buffer_.get(),
473 base::Bind(&DnsTCPAttempt::OnIOComplete, 475 buffer_->BytesRemaining(),
474 base::Unretained(this))); 476 base::Bind(&DnsTCPAttempt::OnIOComplete, base::Unretained(this)));
475 } 477 }
476 if (!response_->InitParse(buffer_->BytesConsumed(), *query_)) 478 if (!response_->InitParse(buffer_->BytesConsumed(), *query_))
477 return ERR_DNS_MALFORMED_RESPONSE; 479 return ERR_DNS_MALFORMED_RESPONSE;
478 if (response_->flags() & dns_protocol::kFlagTC) 480 if (response_->flags() & dns_protocol::kFlagTC)
479 return ERR_UNEXPECTED; 481 return ERR_UNEXPECTED;
480 // TODO(szym): Frankly, none of these are expected. 482 // TODO(szym): Frankly, none of these are expected.
481 if (response_->rcode() == dns_protocol::kRcodeNXDOMAIN) 483 if (response_->rcode() == dns_protocol::kRcodeNXDOMAIN)
482 return ERR_NAME_NOT_RESOLVED; 484 return ERR_NAME_NOT_RESOLVED;
483 if (response_->rcode() != dns_protocol::kRcodeNOERROR) 485 if (response_->rcode() != dns_protocol::kRcodeNOERROR)
484 return ERR_DNS_SERVER_FAILED; 486 return ERR_DNS_SERVER_FAILED;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 const DnsTransactionFactory::CallbackType& callback, 529 const DnsTransactionFactory::CallbackType& callback,
528 const BoundNetLog& net_log) 530 const BoundNetLog& net_log)
529 : session_(session), 531 : session_(session),
530 hostname_(hostname), 532 hostname_(hostname),
531 qtype_(qtype), 533 qtype_(qtype),
532 callback_(callback), 534 callback_(callback),
533 net_log_(net_log), 535 net_log_(net_log),
534 qnames_initial_size_(0), 536 qnames_initial_size_(0),
535 had_tcp_attempt_(false), 537 had_tcp_attempt_(false),
536 first_server_index_(0) { 538 first_server_index_(0) {
537 DCHECK(session_); 539 DCHECK(session_.get());
538 DCHECK(!hostname_.empty()); 540 DCHECK(!hostname_.empty());
539 DCHECK(!callback_.is_null()); 541 DCHECK(!callback_.is_null());
540 DCHECK(!IsIPLiteral(hostname_)); 542 DCHECK(!IsIPLiteral(hostname_));
541 } 543 }
542 544
543 virtual ~DnsTransactionImpl() { 545 virtual ~DnsTransactionImpl() {
544 if (!callback_.is_null()) { 546 if (!callback_.is_null()) {
545 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_DNS_TRANSACTION, 547 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_DNS_TRANSACTION,
546 ERR_ABORTED); 548 ERR_ABORTED);
547 } // otherwise logged in DoCallback or Start 549 } // otherwise logged in DoCallback or Start
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
930 public: 932 public:
931 explicit DnsTransactionFactoryImpl(DnsSession* session) { 933 explicit DnsTransactionFactoryImpl(DnsSession* session) {
932 session_ = session; 934 session_ = session;
933 } 935 }
934 936
935 virtual scoped_ptr<DnsTransaction> CreateTransaction( 937 virtual scoped_ptr<DnsTransaction> CreateTransaction(
936 const std::string& hostname, 938 const std::string& hostname,
937 uint16 qtype, 939 uint16 qtype,
938 const CallbackType& callback, 940 const CallbackType& callback,
939 const BoundNetLog& net_log) OVERRIDE { 941 const BoundNetLog& net_log) OVERRIDE {
940 return scoped_ptr<DnsTransaction>(new DnsTransactionImpl(session_, 942 return scoped_ptr<DnsTransaction>(new DnsTransactionImpl(
941 hostname, 943 session_.get(), hostname, qtype, callback, net_log));
942 qtype,
943 callback,
944 net_log));
945 } 944 }
946 945
947 private: 946 private:
948 scoped_refptr<DnsSession> session_; 947 scoped_refptr<DnsSession> session_;
949 }; 948 };
950 949
951 } // namespace 950 } // namespace
952 951
953 // static 952 // static
954 scoped_ptr<DnsTransactionFactory> DnsTransactionFactory::CreateFactory( 953 scoped_ptr<DnsTransactionFactory> DnsTransactionFactory::CreateFactory(
955 DnsSession* session) { 954 DnsSession* session) {
956 return scoped_ptr<DnsTransactionFactory>( 955 return scoped_ptr<DnsTransactionFactory>(
957 new DnsTransactionFactoryImpl(session)); 956 new DnsTransactionFactoryImpl(session));
958 } 957 }
959 958
960 } // namespace net 959 } // namespace net
OLDNEW
« no previous file with comments | « net/dns/dns_query.h ('k') | net/dns/host_resolver_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698